--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #FF777777
20 |
21 | #55777777
22 | #B1777777
23 | #FF777777
24 |
25 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeMenuItemClickListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | /**
19 | * Created by Yan Zhenjie on 2016/7/26.
20 | */
21 | public interface SwipeMenuItemClickListener {
22 |
23 | /**
24 | * Invoke when the menu item is clicked.
25 | *
26 | * @param menuBridge menu.
27 | */
28 | void onItemClick(SwipeMenuBridge menuBridge);
29 |
30 | }
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 暂时没有数据
20 | 没有更多数据啦
21 | 点击加载更多
22 | 加载出错啦,请稍后重试
23 | 正在加载更多数据,请稍后
24 |
25 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/values-zh-rHK/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 暫時沒有數據
20 | 沒有更多數據啦
21 | 點擊加載更多
22 | 加載出錯啦,請稍後重試
23 | 正在加載更多數據,請稍後
24 |
25 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/values-zh-rTW/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 暫時沒有數據
20 | 沒有更多數據啦
21 | 點擊加載更多
22 | 加載出錯啦,請稍後重試
23 | 正在加載更多數據,請稍後
24 |
25 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | There is no data
20 | No more data
21 | Click to load more
22 | Error, please try again
23 | Loading, please wait later
24 |
25 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/App.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample;
17 |
18 | import android.app.Application;
19 |
20 | /**
21 | * Created by Yan Zhenjie on 2016/7/27.
22 | */
23 | public class App extends Application {
24 |
25 | private static App instance;
26 |
27 | @Override
28 | public void onCreate() {
29 | super.onCreate();
30 |
31 | if (instance == null) {
32 | instance = this;
33 | }
34 | }
35 |
36 | public static App getInstance() {
37 | return instance;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeMenuCreator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | /**
19 | * Created by Yan Zhenjie on 2016/7/26.
20 | */
21 | public interface SwipeMenuCreator {
22 |
23 | /**
24 | * Create menu for recyclerVie item.
25 | *
26 | * @param swipeLeftMenu The menu on the left.
27 | * @param swipeRightMenu The menu on the right.
28 | * @param viewType The view type of the new view.
29 | */
30 | void onCreateMenu(SwipeMenu swipeLeftMenu, SwipeMenu swipeRightMenu, int viewType);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/android/support/v7/widget/helper/CompatItemTouchHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package android.support.v7.widget.helper;
17 |
18 | /**
19 | * Created by Yan Zhenjie on 2016/8/1.
20 | */
21 | public class CompatItemTouchHelper extends ItemTouchHelper {
22 |
23 | public CompatItemTouchHelper(ItemTouchHelper.Callback callback) {
24 | super(callback);
25 | }
26 |
27 | /**
28 | * Developer callback which controls the behavior of ItemTouchHelper.
29 | *
30 | * @return {@link Callback}
31 | */
32 | public ItemTouchHelper.Callback getCallback() {
33 | return mCallback;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/layout_fotter_loadmore.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
25 |
26 |
32 |
33 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_menu_sticky.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
26 |
27 |
32 |
33 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_menu_vertical.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
26 |
27 |
32 |
33 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/layout/recycler_swipe_view_load_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
25 |
26 |
33 |
34 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/widget/ListItemDecoration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.widget;
17 |
18 | import android.support.annotation.ColorInt;
19 |
20 | /**
21 | *
22 | * RecyclerView's Item Split Line.
23 | *
24 | * Created by Yan Zhenjie on 2016/7/27.
25 | *
26 | * @deprecated use {@link DefaultItemDecoration} instead.
27 | */
28 | @Deprecated
29 | public class ListItemDecoration extends DefaultItemDecoration {
30 |
31 | public ListItemDecoration(@ColorInt int color) {
32 | super(color);
33 | }
34 |
35 | public ListItemDecoration(@ColorInt int color, int dividerWidth, int dividerHeight, int... excludeViewType) {
36 | super(color, dividerWidth, dividerHeight, excludeViewType);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
25 |
26 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #3F51B5
19 | #303F9F
20 | #FF4081
21 |
22 | #FF333333
23 |
24 | #FF0000
25 | #FF6666
26 | #37C000
27 | #30A070
28 | #9932CC
29 | #9F79EE
30 |
31 | #FFFFFFFF
32 | #FFCFCFCF
33 |
34 | #FFB7B2B2
35 |
36 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/layout_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
29 |
30 |
36 |
37 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/toolbar_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
31 |
32 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/adapter/BaseAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.adapter;
17 |
18 | import android.content.Context;
19 | import android.support.v7.widget.RecyclerView;
20 | import android.view.LayoutInflater;
21 |
22 | import java.util.List;
23 |
24 | /**
25 | * Created by YanZhenjie on 2017/10/3.
26 | */
27 | public abstract class BaseAdapter extends RecyclerView.Adapter {
28 |
29 | private LayoutInflater mInflater;
30 |
31 | public BaseAdapter(Context context) {
32 | this.mInflater = LayoutInflater.from(context);
33 | }
34 |
35 | public LayoutInflater getInflater() {
36 | return mInflater;
37 | }
38 |
39 | public abstract void notifyDataSetChanged(List dataList);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/touch/OnItemMoveListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.touch;
17 |
18 | import android.support.v7.widget.RecyclerView;
19 |
20 | /**
21 | * Created by Yolanda on 2016/4/19.
22 | */
23 | public interface OnItemMoveListener {
24 |
25 | /**
26 | * When drag and drop the callback.
27 | *
28 | * @param srcHolder src.
29 | * @param targetHolder target.
30 | * @return To deal with the returns true, false otherwise.
31 | */
32 | boolean onItemMove(RecyclerView.ViewHolder srcHolder, RecyclerView.ViewHolder targetHolder);
33 |
34 | /**
35 | * When items should be removed when the callback.
36 | *
37 | * @param srcHolder src.
38 | */
39 | void onItemDismiss(RecyclerView.ViewHolder srcHolder);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/layout_header_switch.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
29 |
30 |
37 |
38 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_refresh_loadmore.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
25 |
26 |
31 |
32 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_group_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
25 |
26 |
31 |
32 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/res/layout/recycler_swipe_view_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
26 |
27 |
31 |
32 |
36 |
37 |
41 |
42 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/touch/OnItemMovementListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.touch;
17 |
18 | import android.support.v7.widget.RecyclerView;
19 | import android.support.v7.widget.helper.ItemTouchHelper;
20 |
21 | /**
22 | * Created by Yan Zhenjie on 2016/8/1.
23 | */
24 | public interface OnItemMovementListener {
25 |
26 | int INVALID = 0;
27 |
28 | int LEFT = ItemTouchHelper.LEFT;
29 |
30 | int UP = ItemTouchHelper.UP;
31 |
32 | int RIGHT = ItemTouchHelper.RIGHT;
33 |
34 | int DOWN = ItemTouchHelper.DOWN;
35 |
36 | /**
37 | * Can drag and drop the ViewHolder?
38 | *
39 | * @param recyclerView {@link RecyclerView}.
40 | * @param targetViewHolder target ViewHolder.
41 | * @return use {@link #LEFT}, {@link #UP}, {@link #RIGHT}, {@link #DOWN}.
42 | */
43 | int onDragFlags(RecyclerView recyclerView, RecyclerView.ViewHolder targetViewHolder);
44 |
45 | /**
46 | * Can swipe and drop the ViewHolder?
47 | *
48 | * @param recyclerView {@link RecyclerView}.
49 | * @param targetViewHolder target ViewHolder.
50 | * @return use {@link #LEFT}, {@link #UP}, {@link #RIGHT}, {@link #DOWN}.
51 | */
52 | int onSwipeFlags(RecyclerView recyclerView, RecyclerView.ViewHolder targetViewHolder);
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/array.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | Item中的横竖菜单
20 | Item的拖拽和侧滑删除
21 | 添加Header和Footer
22 | 下拉刷新和加载更多
23 | 和滑动布局嵌套使用
24 | Sticky分组效果
25 |
26 |
27 |
28 | List形式菜单
29 | Grid形式菜单
30 | 根据ViewType定制菜单
31 | 竖向排布的菜单
32 | 自定义菜单
33 |
34 |
35 |
36 | 默认LoadMoreView
37 | 自定义LoadMoreView
38 |
39 |
40 |
41 | 当Item是CardView时(特殊)
42 | 和DrawerLayout嵌套使用
43 | 和ViewPager嵌套使用
44 |
45 |
46 |
47 | 普通布局中Sticky
48 | Item菜单Sticky分组
49 |
50 |
51 |
52 | ListItem拖拽和侧滑删除
53 | GridItem拖拽
54 | 触摸即开始拖拽
55 | 自定义拖拽参数(不同ViewType)
56 |
57 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/group/GroupActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.group;
17 |
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.view.View;
21 |
22 | import com.yanzhenjie.recyclerview.swipe.sample.R;
23 | import com.yanzhenjie.recyclerview.swipe.sample.activity.BaseActivity;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | /**
29 | *
30 | * Sticky的几个效果演示。
31 | *
32 | * Created by YanZhenjie on 2017/7/22.
33 | */
34 | public class GroupActivity extends BaseActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | mRecyclerView.setAdapter(mAdapter);
41 | }
42 |
43 | @Override
44 | public void onItemClick(View itemView, int position) {
45 | switch (position) {
46 | case 0: {
47 | startActivity(new Intent(this, LayoutActivity.class));
48 | break;
49 | }
50 | case 1: {
51 | startActivity(new Intent(this, MenuActivity.class));
52 | break;
53 | }
54 | }
55 | }
56 |
57 | @Override
58 | protected List createDataList() {
59 | return Arrays.asList(getResources().getStringArray(R.array.sticky_item));
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/load/RefreshLoadActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.load;
17 |
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.view.View;
21 |
22 | import com.yanzhenjie.recyclerview.swipe.sample.R;
23 | import com.yanzhenjie.recyclerview.swipe.sample.activity.BaseActivity;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | /**
29 | *
30 | * 加载更多的两个演示。
31 | *
32 | * Created by YanZhenjie on 2017/7/21.
33 | */
34 | public class RefreshLoadActivity extends BaseActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | mRecyclerView.setAdapter(mAdapter);
41 | mAdapter.notifyDataSetChanged(mDataList);
42 | }
43 |
44 | @Override
45 | public void onItemClick(View itemView, int position) {
46 | switch (position) {
47 | case 0: {
48 | startActivity(new Intent(this, DefaultActivity.class));
49 | break;
50 | }
51 | case 1: {
52 | startActivity(new Intent(this, DefineActivity.class));
53 | break;
54 | }
55 | }
56 | }
57 |
58 | @Override
59 | protected List createDataList() {
60 | return Arrays.asList(getResources().getStringArray(R.array.refresh_item));
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/touch/OnItemStateChangedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.touch;
17 |
18 | import android.support.v7.widget.RecyclerView;
19 | import android.support.v7.widget.helper.ItemTouchHelper;
20 |
21 | /**
22 | * Created by Yan Zhenjie on 2016/8/12.
23 | */
24 | public interface OnItemStateChangedListener {
25 |
26 | /**
27 | * ItemTouchHelper is in idle state. At this state, either there is no related motion event by
28 | * the user or latest motion events have not yet triggered a swipe or drag.
29 | */
30 | int ACTION_STATE_IDLE = ItemTouchHelper.ACTION_STATE_IDLE;
31 |
32 | /**
33 | * A View is currently being swiped.
34 | */
35 | int ACTION_STATE_SWIPE = ItemTouchHelper.ACTION_STATE_SWIPE;
36 |
37 | /**
38 | * A View is currently being dragged.
39 | */
40 | int ACTION_STATE_DRAG = ItemTouchHelper.ACTION_STATE_DRAG;
41 |
42 | /**
43 | * Called when the ViewHolder swiped or dragged by the ItemTouchHelper is changed.
44 | *
45 | * @param viewHolder The new ViewHolder that is being swiped or dragged. Might be null if it is cleared.
46 | * @param actionState One of {@link OnItemStateChangedListener#ACTION_STATE_IDLE},
47 | * {@link OnItemStateChangedListener#ACTION_STATE_SWIPE} or
48 | * {@link OnItemStateChangedListener#ACTION_STATE_DRAG}.
49 | */
50 | void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState);
51 | }
52 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | plugins = [
3 | library : 'com.android.library',
4 | application: 'com.android.application',
5 | maven : 'com.github.dcendents.android-maven',
6 | bintray : 'com.jfrog.bintray'
7 | ]
8 |
9 | android = [
10 | applicationId : "com.yanzhenjie.recyclerview.swipe.sample",
11 | compileSdkVersion: 25,
12 | buildToolsVersion: "25.0.3",
13 |
14 | minSdkVersion : 14,
15 | targetSdkVersion : 25,
16 |
17 | versionCode : 5,
18 | versionName : "1.0.4",
19 | ]
20 |
21 | bintray = [
22 | version : "1.1.3",
23 |
24 | siteUrl : 'https://github.com/yanzhenjie/SwipeRecyclerView',
25 | gitUrl : 'git@github.com:yanzhenjie/SwipeRecyclerView.git',
26 |
27 | group : "com.yanzhenjie",
28 |
29 | // project
30 | packaging : 'aar',
31 | name : 'SwipeRecyclerView',
32 | description : 'SwipeRecyclerView For Android',
33 |
34 | // project.license
35 | licenseName : 'The Apache Software License, Version 2.0',
36 | licenseUrl : 'http://www.apache.org/licenses/LICENSE-2.0.txt',
37 |
38 | // project.developers
39 | developerId : 'yanzhenjie',
40 | developerName : 'yanzhenjie',
41 | developerEmail: 'smallajax@foxmail.com',
42 |
43 | // bintray
44 | binrayLibrary : "recyclerview-swipe",
45 | bintrayRepo : "maven",
46 | bintrayUser : 'yolanda',
47 | bintrayLicense: "Apache-2.0"
48 | ]
49 |
50 | dependencies = [
51 | appCompat : 'com.android.support:appcompat-v7:25.3.1',
52 | design : 'com.android.support:design:25.3.1',
53 | cardView : 'com.android.support:cardview-v7:25.3.1',
54 | recyclerView : 'com.android.support:recyclerview-v7:25.3.1',
55 | loading : 'com.yanzhenjie:loading:1.0.2',
56 | swipeRecyclerView: 'com.yanzhenjie:recyclerview-swipe:1.1.3'
57 | ]
58 | }
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_menu_define.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
28 |
29 |
34 |
35 |
41 |
42 |
43 |
44 |
49 |
50 |
55 |
56 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/nested/NestedActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.nested;
17 |
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.view.View;
21 |
22 | import com.yanzhenjie.recyclerview.swipe.sample.R;
23 | import com.yanzhenjie.recyclerview.swipe.sample.activity.BaseActivity;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | /**
29 | *
30 | * 几种嵌套使用的演示。
31 | *
32 | * Created by YanZhenjie on 2017/7/21.
33 | */
34 | public class NestedActivity extends BaseActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | mRecyclerView.setAdapter(mAdapter);
41 | mAdapter.notifyDataSetChanged(mDataList);
42 | }
43 |
44 | @Override
45 | public void onItemClick(View itemView, int position) {
46 | switch (position) {
47 | case 0: {
48 | startActivity(new Intent(this, CardViewActivity.class));
49 | break;
50 | }
51 | case 1: {
52 | startActivity(new Intent(this, DrawerActivity.class));
53 | break;
54 | }
55 | case 2: {
56 | startActivity(new Intent(this, ViewPagerActivity.class));
57 | break;
58 | }
59 | }
60 | }
61 |
62 | @Override
63 | protected List createDataList() {
64 | return Arrays.asList(getResources().getStringArray(R.array.nested_item));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/adapter/MainAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.adapter;
17 |
18 | import android.content.Context;
19 | import android.support.v7.widget.RecyclerView;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 | import android.widget.TextView;
23 |
24 | import com.yanzhenjie.recyclerview.swipe.sample.R;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * Created by YOLANDA on 2016/7/22.
30 | */
31 | public class MainAdapter extends BaseAdapter {
32 |
33 | private List mDataList;
34 |
35 | public MainAdapter(Context context) {
36 | super(context);
37 | }
38 |
39 | public void notifyDataSetChanged(List dataList) {
40 | this.mDataList = dataList;
41 | super.notifyDataSetChanged();
42 | }
43 |
44 | @Override
45 | public int getItemCount() {
46 | return mDataList == null ? 0 : mDataList.size();
47 | }
48 |
49 | @Override
50 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
51 | return new ViewHolder(getInflater().inflate(R.layout.item_menu_main, parent, false));
52 | }
53 |
54 | @Override
55 | public void onBindViewHolder(ViewHolder holder, int position) {
56 | holder.setData(mDataList.get(position));
57 | }
58 |
59 | static class ViewHolder extends RecyclerView.ViewHolder {
60 | TextView tvTitle;
61 |
62 | public ViewHolder(View itemView) {
63 | super(itemView);
64 | tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
65 | }
66 |
67 | public void setData(String title) {
68 | this.tvTitle.setText(title);
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/move/MoveActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.move;
17 |
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.view.View;
21 |
22 | import com.yanzhenjie.recyclerview.swipe.sample.R;
23 | import com.yanzhenjie.recyclerview.swipe.sample.activity.BaseActivity;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | /**
29 | *
30 | * Item拖拽和侧滑删除演示。
31 | *
32 | * Created by YanZhenjie on 2017/7/21.
33 | */
34 | public class MoveActivity extends BaseActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | mRecyclerView.setAdapter(mAdapter);
41 | mAdapter.notifyDataSetChanged(mDataList);
42 | }
43 |
44 | @Override
45 | public void onItemClick(View itemView, int position) {
46 | switch (position) {
47 | case 0: {
48 | startActivity(new Intent(this, DragSwipeListActivity.class));
49 | break;
50 | }
51 | case 1: {
52 | startActivity(new Intent(this, DragGridActivity.class));
53 | break;
54 | }
55 | case 2: {
56 | startActivity(new Intent(this, DragTouchListActivity.class));
57 | break;
58 | }
59 | case 3: {
60 | startActivity(new Intent(this, DefineActivity.class));
61 | break;
62 | }
63 | }
64 | }
65 |
66 | @Override
67 | protected List createDataList() {
68 | return Arrays.asList(getResources().getStringArray(R.array.touch_item));
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_drag_touch.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
35 |
36 |
45 |
46 |
57 |
58 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/menu/MenuActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.menu;
17 |
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.view.View;
21 |
22 | import com.yanzhenjie.recyclerview.swipe.sample.R;
23 | import com.yanzhenjie.recyclerview.swipe.sample.activity.BaseActivity;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | /**
29 | *
30 | * 侧滑菜单的演示。
31 | *
32 | * Created by YanZhenjie on 2017/7/21.
33 | */
34 | public class MenuActivity extends BaseActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | mRecyclerView.setAdapter(mAdapter);
41 | mAdapter.notifyDataSetChanged(mDataList);
42 | }
43 |
44 | @Override
45 | public void onItemClick(View itemView, int position) {
46 | switch (position) {
47 | case 0: {
48 | startActivity(new Intent(this, ListActivity.class));
49 | break;
50 | }
51 | case 1: {
52 | startActivity(new Intent(this, GridActivity.class));
53 | break;
54 | }
55 | case 2: {
56 | startActivity(new Intent(this, ViewTypeActivity.class));
57 | break;
58 | }
59 | case 3: {
60 | startActivity(new Intent(this, VerticalActivity.class));
61 | break;
62 | }
63 | case 4: {
64 | startActivity(new Intent(this, DefineActivity.class));
65 | break;
66 | }
67 | }
68 | }
69 |
70 | @Override
71 | protected List createDataList() {
72 | return Arrays.asList(getResources().getStringArray(R.array.menu_item));
73 | }
74 | }
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeHorizontal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.OverScroller;
21 |
22 | /**
23 | * Created by Yan Zhenjie on 2016/7/22.
24 | */
25 | abstract class SwipeHorizontal {
26 |
27 | private int direction;
28 | private View menuView;
29 | protected Checker mChecker;
30 |
31 | public SwipeHorizontal(int direction, View menuView) {
32 | this.direction = direction;
33 | this.menuView = menuView;
34 | mChecker = new Checker();
35 | }
36 |
37 | public boolean canSwipe() {
38 | if (menuView instanceof ViewGroup) {
39 | return ((ViewGroup) menuView).getChildCount() > 0;
40 | }
41 | return false;
42 | }
43 |
44 | public boolean isCompleteClose(int scrollX) {
45 | int i = -getMenuView().getWidth() * getDirection();
46 | return scrollX == 0 && i != 0;
47 | }
48 |
49 | public abstract boolean isMenuOpen(int scrollX);
50 |
51 | public abstract boolean isMenuOpenNotEqual(int scrollX);
52 |
53 | public abstract void autoOpenMenu(OverScroller scroller, int scrollX, int duration);
54 |
55 | public abstract void autoCloseMenu(OverScroller scroller, int scrollX, int duration);
56 |
57 | public abstract Checker checkXY(int x, int y);
58 |
59 | public abstract boolean isClickOnContentView(int contentViewWidth, float x);
60 |
61 | public int getDirection() {
62 | return direction;
63 | }
64 |
65 | public View getMenuView() {
66 | return menuView;
67 | }
68 |
69 | public int getMenuWidth() {
70 | return menuView.getWidth();
71 | }
72 |
73 | public static final class Checker {
74 | public int x;
75 | public int y;
76 | public boolean shouldResetSwipe;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeLeftHorizontal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | import android.view.View;
19 | import android.widget.OverScroller;
20 |
21 | /**
22 | * Created by Yan Zhenjie on 2016/7/22.
23 | */
24 | class SwipeLeftHorizontal extends SwipeHorizontal {
25 |
26 | public SwipeLeftHorizontal(View menuView) {
27 | super(SwipeMenuRecyclerView.LEFT_DIRECTION, menuView);
28 | }
29 |
30 | @Override
31 | public boolean isMenuOpen(int scrollX) {
32 | int i = -getMenuView().getWidth() * getDirection();
33 | return scrollX <= i && i != 0;
34 | }
35 |
36 | @Override
37 | public boolean isMenuOpenNotEqual(int scrollX) {
38 | return scrollX < -getMenuView().getWidth() * getDirection();
39 | }
40 |
41 | @Override
42 | public void autoOpenMenu(OverScroller scroller, int scrollX, int duration) {
43 | scroller.startScroll(Math.abs(scrollX), 0, getMenuView().getWidth() - Math.abs(scrollX), 0, duration);
44 | }
45 |
46 | @Override
47 | public void autoCloseMenu(OverScroller scroller, int scrollX, int duration) {
48 | scroller.startScroll(-Math.abs(scrollX), 0, Math.abs(scrollX), 0, duration);
49 | }
50 |
51 | @Override
52 | public Checker checkXY(int x, int y) {
53 | mChecker.x = x;
54 | mChecker.y = y;
55 | mChecker.shouldResetSwipe = false;
56 | if (mChecker.x == 0) {
57 | mChecker.shouldResetSwipe = true;
58 | }
59 | if (mChecker.x >= 0) {
60 | mChecker.x = 0;
61 | }
62 | if (mChecker.x <= -getMenuView().getWidth()) {
63 | mChecker.x = -getMenuView().getWidth();
64 | }
65 | return mChecker;
66 | }
67 |
68 | @Override
69 | public boolean isClickOnContentView(int contentViewWidth, float x) {
70 | return x > getMenuView().getWidth();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeRightHorizontal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | import android.view.View;
19 | import android.widget.OverScroller;
20 |
21 | /**
22 | * Created by Yan Zhenjie on 2016/7/22.
23 | */
24 | class SwipeRightHorizontal extends SwipeHorizontal {
25 |
26 | public SwipeRightHorizontal(View menuView) {
27 | super(SwipeMenuRecyclerView.RIGHT_DIRECTION, menuView);
28 | }
29 |
30 | @Override
31 | public boolean isMenuOpen(int scrollX) {
32 | int i = -getMenuView().getWidth() * getDirection();
33 | return scrollX >= i && i != 0;
34 | }
35 |
36 | @Override
37 | public boolean isMenuOpenNotEqual(int scrollX) {
38 | return scrollX > -getMenuView().getWidth() * getDirection();
39 | }
40 |
41 | @Override
42 | public void autoOpenMenu(OverScroller scroller, int scrollX, int duration) {
43 | scroller.startScroll(Math.abs(scrollX), 0, getMenuView().getWidth() - Math.abs(scrollX), 0, duration);
44 | }
45 |
46 | @Override
47 | public void autoCloseMenu(OverScroller scroller, int scrollX, int duration) {
48 | scroller.startScroll(-Math.abs(scrollX), 0, Math.abs(scrollX), 0, duration);
49 | }
50 |
51 | @Override
52 | public Checker checkXY(int x, int y) {
53 | mChecker.x = x;
54 | mChecker.y = y;
55 | mChecker.shouldResetSwipe = false;
56 | if (mChecker.x == 0) {
57 | mChecker.shouldResetSwipe = true;
58 | }
59 | if (mChecker.x < 0) {
60 | mChecker.x = 0;
61 | }
62 | if (mChecker.x > getMenuView().getWidth()) {
63 | mChecker.x = getMenuView().getWidth();
64 | }
65 | return mChecker;
66 | }
67 |
68 | @Override
69 | public boolean isClickOnContentView(int contentViewWidth, float x) {
70 | return x < (contentViewWidth - getMenuView().getWidth());
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_menu_pager_.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
25 |
26 |
31 |
32 |
38 |
39 |
45 |
46 |
52 |
53 |
59 |
60 |
61 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_menu_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
25 |
26 |
34 |
35 |
42 |
43 |
48 |
49 |
55 |
56 |
57 |
58 |
63 |
64 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/move/DragTouchListActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.move;
17 |
18 | import android.os.Bundle;
19 | import android.support.v7.widget.RecyclerView;
20 | import android.widget.Toast;
21 |
22 | import com.yanzhenjie.recyclerview.swipe.sample.adapter.BaseAdapter;
23 | import com.yanzhenjie.recyclerview.swipe.sample.adapter.DragTouchAdapter;
24 | import com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener;
25 |
26 | import java.util.Collections;
27 |
28 | /**
29 | *
30 | * 拖拽Item + 侧滑删除,默认侧滑删除只支持List形式。
31 | *
32 | * Created by Yan Zhenjie on 2016/8/3.
33 | */
34 | public class DragTouchListActivity extends BaseDragActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
41 | mRecyclerView.setItemViewSwipeEnabled(true); // 滑动删除,默认关闭。
42 | }
43 |
44 | @Override
45 | protected OnItemMoveListener getItemMoveListener() {
46 | return onItemMoveListener;
47 | }
48 |
49 | @Override
50 | protected BaseAdapter createAdapter() {
51 | return new DragTouchAdapter(this, mRecyclerView);
52 | }
53 |
54 | /**
55 | * 监听拖拽和侧滑删除,更新UI和数据源。
56 | */
57 | private OnItemMoveListener onItemMoveListener = new OnItemMoveListener() {
58 | @Override
59 | public boolean onItemMove(RecyclerView.ViewHolder srcHolder, RecyclerView.ViewHolder targetHolder) {
60 | // 不同的ViewType不能拖拽换位置。
61 | if (srcHolder.getItemViewType() != targetHolder.getItemViewType()) return false;
62 |
63 | int fromPosition = srcHolder.getAdapterPosition();
64 | int toPosition = targetHolder.getAdapterPosition();
65 |
66 | Collections.swap(mDataList, fromPosition, toPosition);
67 | mAdapter.notifyItemMoved(fromPosition, toPosition);
68 | return true;// 返回true表示处理了并可以换位置,返回false表示你没有处理并不能换位置。
69 | }
70 |
71 | @Override
72 | public void onItemDismiss(RecyclerView.ViewHolder srcHolder) {
73 | int position = srcHolder.getAdapterPosition();
74 | mDataList.remove(position);
75 | mAdapter.notifyItemRemoved(position);
76 | Toast.makeText(DragTouchListActivity.this, "现在的第" + position + "条被删除。", Toast.LENGTH_SHORT).show();
77 | }
78 |
79 | };
80 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity;
17 |
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.view.View;
21 |
22 | import com.yanzhenjie.recyclerview.swipe.sample.R;
23 | import com.yanzhenjie.recyclerview.swipe.sample.activity.group.GroupActivity;
24 | import com.yanzhenjie.recyclerview.swipe.sample.activity.header.HeaderViewActivity;
25 | import com.yanzhenjie.recyclerview.swipe.sample.activity.load.RefreshLoadActivity;
26 | import com.yanzhenjie.recyclerview.swipe.sample.activity.menu.MenuActivity;
27 | import com.yanzhenjie.recyclerview.swipe.sample.activity.move.MoveActivity;
28 | import com.yanzhenjie.recyclerview.swipe.sample.activity.nested.NestedActivity;
29 |
30 | import java.util.Arrays;
31 | import java.util.List;
32 |
33 |
34 | /**
35 | *
36 | * Demo入口。
37 | *
38 | * Created by YOLANDA on 2016/7/22.
39 | */
40 | public class MainActivity extends BaseActivity {
41 |
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 |
46 | mRecyclerView.setAdapter(mAdapter);
47 | mAdapter.notifyDataSetChanged(mDataList);
48 | }
49 |
50 | @Override
51 | public void onItemClick(View itemView, int position) {
52 | switch (position) {
53 | case 0: {
54 | startActivity(new Intent(this, MenuActivity.class));
55 | break;
56 | }
57 | case 1: {
58 | startActivity(new Intent(this, MoveActivity.class));
59 | break;
60 | }
61 | case 2: {
62 | startActivity(new Intent(this, HeaderViewActivity.class));
63 | break;
64 | }
65 | case 3: {
66 | startActivity(new Intent(this, RefreshLoadActivity.class));
67 | break;
68 | }
69 | case 4: {
70 | startActivity(new Intent(this, NestedActivity.class));
71 | break;
72 | }
73 | case 5: {
74 | startActivity(new Intent(this, GroupActivity.class));
75 | break;
76 | }
77 | }
78 | }
79 |
80 | @Override
81 | protected boolean displayHomeAsUpEnabled() {
82 | return false;
83 | }
84 |
85 | @Override
86 | protected List createDataList() {
87 | return Arrays.asList(getResources().getStringArray(R.array.main_item));
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/group/LayoutActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.group;
17 |
18 | import android.os.Bundle;
19 | import android.support.annotation.Nullable;
20 | import android.support.design.widget.TabLayout;
21 | import android.support.v7.app.ActionBar;
22 | import android.support.v7.app.AppCompatActivity;
23 | import android.support.v7.widget.Toolbar;
24 | import android.view.MenuItem;
25 | import android.widget.Toast;
26 |
27 | import com.yanzhenjie.recyclerview.swipe.sample.R;
28 |
29 | /**
30 | *
31 | * 和Sticky的基本使用。
32 | *
33 | * Created by YanZhenjie on 2017/7/22.
34 | */
35 | public class LayoutActivity extends AppCompatActivity {
36 |
37 | @Override
38 | protected void onCreate(@Nullable Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_group_layout);
41 |
42 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
43 | setSupportActionBar(toolbar);
44 | ActionBar actionBar = getSupportActionBar();
45 | assert actionBar != null;
46 | actionBar.setDisplayHomeAsUpEnabled(true);
47 | initTabLayout();
48 |
49 | /*
50 | * 注意:
51 | * 1. 要给需要sticky的View设置tab属性:android:tag="sticky";
52 | * 2. 也可以Java动态设置:view.setTag("sticky");
53 | * 3. 如果这个sticky的View是可点击的,那么tag为:android:tag="sticky-nonconstant"或者view.setTag("sticky-nonconstant");
54 | */
55 | }
56 |
57 | private void initTabLayout() {
58 | TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
59 | TabLayout.Tab tab = tabLayout.newTab();
60 | tab.setText("商品预览");
61 | tabLayout.addTab(tab);
62 |
63 | tab = tabLayout.newTab();
64 | tab.setText("商品详情");
65 | tabLayout.addTab(tab);
66 |
67 | tab = tabLayout.newTab();
68 | tab.setText("商品描述");
69 | tabLayout.addTab(tab);
70 |
71 | tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
72 | @Override
73 | public void onTabSelected(TabLayout.Tab tab) {
74 | Toast.makeText(LayoutActivity.this, "第" + tab.getPosition() + "个Tab", Toast.LENGTH_SHORT).show();
75 | }
76 |
77 | @Override
78 | public void onTabUnselected(TabLayout.Tab tab) {
79 | }
80 |
81 | @Override
82 | public void onTabReselected(TabLayout.Tab tab) {
83 | }
84 | });
85 | }
86 |
87 | @Override
88 | public boolean onOptionsItemSelected(MenuItem item) {
89 | if (item.getItemId() == android.R.id.home) {
90 | finish();
91 | }
92 | return true;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/adapter/DragTouchAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.adapter;
17 |
18 | import android.content.Context;
19 | import android.support.v7.widget.RecyclerView;
20 | import android.view.MotionEvent;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 | import android.widget.TextView;
24 |
25 | import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
26 | import com.yanzhenjie.recyclerview.swipe.sample.R;
27 |
28 | import java.util.List;
29 |
30 | /**
31 | *
32 | * 触摸即开始拖拽。
33 | *
34 | * Created by YanZhenjie on 2016/7/22.
35 | */
36 | public class DragTouchAdapter extends BaseAdapter {
37 |
38 | private SwipeMenuRecyclerView mMenuRecyclerView;
39 | private List mDataList;
40 |
41 | public DragTouchAdapter(Context context, SwipeMenuRecyclerView menuRecyclerView) {
42 | super(context);
43 | this.mMenuRecyclerView = menuRecyclerView;
44 | }
45 |
46 | @Override
47 | public void notifyDataSetChanged(List dataList) {
48 | this.mDataList = dataList;
49 | super.notifyDataSetChanged();
50 | }
51 |
52 | @Override
53 | public int getItemCount() {
54 | return mDataList == null ? 0 : mDataList.size();
55 | }
56 |
57 | @Override
58 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
59 | ViewHolder viewHolder = new ViewHolder(getInflater().inflate(R.layout.item_drag_touch, parent, false));
60 | viewHolder.mMenuRecyclerView = mMenuRecyclerView;
61 | return viewHolder;
62 | }
63 |
64 | @Override
65 | public void onBindViewHolder(ViewHolder holder, int position) {
66 | holder.setData(mDataList.get(position));
67 | }
68 |
69 | static class ViewHolder extends RecyclerView.ViewHolder implements View.OnTouchListener {
70 |
71 | TextView tvTitle;
72 | SwipeMenuRecyclerView mMenuRecyclerView;
73 |
74 | public ViewHolder(View itemView) {
75 | super(itemView);
76 | tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
77 | itemView.findViewById(R.id.iv_touch).setOnTouchListener(this);
78 | }
79 |
80 | public void setData(String title) {
81 | this.tvTitle.setText(title);
82 | }
83 |
84 |
85 | @Override
86 | public boolean onTouch(View v, MotionEvent event) {
87 | int action = event.getAction();
88 | switch (action) {
89 | case MotionEvent.ACTION_DOWN: {
90 | mMenuRecyclerView.startDrag(this);
91 | break;
92 | }
93 | }
94 | return false;
95 | }
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_menu_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
25 |
26 |
31 |
32 |
36 |
37 |
44 |
45 |
51 |
52 |
60 |
61 |
68 |
69 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeSwitch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | /**
19 | * Created by Yan Zhenjie on 2016/7/27.
20 | */
21 | public interface SwipeSwitch {
22 |
23 | /**
24 | * The menu is open?
25 | *
26 | * @return true, otherwise false.
27 | */
28 | boolean isMenuOpen();
29 |
30 | /**
31 | * The menu is open on the left?
32 | *
33 | * @return true, otherwise false.
34 | */
35 | boolean isLeftMenuOpen();
36 |
37 | /**
38 | * The menu is open on the right?
39 | *
40 | * @return true, otherwise false.
41 | */
42 | boolean isRightMenuOpen();
43 |
44 | /**
45 | * The menu is completely open?
46 | *
47 | * @return true, otherwise false.
48 | */
49 | boolean isCompleteOpen();
50 |
51 | /**
52 | * The menu is completely open on the left?
53 | *
54 | * @return true, otherwise false.
55 | */
56 | boolean isLeftCompleteOpen();
57 |
58 | /**
59 | * The menu is completely open on the right?
60 | *
61 | * @return true, otherwise false.
62 | */
63 | boolean isRightCompleteOpen();
64 |
65 | /**
66 | * The menu is open?
67 | *
68 | * @return true, otherwise false.
69 | */
70 | boolean isMenuOpenNotEqual();
71 |
72 | /**
73 | * The menu is open on the left?
74 | *
75 | * @return true, otherwise false.
76 | */
77 | boolean isLeftMenuOpenNotEqual();
78 |
79 | /**
80 | * The menu is open on the right?
81 | *
82 | * @return true, otherwise false.
83 | */
84 | boolean isRightMenuOpenNotEqual();
85 |
86 | /**
87 | * Open the current menu.
88 | */
89 | void smoothOpenMenu();
90 |
91 | /**
92 | * Open the menu on left.
93 | */
94 | void smoothOpenLeftMenu();
95 |
96 | /**
97 | * Open the menu on right.
98 | */
99 | void smoothOpenRightMenu();
100 |
101 | /**
102 | * Open the menu on left for the duration.
103 | *
104 | * @param duration duration time.
105 | */
106 | void smoothOpenLeftMenu(int duration);
107 |
108 | /**
109 | * Open the menu on right for the duration.
110 | *
111 | * @param duration duration time.
112 | */
113 | void smoothOpenRightMenu(int duration);
114 |
115 | // ---------- closeMenu. ---------- //
116 |
117 | /**
118 | * Smooth closed the menu.
119 | */
120 | void smoothCloseMenu();
121 |
122 | /**
123 | * Smooth closed the menu on the left.
124 | */
125 | void smoothCloseLeftMenu();
126 |
127 | /**
128 | * Smooth closed the menu on the right.
129 | */
130 | void smoothCloseRightMenu();
131 |
132 | /**
133 | * Smooth closed the menu for the duration.
134 | *
135 | * @param duration duration time.
136 | */
137 | void smoothCloseMenu(int duration);
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeMenuBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | import android.graphics.drawable.Drawable;
19 | import android.support.annotation.ColorInt;
20 | import android.support.annotation.ColorRes;
21 | import android.support.annotation.DrawableRes;
22 | import android.support.v4.content.ContextCompat;
23 | import android.support.v4.view.ViewCompat;
24 | import android.view.View;
25 | import android.widget.ImageView;
26 | import android.widget.TextView;
27 |
28 | /**
29 | * Created by YanZhenjie on 2017/7/20.
30 | */
31 | public final class SwipeMenuBridge {
32 |
33 | @SwipeMenuRecyclerView.DirectionMode
34 | private final int mDirection;
35 | private final int mPosition;
36 | private final SwipeSwitch mSwipeSwitch;
37 | private final View mViewRoot;
38 |
39 | int mAdapterPosition;
40 | TextView mTextView;
41 | ImageView mImageView;
42 |
43 | SwipeMenuBridge(@SwipeMenuRecyclerView.DirectionMode int direction, int position, SwipeSwitch swipeSwitch, View viewRoot) {
44 | mDirection = direction;
45 | mPosition = position;
46 | mSwipeSwitch = swipeSwitch;
47 | mViewRoot = viewRoot;
48 | }
49 |
50 | public SwipeMenuBridge setBackgroundDrawable(@DrawableRes int resId) {
51 | return setBackgroundDrawable(ContextCompat.getDrawable(mViewRoot.getContext(), resId));
52 | }
53 |
54 | public SwipeMenuBridge setBackgroundDrawable(Drawable background) {
55 | ViewCompat.setBackground(mViewRoot, background);
56 | return this;
57 | }
58 |
59 | public SwipeMenuBridge setBackgroundColorResource(@ColorRes int color) {
60 | return setBackgroundColor(ContextCompat.getColor(mViewRoot.getContext(), color));
61 | }
62 |
63 | public SwipeMenuBridge setBackgroundColor(@ColorInt int color) {
64 | mViewRoot.setBackgroundColor(color);
65 | return this;
66 | }
67 |
68 | public SwipeMenuBridge setImage(int resId) {
69 | return setImage(ContextCompat.getDrawable(mViewRoot.getContext(), resId));
70 | }
71 |
72 | public SwipeMenuBridge setImage(Drawable icon) {
73 | if (mImageView != null)
74 | mImageView.setImageDrawable(icon);
75 | return this;
76 | }
77 |
78 | public SwipeMenuBridge setText(int resId) {
79 | return setText(mViewRoot.getContext().getString(resId));
80 | }
81 |
82 | public SwipeMenuBridge setText(String title) {
83 | if (mTextView != null)
84 | mTextView.setText(title);
85 | return this;
86 | }
87 |
88 | @SwipeMenuRecyclerView.DirectionMode
89 | public int getDirection() {
90 | return mDirection;
91 | }
92 |
93 | public int getPosition() {
94 | return mPosition;
95 | }
96 |
97 | public int getAdapterPosition() {
98 | return mAdapterPosition;
99 | }
100 |
101 | public void closeMenu() {
102 | mSwipeSwitch.smoothCloseMenu();
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_menu_define.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
25 |
26 |
31 |
32 |
44 |
45 |
50 |
51 |
55 |
56 |
61 |
62 |
63 |
68 |
69 |
74 |
75 |
76 |
80 |
81 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeMenu.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | import android.content.Context;
19 | import android.support.annotation.IntDef;
20 | import android.widget.LinearLayout;
21 |
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | /**
28 | * Created by Yan Zhenjie on 2016/7/22.
29 | */
30 | public class SwipeMenu {
31 |
32 | @IntDef({HORIZONTAL, VERTICAL})
33 | @Retention(RetentionPolicy.SOURCE)
34 | public @interface OrientationMode {
35 | }
36 |
37 | public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
38 | public static final int VERTICAL = LinearLayout.VERTICAL;
39 |
40 | private SwipeMenuLayout mSwipeMenuLayout;
41 |
42 | private int mViewType;
43 |
44 | private int orientation = HORIZONTAL;
45 |
46 | private List mSwipeMenuItems = new ArrayList<>(2);
47 |
48 | public SwipeMenu(SwipeMenuLayout swipeMenuLayout, int viewType) {
49 | this.mSwipeMenuLayout = swipeMenuLayout;
50 | this.mViewType = viewType;
51 | }
52 |
53 | /**
54 | * Set a percentage.
55 | *
56 | * @param openPercent such as 0.5F.
57 | */
58 | public void setOpenPercent(float openPercent) {
59 | if (openPercent != mSwipeMenuLayout.getOpenPercent()) {
60 | openPercent = openPercent > 1 ? 1 : (openPercent < 0 ? 0 : openPercent);
61 | mSwipeMenuLayout.setOpenPercent(openPercent);
62 | }
63 | }
64 |
65 | /**
66 | * The duration of the set.
67 | *
68 | * @param scrollerDuration such 500.
69 | */
70 | public void setScrollerDuration(int scrollerDuration) {
71 | this.mSwipeMenuLayout.setScrollerDuration(scrollerDuration);
72 | }
73 |
74 | /**
75 | * Set the menu orientation.
76 | *
77 | * @param orientation use {@link SwipeMenu#HORIZONTAL} or {@link SwipeMenu#VERTICAL}.
78 | * @see SwipeMenu#HORIZONTAL
79 | * @see SwipeMenu#VERTICAL
80 | */
81 | public void setOrientation(@OrientationMode int orientation) {
82 | if (orientation != HORIZONTAL && orientation != VERTICAL)
83 | throw new IllegalArgumentException("Use SwipeMenu#HORIZONTAL or SwipeMenu#VERTICAL.");
84 | this.orientation = orientation;
85 | }
86 |
87 | /**
88 | * Get the menu orientation.
89 | *
90 | * @return {@link SwipeMenu#HORIZONTAL} or {@link SwipeMenu#VERTICAL}.
91 | */
92 | @OrientationMode
93 | public int getOrientation() {
94 | return orientation;
95 | }
96 |
97 | public void addMenuItem(SwipeMenuItem item) {
98 | mSwipeMenuItems.add(item);
99 | }
100 |
101 | public void removeMenuItem(SwipeMenuItem item) {
102 | mSwipeMenuItems.remove(item);
103 | }
104 |
105 | public List getMenuItems() {
106 | return mSwipeMenuItems;
107 | }
108 |
109 | public SwipeMenuItem getMenuItem(int index) {
110 | return mSwipeMenuItems.get(index);
111 | }
112 |
113 | public Context getContext() {
114 | return mSwipeMenuLayout.getContext();
115 | }
116 |
117 | public int getViewType() {
118 | return mViewType;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/nested/CardViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.yanzhenjie.recyclerview.swipe.sample.activity.nested;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.CardView;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.yanzhenjie.recyclerview.swipe.sample.R;
15 | import com.yanzhenjie.recyclerview.swipe.sample.activity.BaseActivity;
16 | import com.yanzhenjie.recyclerview.swipe.sample.adapter.BaseAdapter;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | *
23 | * Item是CardView时的演示,Item的布局需要特殊处理一下。
24 | *
25 | * Created by Yan Zhenjie on 2017/3/12.
26 | */
27 | public class CardViewActivity extends BaseActivity {
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 |
33 | mRecyclerView.setAdapter(mAdapter);
34 | mAdapter.notifyDataSetChanged(mDataList);
35 | }
36 |
37 | /**
38 | * 主要就是这里的这个Adapter,里面的ItemView需要处理一下。
39 | */
40 | @Override
41 | protected BaseAdapter createAdapter() {
42 | return new MenuCardAdapter(this);
43 | }
44 |
45 | @Override
46 | protected RecyclerView.ItemDecoration createItemDecoration() {
47 | return new RecyclerView.ItemDecoration() {
48 | @Override
49 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
50 | outRect.set(20, 20, 20, 20);
51 | }
52 | };
53 | }
54 |
55 | /**
56 | * 就是这个适配器的Item的Layout需要处理,其实就是自定义Menu啦,一模一样。
57 | */
58 | private static class MenuCardAdapter extends BaseAdapter {
59 |
60 | private List mDataList;
61 |
62 | MenuCardAdapter(Context context) {
63 | super(context);
64 | }
65 |
66 | @Override
67 | public void notifyDataSetChanged(List dataList) {
68 | this.mDataList = dataList;
69 | super.notifyDataSetChanged();
70 | }
71 |
72 |
73 | @Override
74 | public int getItemCount() {
75 | return mDataList == null ? 0 : mDataList.size();
76 | }
77 |
78 | @Override
79 | public DefaultViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
80 | return new DefaultViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_menu_card, parent, false));
81 | }
82 |
83 | @Override
84 | public void onBindViewHolder(DefaultViewHolder holder, int position) {
85 | holder.setData(mDataList.get(position));
86 | }
87 | }
88 |
89 | static class DefaultViewHolder extends RecyclerView.ViewHolder {
90 | TextView tvTitle;
91 |
92 | public DefaultViewHolder(View itemView) {
93 | super(itemView);
94 | tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
95 |
96 | ((CardView) itemView).getChildAt(0).setOnClickListener(new View.OnClickListener() {
97 | @Override
98 | public void onClick(View v) {
99 | Toast.makeText(v.getContext(), "第" + getAdapterPosition() + "个", Toast.LENGTH_SHORT).show();
100 | }
101 | });
102 | }
103 |
104 | public void setData(String title) {
105 | this.tvTitle.setText(title);
106 | }
107 | }
108 |
109 | @Override
110 | protected List createDataList() {
111 | List strings = new ArrayList<>();
112 | for (int i = 0; i < 100; i++) {
113 | strings.add("第" + i + "个Item");
114 | }
115 | return strings;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/move/DragSwipeListActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.move;
17 |
18 | import android.os.Bundle;
19 | import android.support.v7.widget.RecyclerView;
20 | import android.support.v7.widget.SwitchCompat;
21 | import android.view.View;
22 | import android.widget.CompoundButton;
23 | import android.widget.Toast;
24 |
25 | import com.yanzhenjie.recyclerview.swipe.sample.R;
26 | import com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener;
27 |
28 | import java.util.Collections;
29 |
30 | /**
31 | *
32 | * 拖拽Item + 侧滑删除,默认侧滑删除只支持List形式。
33 | *
34 | * Created by Yan Zhenjie on 2016/8/3.
35 | */
36 | public class DragSwipeListActivity extends BaseDragActivity {
37 |
38 | View mHeaderView;
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 |
44 | mHeaderView = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
45 | mRecyclerView.addHeaderView(mHeaderView);
46 |
47 | SwitchCompat switchCompat = (SwitchCompat) mHeaderView.findViewById(R.id.switch_compat);
48 | switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
49 | @Override
50 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
51 | // 控制是否可以侧滑删除。
52 | mRecyclerView.setItemViewSwipeEnabled(isChecked);
53 | }
54 | });
55 |
56 | mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
57 | mRecyclerView.setItemViewSwipeEnabled(true); // 滑动删除,默认关闭。
58 | }
59 |
60 | @Override
61 | protected OnItemMoveListener getItemMoveListener() {
62 | // 监听拖拽和侧滑删除,更新UI和数据源。
63 | return new OnItemMoveListener() {
64 | @Override
65 | public boolean onItemMove(RecyclerView.ViewHolder srcHolder, RecyclerView.ViewHolder targetHolder) {
66 | // 不同的ViewType不能拖拽换位置。
67 | if (srcHolder.getItemViewType() != targetHolder.getItemViewType()) return false;
68 |
69 | // 真实的Position:通过ViewHolder拿到的position都需要减掉HeadView的数量。
70 | int fromPosition = srcHolder.getAdapterPosition() - mRecyclerView.getHeaderItemCount();
71 | int toPosition = targetHolder.getAdapterPosition() - mRecyclerView.getHeaderItemCount();
72 |
73 | Collections.swap(mDataList, fromPosition, toPosition);
74 | mAdapter.notifyItemMoved(fromPosition, toPosition);
75 | return true;// 返回true表示处理了并可以换位置,返回false表示你没有处理并不能换位置。
76 | }
77 |
78 | @Override
79 | public void onItemDismiss(RecyclerView.ViewHolder srcHolder) {
80 | int adapterPosition = srcHolder.getAdapterPosition();
81 | int position = adapterPosition - mRecyclerView.getHeaderItemCount();
82 |
83 | if (mRecyclerView.getHeaderItemCount() > 0 && adapterPosition == 0) { // HeaderView。
84 | mRecyclerView.removeHeaderView(mHeaderView);
85 | Toast.makeText(DragSwipeListActivity.this, "HeaderView被删除。", Toast.LENGTH_SHORT).show();
86 | } else { // 普通Item。
87 | mDataList.remove(position);
88 | mAdapter.notifyItemRemoved(position);
89 | Toast.makeText(DragSwipeListActivity.this, "现在的第" + position + "条被删除。", Toast.LENGTH_SHORT).show();
90 | }
91 | }
92 | };
93 | }
94 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity;
17 |
18 | import android.os.Bundle;
19 | import android.support.v4.content.ContextCompat;
20 | import android.support.v7.app.ActionBar;
21 | import android.support.v7.app.AppCompatActivity;
22 | import android.support.v7.widget.LinearLayoutManager;
23 | import android.support.v7.widget.RecyclerView;
24 | import android.support.v7.widget.Toolbar;
25 | import android.view.MenuItem;
26 | import android.view.View;
27 | import android.widget.Toast;
28 |
29 | import com.yanzhenjie.recyclerview.swipe.SwipeItemClickListener;
30 | import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
31 | import com.yanzhenjie.recyclerview.swipe.sample.R;
32 | import com.yanzhenjie.recyclerview.swipe.sample.adapter.BaseAdapter;
33 | import com.yanzhenjie.recyclerview.swipe.sample.adapter.MainAdapter;
34 | import com.yanzhenjie.recyclerview.swipe.widget.DefaultItemDecoration;
35 |
36 | import java.util.ArrayList;
37 | import java.util.List;
38 |
39 | /**
40 | * Created by YanZhenjie on 2017/7/21.
41 | */
42 | public class BaseActivity extends AppCompatActivity implements SwipeItemClickListener {
43 |
44 | protected Toolbar mToolbar;
45 | protected ActionBar mActionBar;
46 | protected SwipeMenuRecyclerView mRecyclerView;
47 | protected RecyclerView.LayoutManager mLayoutManager;
48 | protected RecyclerView.ItemDecoration mItemDecoration;
49 |
50 | protected BaseAdapter mAdapter;
51 | protected List mDataList;
52 |
53 | @Override
54 | protected void onCreate(Bundle savedInstanceState) {
55 | super.onCreate(savedInstanceState);
56 | setContentView(getContentView());
57 |
58 | mToolbar = (Toolbar) findViewById(R.id.toolbar);
59 | mRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
60 |
61 |
62 | setSupportActionBar(mToolbar);
63 | mActionBar = getSupportActionBar();
64 | if (displayHomeAsUpEnabled()) {
65 | mActionBar.setDisplayHomeAsUpEnabled(true);
66 | }
67 |
68 | mLayoutManager = createLayoutManager();
69 | mItemDecoration = createItemDecoration();
70 | mDataList = createDataList();
71 | mAdapter = createAdapter();
72 |
73 | mRecyclerView.setLayoutManager(mLayoutManager);
74 | mRecyclerView.addItemDecoration(mItemDecoration);
75 | mRecyclerView.setSwipeItemClickListener(this);
76 | }
77 |
78 | protected int getContentView() {
79 | return R.layout.activity_scroll;
80 | }
81 |
82 | protected RecyclerView.LayoutManager createLayoutManager() {
83 | return new LinearLayoutManager(this);
84 | }
85 |
86 | protected RecyclerView.ItemDecoration createItemDecoration() {
87 | return new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color));
88 | }
89 |
90 | protected List createDataList() {
91 | List dataList = new ArrayList<>();
92 | for (int i = 0; i < 100; i++) {
93 | dataList.add("第" + i + "个Item");
94 | }
95 | return dataList;
96 | }
97 |
98 | protected BaseAdapter createAdapter() {
99 | return new MainAdapter(this);
100 | }
101 |
102 | @Override
103 | public void onItemClick(View itemView, int position) {
104 | Toast.makeText(this, "第" + position + "个", Toast.LENGTH_SHORT).show();
105 | }
106 |
107 | protected boolean displayHomeAsUpEnabled() {
108 | return true;
109 | }
110 |
111 | @Override
112 | public boolean onOptionsItemSelected(MenuItem item) {
113 | if (item.getItemId() == android.R.id.home) {
114 | finish();
115 | }
116 | return true;
117 | }
118 |
119 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/header/HeaderViewActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.header;
17 |
18 | import android.os.Bundle;
19 | import android.support.annotation.Nullable;
20 | import android.support.v4.content.ContextCompat;
21 | import android.support.v7.app.ActionBar;
22 | import android.support.v7.app.AppCompatActivity;
23 | import android.support.v7.widget.GridLayoutManager;
24 | import android.support.v7.widget.Toolbar;
25 | import android.view.MenuItem;
26 | import android.view.View;
27 | import android.widget.Toast;
28 |
29 | import com.yanzhenjie.recyclerview.swipe.SwipeItemClickListener;
30 | import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
31 | import com.yanzhenjie.recyclerview.swipe.sample.R;
32 | import com.yanzhenjie.recyclerview.swipe.sample.adapter.MainAdapter;
33 | import com.yanzhenjie.recyclerview.swipe.widget.DefaultItemDecoration;
34 |
35 | import java.util.ArrayList;
36 | import java.util.List;
37 |
38 | /**
39 | *
40 | * 添加HeaderView和添加FooterView。
41 | *
42 | * Created by YanZhenjie on 2017/7/21.
43 | */
44 | public class HeaderViewActivity extends AppCompatActivity implements SwipeItemClickListener {
45 |
46 | @Override
47 | protected void onCreate(@Nullable Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_scroll);
50 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
51 | setSupportActionBar(toolbar);
52 | ActionBar actionBar = getSupportActionBar();
53 | assert actionBar != null;
54 | actionBar.setDisplayHomeAsUpEnabled(true);
55 |
56 | SwipeMenuRecyclerView recyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
57 | recyclerView.setSwipeItemClickListener(this);
58 | recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
59 | recyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
60 |
61 | // HeaderView。
62 | View headerView = getLayoutInflater().inflate(R.layout.layout_header, recyclerView, false);
63 | headerView.findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
64 | @Override
65 | public void onClick(View v) {
66 | Toast.makeText(v.getContext(), "HeaderView", Toast.LENGTH_SHORT).show();
67 | }
68 | });
69 | recyclerView.addHeaderView(headerView);
70 |
71 | // FooterView。
72 | View footerView = getLayoutInflater().inflate(R.layout.layout_footer, recyclerView, false);
73 | footerView.findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
74 | @Override
75 | public void onClick(View v) {
76 | Toast.makeText(v.getContext(), "FooterView", Toast.LENGTH_SHORT).show();
77 | }
78 | });
79 | recyclerView.addFooterView(footerView);
80 |
81 | MainAdapter mainAdapter = new MainAdapter(this);
82 | recyclerView.setAdapter(mainAdapter);
83 | mainAdapter.notifyDataSetChanged(createDataList());
84 | }
85 |
86 | protected List createDataList() {
87 | List strings = new ArrayList<>();
88 | for (int i = 0; i < 100; i++) {
89 | strings.add("第" + i + "个Item");
90 | }
91 | return strings;
92 | }
93 |
94 | @Override
95 | public void onItemClick(View itemView, int position) {
96 | Toast.makeText(this, "第" + position + "个", Toast.LENGTH_SHORT).show();
97 | }
98 |
99 | @Override
100 | public boolean onOptionsItemSelected(MenuItem item) {
101 | if (item.getItemId() == android.R.id.home) {
102 | finish();
103 | }
104 | return true;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
20 |
21 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
42 |
45 |
48 |
51 |
54 |
57 |
58 |
59 |
62 |
65 |
68 |
71 |
74 |
75 |
76 |
79 |
80 |
81 |
84 |
87 |
90 |
91 |
92 |
95 |
98 |
101 |
104 |
105 |
106 |
109 |
112 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/touch/DefaultItemTouchHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.touch;
17 |
18 | import android.support.v7.widget.helper.CompatItemTouchHelper;
19 |
20 | /**
21 | * Created by Yolanda on 2016/4/19.
22 | */
23 | public class DefaultItemTouchHelper extends CompatItemTouchHelper {
24 |
25 | private DefaultItemTouchHelperCallback mDefaultItemTouchHelperCallback;
26 |
27 | /**
28 | * Create default item touch helper.
29 | */
30 | public DefaultItemTouchHelper() {
31 | this(new DefaultItemTouchHelperCallback());
32 | }
33 |
34 | /**
35 | * @param callback the behavior of ItemTouchHelper.
36 | */
37 | private DefaultItemTouchHelper(DefaultItemTouchHelperCallback callback) {
38 | super(callback);
39 | mDefaultItemTouchHelperCallback = (DefaultItemTouchHelperCallback) getCallback();
40 | }
41 |
42 | /**
43 | * Set OnItemMoveListener.
44 | *
45 | * @param onItemMoveListener {@link OnItemMoveListener}.
46 | */
47 | public void setOnItemMoveListener(OnItemMoveListener onItemMoveListener) {
48 | mDefaultItemTouchHelperCallback.setOnItemMoveListener(onItemMoveListener);
49 | }
50 |
51 | /**
52 | * Get OnItemMoveListener.
53 | *
54 | * @return {@link OnItemMoveListener}.
55 | */
56 | public OnItemMoveListener getOnItemMoveListener() {
57 | return mDefaultItemTouchHelperCallback.getOnItemMoveListener();
58 | }
59 |
60 | /**
61 | * Set OnItemMovementListener.
62 | *
63 | * @param onItemMovementListener {@link OnItemMovementListener}.
64 | */
65 | public void setOnItemMovementListener(OnItemMovementListener onItemMovementListener) {
66 | mDefaultItemTouchHelperCallback.setOnItemMovementListener(onItemMovementListener);
67 | }
68 |
69 | /**
70 | * Get OnItemMovementListener.
71 | *
72 | * @return {@link OnItemMovementListener}.
73 | */
74 | public OnItemMovementListener getOnItemMovementListener() {
75 | return mDefaultItemTouchHelperCallback.getOnItemMovementListener();
76 | }
77 |
78 | /**
79 | * Set can long press drag.
80 | *
81 | * @param canDrag drag true, otherwise is can't.
82 | */
83 | public void setLongPressDragEnabled(boolean canDrag) {
84 | mDefaultItemTouchHelperCallback.setLongPressDragEnabled(canDrag);
85 | }
86 |
87 | /**
88 | * Get can long press drag.
89 | *
90 | * @return drag true, otherwise is can't.
91 | */
92 | public boolean isLongPressDragEnabled() {
93 | return mDefaultItemTouchHelperCallback.isLongPressDragEnabled();
94 | }
95 |
96 |
97 | /**
98 | * Set can long press swipe.
99 | *
100 | * @param canSwipe swipe true, otherwise is can't.
101 | */
102 | public void setItemViewSwipeEnabled(boolean canSwipe) {
103 | mDefaultItemTouchHelperCallback.setItemViewSwipeEnabled(canSwipe);
104 | }
105 |
106 | /**
107 | * Get can long press swipe.
108 | *
109 | * @return swipe true, otherwise is can't.
110 | */
111 | public boolean isItemViewSwipeEnabled() {
112 | return this.mDefaultItemTouchHelperCallback.isItemViewSwipeEnabled();
113 | }
114 |
115 | /**
116 | * Set OnItemStateChangedListener.
117 | *
118 | * @param onItemStateChangedListener {@link OnItemStateChangedListener}.
119 | */
120 | public void setOnItemStateChangedListener(OnItemStateChangedListener onItemStateChangedListener) {
121 | this.mDefaultItemTouchHelperCallback.setOnItemStateChangedListener(onItemStateChangedListener);
122 | }
123 |
124 | /**
125 | * Get OnItemStateChangedListener.
126 | *
127 | * @return {@link OnItemStateChangedListener}.
128 | */
129 | public OnItemStateChangedListener getOnItemStateChangedListener() {
130 | return this.mDefaultItemTouchHelperCallback.getOnItemStateChangedListener();
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/move/DragGridActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.move;
17 |
18 | import android.os.Bundle;
19 | import android.support.v7.widget.GridLayoutManager;
20 | import android.support.v7.widget.RecyclerView;
21 | import android.support.v7.widget.SwitchCompat;
22 | import android.view.View;
23 | import android.widget.CompoundButton;
24 | import android.widget.Toast;
25 |
26 | import com.yanzhenjie.recyclerview.swipe.sample.R;
27 | import com.yanzhenjie.recyclerview.swipe.touch.OnItemMoveListener;
28 |
29 | import java.util.Collections;
30 |
31 | /**
32 | *
33 | * 拖拽Item,侧滑菜单一起使用,是Grid形式的。
34 | *
35 | * Created by Yan Zhenjie on 2016/8/3.
36 | */
37 | public class DragGridActivity extends BaseDragActivity {
38 |
39 | View mHeaderView;
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 |
45 | mHeaderView = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
46 | mRecyclerView.addHeaderView(mHeaderView);
47 |
48 | SwitchCompat switchCompat = (SwitchCompat) mHeaderView.findViewById(R.id.switch_compat);
49 | switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
50 | @Override
51 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
52 | mRecyclerView.setItemViewSwipeEnabled(isChecked);
53 | }
54 | });
55 |
56 | mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
57 | mRecyclerView.setItemViewSwipeEnabled(false); // 滑动删除,默认关闭。
58 | }
59 |
60 | @Override
61 | protected RecyclerView.LayoutManager createLayoutManager() {
62 | return new GridLayoutManager(this, 2);
63 | }
64 |
65 | @Override
66 | protected OnItemMoveListener getItemMoveListener() {
67 | // 监听拖拽和侧滑删除,更新UI和数据源。
68 | return new OnItemMoveListener() {
69 | @Override
70 | public boolean onItemMove(RecyclerView.ViewHolder srcHolder, RecyclerView.ViewHolder targetHolder) {
71 | // 不同的ViewType不能拖拽换位置。
72 | if (srcHolder.getItemViewType() != targetHolder.getItemViewType()) return false;
73 |
74 | // 真实的Position:通过ViewHolder拿到的position都需要减掉HeadView的数量。
75 | int fromPosition = srcHolder.getAdapterPosition() - mRecyclerView.getHeaderItemCount();
76 | int toPosition = targetHolder.getAdapterPosition() - mRecyclerView.getHeaderItemCount();
77 |
78 | if (fromPosition < toPosition)
79 | for (int i = fromPosition; i < toPosition; i++)
80 | Collections.swap(mDataList, i, i + 1);
81 | else
82 | for (int i = fromPosition; i > toPosition; i--)
83 | Collections.swap(mDataList, i, i - 1);
84 |
85 | mAdapter.notifyItemMoved(fromPosition, toPosition);
86 | return true;// 返回true表示处理了,返回false表示你没有处理。
87 | }
88 |
89 | @Override
90 | public void onItemDismiss(RecyclerView.ViewHolder srcHolder) {
91 | int adapterPosition = srcHolder.getAdapterPosition();
92 | int position = adapterPosition - mRecyclerView.getHeaderItemCount();
93 |
94 | if (mRecyclerView.getHeaderItemCount() > 0 && adapterPosition == 0) { // HeaderView。
95 | mRecyclerView.removeHeaderView(mHeaderView);
96 | Toast.makeText(DragGridActivity.this, "HeaderView被删除。", Toast.LENGTH_SHORT).show();
97 | } else { // 普通Item。
98 | mDataList.remove(position);
99 | mAdapter.notifyItemRemoved(position);
100 | Toast.makeText(DragGridActivity.this, "现在的第" + position + "条被删除。", Toast.LENGTH_SHORT).show();
101 | }
102 | }
103 | };
104 | }
105 | }
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/widget/DefaultLoadMoreView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.widget;
17 |
18 | import android.content.Context;
19 | import android.support.annotation.Nullable;
20 | import android.support.v4.content.ContextCompat;
21 | import android.text.TextUtils;
22 | import android.util.AttributeSet;
23 | import android.util.DisplayMetrics;
24 | import android.view.Gravity;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.widget.LinearLayout;
28 | import android.widget.TextView;
29 |
30 | import com.yanzhenjie.loading.LoadingView;
31 | import com.yanzhenjie.recyclerview.swipe.R;
32 | import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
33 |
34 | /**
35 | * Created by YanZhenjie on 2017/7/21.
36 | */
37 | public class DefaultLoadMoreView extends LinearLayout implements SwipeMenuRecyclerView.LoadMoreView, View.OnClickListener {
38 |
39 | private LoadingView mLoadingView;
40 | private TextView mTvMessage;
41 |
42 | private SwipeMenuRecyclerView.LoadMoreListener mLoadMoreListener;
43 |
44 | public DefaultLoadMoreView(Context context) {
45 | this(context, null);
46 | }
47 |
48 | public DefaultLoadMoreView(Context context, @Nullable AttributeSet attrs) {
49 | super(context, attrs);
50 | setLayoutParams(new ViewGroup.LayoutParams(-1, -2));
51 | setGravity(Gravity.CENTER);
52 | setVisibility(GONE);
53 |
54 | DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
55 |
56 | int minHeight = (int) (displayMetrics.density * 60 + 0.5);
57 | setMinimumHeight(minHeight);
58 |
59 | inflate(getContext(), R.layout.recycler_swipe_view_load_more, this);
60 | mLoadingView = (LoadingView) findViewById(R.id.loading_view);
61 | mTvMessage = (TextView) findViewById(R.id.tv_load_more_message);
62 |
63 | int color1 = ContextCompat.getColor(getContext(), R.color.recycler_swipe_color_loading_color1);
64 | int color2 = ContextCompat.getColor(getContext(), R.color.recycler_swipe_color_loading_color2);
65 | int color3 = ContextCompat.getColor(getContext(), R.color.recycler_swipe_color_loading_color3);
66 |
67 | mLoadingView.setCircleColors(color1, color2, color3);
68 |
69 | setOnClickListener(this);
70 | }
71 |
72 | @Override
73 | public void onLoading() {
74 | setVisibility(VISIBLE);
75 | mLoadingView.setVisibility(VISIBLE);
76 | mTvMessage.setVisibility(VISIBLE);
77 | mTvMessage.setText(R.string.recycler_swipe_load_more_message);
78 | }
79 |
80 | @Override
81 | public void onLoadFinish(boolean dataEmpty, boolean hasMore) {
82 | if (!hasMore) {
83 | setVisibility(VISIBLE);
84 |
85 | if (dataEmpty) {
86 | mLoadingView.setVisibility(GONE);
87 | mTvMessage.setVisibility(VISIBLE);
88 | mTvMessage.setText(R.string.recycler_swipe_data_empty);
89 | } else {
90 | mLoadingView.setVisibility(GONE);
91 | mTvMessage.setVisibility(VISIBLE);
92 | mTvMessage.setText(R.string.recycler_swipe_more_not);
93 | }
94 | } else {
95 | setVisibility(INVISIBLE);
96 | }
97 | }
98 |
99 | @Override
100 | public void onWaitToLoadMore(SwipeMenuRecyclerView.LoadMoreListener loadMoreListener) {
101 | this.mLoadMoreListener = loadMoreListener;
102 |
103 | setVisibility(VISIBLE);
104 | mLoadingView.setVisibility(GONE);
105 | mTvMessage.setVisibility(VISIBLE);
106 | mTvMessage.setText(R.string.recycler_swipe_click_load_more);
107 | }
108 |
109 | @Override
110 | public void onLoadError(int errorCode, String errorMessage) {
111 | setVisibility(VISIBLE);
112 | mLoadingView.setVisibility(GONE);
113 | mTvMessage.setVisibility(VISIBLE);
114 | mTvMessage.setText(TextUtils.isEmpty(errorMessage) ? getContext().getString(R.string.recycler_swipe_load_error) : errorMessage);
115 | }
116 |
117 | @Override
118 | public void onClick(View v) {
119 | if (mLoadMoreListener != null) mLoadMoreListener.onLoadMore();
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeMenuItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | import android.content.Context;
19 | import android.content.res.ColorStateList;
20 | import android.graphics.Typeface;
21 | import android.graphics.drawable.ColorDrawable;
22 | import android.graphics.drawable.Drawable;
23 | import android.support.annotation.ColorInt;
24 | import android.support.annotation.ColorRes;
25 | import android.support.annotation.DrawableRes;
26 | import android.support.annotation.Px;
27 | import android.support.annotation.StyleRes;
28 | import android.support.v4.content.ContextCompat;
29 |
30 | /**
31 | * Created by Yan Zhenjie on 2016/7/26.
32 | */
33 | public class SwipeMenuItem {
34 |
35 | private Context mContext;
36 | private Drawable background;
37 | private Drawable icon;
38 | private String title;
39 | private ColorStateList titleColor;
40 | private int titleSize;
41 | private Typeface textTypeface;
42 | private int textAppearance;
43 | private int width = -2;
44 | private int height = -2;
45 | private int weight = 0;
46 |
47 | public SwipeMenuItem(Context context) {
48 | mContext = context;
49 | }
50 |
51 | public SwipeMenuItem setBackground(@DrawableRes int resId) {
52 | return setBackground(ContextCompat.getDrawable(mContext, resId));
53 | }
54 |
55 | public SwipeMenuItem setBackground(Drawable background) {
56 | this.background = background;
57 | return this;
58 | }
59 |
60 | public SwipeMenuItem setBackgroundColorResource(@ColorRes int color) {
61 | return setBackgroundColor(ContextCompat.getColor(mContext, color));
62 | }
63 |
64 | public SwipeMenuItem setBackgroundColor(@ColorInt int color) {
65 | this.background = new ColorDrawable(color);
66 | return this;
67 | }
68 |
69 | public Drawable getBackground() {
70 | return background;
71 | }
72 |
73 | public SwipeMenuItem setImage(int resId) {
74 | return setImage(ContextCompat.getDrawable(mContext, resId));
75 | }
76 |
77 | public SwipeMenuItem setImage(Drawable icon) {
78 | this.icon = icon;
79 | return this;
80 | }
81 |
82 | public Drawable getImage() {
83 | return icon;
84 | }
85 |
86 | public SwipeMenuItem setText(int resId) {
87 | return setText(mContext.getString(resId));
88 | }
89 |
90 | public SwipeMenuItem setText(String title) {
91 | this.title = title;
92 | return this;
93 | }
94 |
95 | public String getText() {
96 | return title;
97 | }
98 |
99 | public SwipeMenuItem setTextColorResource(@ColorRes int titleColor) {
100 | return setTextColor(ContextCompat.getColor(mContext, titleColor));
101 | }
102 |
103 | public SwipeMenuItem setTextColor(@ColorInt int titleColor) {
104 | this.titleColor = ColorStateList.valueOf(titleColor);
105 | return this;
106 | }
107 |
108 | public ColorStateList getTitleColor() {
109 | return titleColor;
110 | }
111 |
112 | public SwipeMenuItem setTextSize(@Px int titleSize) {
113 | this.titleSize = titleSize;
114 | return this;
115 | }
116 |
117 | public int getTextSize() {
118 | return titleSize;
119 | }
120 |
121 | public SwipeMenuItem setTextAppearance(@StyleRes int textAppearance) {
122 | this.textAppearance = textAppearance;
123 | return this;
124 | }
125 |
126 | public int getTextAppearance() {
127 | return textAppearance;
128 | }
129 |
130 | public SwipeMenuItem setTextTypeface(Typeface textTypeface) {
131 | this.textTypeface = textTypeface;
132 | return this;
133 | }
134 |
135 | public Typeface getTextTypeface() {
136 | return textTypeface;
137 | }
138 |
139 | public SwipeMenuItem setWidth(int width) {
140 | this.width = width;
141 | return this;
142 | }
143 |
144 | public int getWidth() {
145 | return width;
146 | }
147 |
148 | public SwipeMenuItem setHeight(int height) {
149 | this.height = height;
150 | return this;
151 | }
152 |
153 | public int getHeight() {
154 | return height;
155 | }
156 |
157 | public SwipeMenuItem setWeight(int weight) {
158 | this.weight = weight;
159 | return this;
160 | }
161 |
162 | public int getWeight() {
163 | return weight;
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/recyclerview-swipe/src/main/java/com/yanzhenjie/recyclerview/swipe/SwipeMenuView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe;
17 |
18 | import android.content.Context;
19 | import android.content.res.ColorStateList;
20 | import android.graphics.Typeface;
21 | import android.support.v4.view.ViewCompat;
22 | import android.support.v4.widget.TextViewCompat;
23 | import android.support.v7.widget.RecyclerView;
24 | import android.text.TextUtils;
25 | import android.util.AttributeSet;
26 | import android.view.Gravity;
27 | import android.view.View;
28 | import android.widget.ImageView;
29 | import android.widget.LinearLayout;
30 | import android.widget.TextView;
31 |
32 | import java.util.List;
33 |
34 | /**
35 | * Created by Yan Zhenjie on 2016/7/26.
36 | */
37 | public class SwipeMenuView extends LinearLayout implements View.OnClickListener {
38 |
39 | private RecyclerView.ViewHolder mAdapterVIewHolder;
40 | private SwipeSwitch mSwipeSwitch;
41 | private SwipeMenuItemClickListener mItemClickListener;
42 | @SwipeMenuRecyclerView.DirectionMode
43 | private int mDirection;
44 |
45 | public SwipeMenuView(Context context) {
46 | this(context, null);
47 | }
48 |
49 | public SwipeMenuView(Context context, AttributeSet attrs) {
50 | this(context, attrs, 0);
51 | }
52 |
53 | public SwipeMenuView(Context context, AttributeSet attrs, int defStyleAttr) {
54 | super(context, attrs, defStyleAttr);
55 | }
56 |
57 | public void createMenu(SwipeMenu swipeMenu, SwipeSwitch swipeSwitch,
58 | SwipeMenuItemClickListener swipeMenuItemClickListener,
59 | @SwipeMenuRecyclerView.DirectionMode int direction) {
60 | removeAllViews();
61 |
62 | this.mSwipeSwitch = swipeSwitch;
63 | this.mItemClickListener = swipeMenuItemClickListener;
64 | this.mDirection = direction;
65 |
66 | List items = swipeMenu.getMenuItems();
67 | for (int i = 0; i < items.size(); i++) {
68 | SwipeMenuItem item = items.get(i);
69 |
70 | LayoutParams params = new LayoutParams(item.getWidth(), item.getHeight());
71 | params.weight = item.getWeight();
72 | LinearLayout parent = new LinearLayout(getContext());
73 | parent.setId(i);
74 | parent.setGravity(Gravity.CENTER);
75 | parent.setOrientation(VERTICAL);
76 | parent.setLayoutParams(params);
77 | ViewCompat.setBackground(parent, item.getBackground());
78 | parent.setOnClickListener(this);
79 | addView(parent);
80 |
81 | SwipeMenuBridge menuBridge = new SwipeMenuBridge(mDirection, i, mSwipeSwitch, parent);
82 | parent.setTag(menuBridge);
83 |
84 | if (item.getImage() != null) {
85 | ImageView iv = createIcon(item);
86 | menuBridge.mImageView = iv;
87 | parent.addView(iv);
88 | }
89 |
90 | if (!TextUtils.isEmpty(item.getText())) {
91 | TextView tv = createTitle(item);
92 | menuBridge.mTextView = tv;
93 | parent.addView(tv);
94 | }
95 | }
96 | }
97 |
98 | public void bindViewHolder(RecyclerView.ViewHolder adapterVIewHolder) {
99 | this.mAdapterVIewHolder = adapterVIewHolder;
100 | }
101 |
102 | private ImageView createIcon(SwipeMenuItem item) {
103 | ImageView imageView = new ImageView(getContext());
104 | imageView.setImageDrawable(item.getImage());
105 | return imageView;
106 | }
107 |
108 | private TextView createTitle(SwipeMenuItem item) {
109 | TextView textView = new TextView(getContext());
110 | textView.setText(item.getText());
111 | textView.setGravity(Gravity.CENTER);
112 | int textSize = item.getTextSize();
113 | if (textSize > 0)
114 | textView.setTextSize(textSize);
115 | ColorStateList textColor = item.getTitleColor();
116 | if (textColor != null)
117 | textView.setTextColor(textColor);
118 | int textAppearance = item.getTextAppearance();
119 | if (textAppearance != 0)
120 | TextViewCompat.setTextAppearance(textView, textAppearance);
121 | Typeface typeface = item.getTextTypeface();
122 | if (typeface != null)
123 | textView.setTypeface(typeface);
124 | return textView;
125 | }
126 |
127 | @Override
128 | public void onClick(View v) {
129 | if (mItemClickListener != null && mSwipeSwitch.isMenuOpen()) {
130 | SwipeMenuBridge menuBridge = (SwipeMenuBridge) v.getTag();
131 | menuBridge.mAdapterPosition = mAdapterVIewHolder.getAdapterPosition();
132 | mItemClickListener.onItemClick(menuBridge);
133 | }
134 | }
135 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yanzhenjie/recyclerview/swipe/sample/activity/nested/ViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.recyclerview.swipe.sample.activity.nested;
17 |
18 | import android.os.Bundle;
19 | import android.support.annotation.Nullable;
20 | import android.support.v4.app.Fragment;
21 | import android.support.v4.app.FragmentManager;
22 | import android.support.v4.app.FragmentPagerAdapter;
23 | import android.support.v4.content.ContextCompat;
24 | import android.support.v4.view.ViewPager;
25 | import android.support.v7.app.ActionBar;
26 | import android.support.v7.app.AppCompatActivity;
27 | import android.support.v7.widget.Toolbar;
28 | import android.view.MenuItem;
29 | import android.view.View;
30 |
31 | import com.yanzhenjie.recyclerview.swipe.sample.R;
32 | import com.yanzhenjie.recyclerview.swipe.sample.fragment.MenuFragment;
33 |
34 | import java.util.ArrayList;
35 | import java.util.List;
36 |
37 | /**
38 | *