├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── compiler.xml
├── encodings.xml
├── jarRepositories.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── DragBoardView
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── time
│ │ └── cat
│ │ └── dragboardview
│ │ ├── DragBoardView.java
│ │ ├── DragLayout.java
│ │ ├── PagerRecyclerView.java
│ │ ├── adapter
│ │ ├── HorizontalAdapter.java
│ │ ├── RecyclerViewPagerAdapter.java
│ │ └── VerticalAdapter.java
│ │ ├── callback
│ │ ├── DragHorizontalAdapter.java
│ │ ├── DragHorizontalViewHolder.java
│ │ ├── DragVerticalAdapter.java
│ │ ├── onDragColumnListener.java
│ │ └── onDragItemListener.java
│ │ ├── helper
│ │ └── DragHelper.java
│ │ ├── model
│ │ ├── DragColumn.java
│ │ └── DragItem.java
│ │ └── utils
│ │ └── RecyclerviewUtils.java
│ └── res
│ ├── layout
│ └── view_drag_board.xml
│ └── values
│ └── attrs_pagerrecyclerview.xml
├── LICENSE
├── README.md
├── README_zh.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── time
│ │ └── cat
│ │ └── demo
│ │ ├── MainActivity.java
│ │ ├── adapter
│ │ ├── ColumnAdapter.java
│ │ └── ItemAdapter.java
│ │ └── data
│ │ ├── Entry.java
│ │ └── Item.java
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ ├── ic_action_add.xml
│ ├── ic_launcher_background.xml
│ ├── ic_more_grey_24dp.xml
│ └── shape_rectangle_with_radius.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── recyclerview_footer_addlist.xml
│ ├── recyclerview_item_entry.xml
│ └── recyclerview_item_item.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── art
├── device-2018-04-04-085351.gif
├── device-2018-04-04-085942.png
├── device-2018-04-04-090017.png
├── device-2018-04-04-090030.png
├── device-2018-04-04-090047.png
└── device-2018-04-04-090115.png
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
57 | .idea/
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
40 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | xmlns:android
103 | Namespace:
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | xmlns:.*
113 | Namespace:
114 |
115 |
116 | BY_NAME
117 |
118 |
119 |
120 |
121 |
122 |
123 | .*:id
124 | http://schemas.android.com/apk/res/android
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 | .*:name
134 | http://schemas.android.com/apk/res/android
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 | name
144 | ^$
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | style
154 | ^$
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 | .*
164 | ^$
165 |
166 |
167 | BY_NAME
168 |
169 |
170 |
171 |
172 |
173 |
174 | .*:layout_width
175 | http://schemas.android.com/apk/res/android
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 | .*:layout_height
185 | http://schemas.android.com/apk/res/android
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 | .*:layout_.*
195 | http://schemas.android.com/apk/res/android
196 |
197 |
198 | BY_NAME
199 |
200 |
201 |
202 |
203 |
204 |
205 | .*:width
206 | http://schemas.android.com/apk/res/android
207 |
208 |
209 | BY_NAME
210 |
211 |
212 |
213 |
214 |
215 |
216 | .*:height
217 | http://schemas.android.com/apk/res/android
218 |
219 |
220 | BY_NAME
221 |
222 |
223 |
224 |
225 |
226 |
227 | .*
228 | http://schemas.android.com/apk/res/android
229 |
230 |
231 | BY_NAME
232 |
233 |
234 |
235 |
236 |
237 |
238 | .*
239 | .*
240 |
241 |
242 | BY_NAME
243 |
244 |
245 |
246 |
247 |
248 |
249 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/DragBoardView/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/DragBoardView/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion '28.0.3'
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation 'androidx.appcompat:appcompat:1.0.0'
27 | implementation 'com.google.android.material:material:1.0.0'
28 | implementation 'androidx.cardview:cardview:1.0.0'
29 | }
30 |
--------------------------------------------------------------------------------
/DragBoardView/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\AndroidSdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/DragBoardView.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.NonNull;
5 | import androidx.annotation.Nullable;
6 | import androidx.recyclerview.widget.LinearLayoutManager;
7 | import androidx.recyclerview.widget.RecyclerView;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import com.time.cat.dragboardview.adapter.HorizontalAdapter;
12 | import com.time.cat.dragboardview.helper.DragHelper;
13 |
14 | /**
15 | * @author dlink
16 | * @email linxy59@mail2.sysu.edu.cn
17 | * @date 2018/11/30
18 | * @discription null
19 | * @usage null
20 | */
21 | public class DragBoardView extends DragLayout {
22 | private PagerRecyclerView mRecyclerView;
23 | private HorizontalAdapter mAdapter;
24 | private DragLayout mLayoutMain;
25 | private DragHelper mDragHelper;
26 |
27 | public DragBoardView(Context context) {
28 | super(context);
29 | init(context);
30 | }
31 |
32 | public DragBoardView(Context context, @Nullable AttributeSet attrs) {
33 | super(context, attrs);
34 | init(context, attrs);
35 | }
36 |
37 | public DragBoardView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
38 | super(context, attrs, defStyleAttr);
39 | init(context, attrs);
40 | }
41 |
42 | private void init(Context context, AttributeSet attrs) {
43 | init(context);
44 | }
45 |
46 | private void init(Context context) {
47 | inflate(context, R.layout.view_drag_board, this);
48 | mLayoutMain = (DragLayout) findViewById(R.id.layout_main);
49 | mRecyclerView = (PagerRecyclerView) findViewById(R.id.rv_lists);
50 |
51 | // 配置RecycleView
52 | LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
53 | mRecyclerView.setLayoutManager(layoutManager);
54 | mRecyclerView.setHasFixedSize(true);
55 | mRecyclerView.setFlingFactor(0.1f);
56 | mRecyclerView.addOnPageChangedListener(mOnPagerChangedListener);
57 | mRecyclerView.addOnLayoutChangeListener(mOnLayoutChangedListener);
58 | mRecyclerView.addOnScrollListener(mOnScrollListener);
59 |
60 | // 通过 DragHelper 把 RecycleView 绑定到 DragLayout
61 | mDragHelper = new DragHelper(context);
62 | mDragHelper.bindHorizontalRecyclerView(mRecyclerView);
63 | mLayoutMain.setDragHelper(mDragHelper);
64 | }
65 |
66 | private RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
67 | @Override
68 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
69 | super.onScrollStateChanged(recyclerView, newState);
70 | }
71 |
72 | @Override
73 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
74 | int childCount = mRecyclerView.getChildCount();
75 | int width = mRecyclerView.getChildAt(0).getWidth();
76 | int padding = (mRecyclerView.getWidth() - width) / 2;
77 |
78 | for (int j = 0; j < childCount; j++) {
79 | View v = recyclerView.getChildAt(j);
80 | //往左 从 padding 到 -(v.getWidth()-padding) 的过程中,由大到小
81 | float rate = 0;
82 | if (v.getLeft() <= padding) {
83 | if (v.getLeft() >= padding - v.getWidth()) {
84 | rate = (padding - v.getLeft()) * 1f / v.getWidth();
85 | } else {
86 | rate = 1;
87 | }
88 | v.setScaleX(1 - rate * 0.1f);
89 |
90 | } else {
91 | //往右 从 padding 到 recyclerView.getWidth()-padding 的过程中,由大到小
92 | if (v.getLeft() <= recyclerView.getWidth() - padding) {
93 | rate = (recyclerView.getWidth() - padding - v.getLeft()) * 1f / v.getWidth();
94 | }
95 | v.setScaleX(0.9f + rate * 0.1f);
96 | }
97 | }
98 | }
99 | };
100 | private View.OnLayoutChangeListener mOnLayoutChangedListener = new View.OnLayoutChangeListener() {
101 | @Override
102 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
103 | }
104 | };
105 | private PagerRecyclerView.OnPageChangedListener mOnPagerChangedListener = new PagerRecyclerView.OnPageChangedListener() {
106 | @Override
107 | public void OnPageChanged(int oldPosition, int newPosition) {
108 |
109 | }
110 | };
111 |
112 | public void setHorizontalAdapter(@NonNull HorizontalAdapter horizontalAdapter) {
113 | this.mAdapter = horizontalAdapter;
114 | mAdapter.setDragHelper(mDragHelper);
115 | mRecyclerView.setAdapter(mAdapter);
116 | }
117 |
118 | public DragHelper getDragHelper() {
119 | return mDragHelper;
120 | }
121 |
122 | public PagerRecyclerView getRecyclerView() {
123 | return mRecyclerView;
124 | }
125 |
126 | public HorizontalAdapter getAdapter() {
127 | return mAdapter;
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/DragLayout.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.MotionEvent;
6 | import android.widget.RelativeLayout;
7 |
8 | import com.time.cat.dragboardview.helper.DragHelper;
9 |
10 | /**
11 | * @author dlink
12 | * @email linxy59@mail2.sysu.edu.cn
13 | * @date 2018/4/3
14 | * @discription 配合 {@link DragHelper} 实现拖拽的根布局
15 | * @usage null
16 | */
17 | public class DragLayout extends RelativeLayout {
18 |
19 | private DragHelper mDragHelper;
20 |
21 | public DragLayout(Context context) {
22 | super(context);
23 | }
24 |
25 | public DragLayout(Context context, AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | public void setDragHelper(DragHelper dragHelper) {
34 | mDragHelper = dragHelper;
35 | }
36 |
37 |
38 | @Override
39 | public boolean onInterceptTouchEvent(MotionEvent ev) {
40 | if (mDragHelper != null) {
41 | if (mDragHelper.isDraggingItem() || mDragHelper.isDraggingColumn()) {return true;}
42 | }
43 | return super.onInterceptTouchEvent(ev);
44 | }
45 |
46 | @Override
47 | public boolean onTouchEvent(MotionEvent event) {
48 | switch (event.getAction()) {
49 | case MotionEvent.ACTION_MOVE:
50 | if (mDragHelper != null) {
51 | mDragHelper.updateDraggingPosition(event.getRawX(), event.getRawY());
52 | }
53 | break;
54 | case MotionEvent.ACTION_UP:
55 | case MotionEvent.ACTION_CANCEL:
56 | if (mDragHelper != null) {
57 | if (mDragHelper.isDraggingItem()) {
58 | mDragHelper.dropItem();
59 | } else if (mDragHelper.isDraggingColumn()) {
60 | mDragHelper.dropCol();
61 | }
62 | }
63 | break;
64 | default:
65 | break;
66 | }
67 | return super.onTouchEvent(event);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/PagerRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.PointF;
6 | import android.os.Build;
7 | import android.os.Parcelable;
8 | import androidx.annotation.NonNull;
9 | import androidx.recyclerview.widget.LinearLayoutManager;
10 | import androidx.recyclerview.widget.LinearSmoothScroller;
11 | import androidx.recyclerview.widget.RecyclerView;
12 | import android.util.AttributeSet;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.ViewTreeObserver;
16 |
17 | import com.time.cat.dragboardview.adapter.RecyclerViewPagerAdapter;
18 | import com.time.cat.dragboardview.utils.RecyclerviewUtils;
19 |
20 | import java.lang.reflect.Field;
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * @author dlink
26 | * @email linxy59@mail2.sysu.edu.cn
27 | * @date 2018/4/3
28 | * @discription 实现看板的RecycleView
29 | * @usage null
30 | */
31 | public class PagerRecyclerView extends RecyclerView {
32 |
33 | private RecyclerViewPagerAdapter> mViewPagerAdapter;
34 | private float mTriggerOffset = 0.25f;
35 | private float mFlingFactor = 0.15f;
36 | private float mTouchSpan;
37 | private List mOnPageChangedListeners;
38 | private int mSmoothScrollTargetPosition = -1;
39 | private int mPositionBeforeScroll = -1;
40 |
41 | private boolean mSinglePageFling;
42 |
43 | boolean mNeedAdjust;
44 | int mFirstLeftWhenDragging;
45 | int mFirstTopWhenDragging;
46 | View mCurView;
47 | int mMaxLeftWhenDragging = Integer.MIN_VALUE;
48 | int mMinLeftWhenDragging = Integer.MAX_VALUE;
49 | int mMaxTopWhenDragging = Integer.MIN_VALUE;
50 | int mMinTopWhenDragging = Integer.MAX_VALUE;
51 | private int mPositionOnTouchDown = -1;
52 | private boolean mHasCalledOnPageChanged = true;
53 | private boolean reverseLayout = false;
54 |
55 | public PagerRecyclerView(Context context) {
56 | this(context, null);
57 | }
58 |
59 | public PagerRecyclerView(Context context, AttributeSet attrs) {
60 | this(context, attrs, 0);
61 | }
62 |
63 | public PagerRecyclerView(Context context, AttributeSet attrs, int defStyle) {
64 | super(context, attrs, defStyle);
65 | initAttrs(context, attrs, defStyle);
66 | setNestedScrollingEnabled(false);
67 | }
68 |
69 | private void initAttrs(Context context, AttributeSet attrs, int defStyle) {
70 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerViewPager, defStyle, 0);
71 | mFlingFactor = a.getFloat(R.styleable.RecyclerViewPager_flingFactor, 0.15f);
72 | mTriggerOffset = a.getFloat(R.styleable.RecyclerViewPager_triggerOffset, 0.25f);
73 | mSinglePageFling = a.getBoolean(R.styleable.RecyclerViewPager_singlePageFling, mSinglePageFling);
74 | a.recycle();
75 | }
76 |
77 | public void setFlingFactor(float flingFactor) {
78 | mFlingFactor = flingFactor;
79 | }
80 |
81 | public float getFlingFactor() {
82 | return mFlingFactor;
83 | }
84 |
85 | public void setTriggerOffset(float triggerOffset) {
86 | mTriggerOffset = triggerOffset;
87 | }
88 |
89 | public float getTriggerOffset() {
90 | return mTriggerOffset;
91 | }
92 |
93 | public void setSinglePageFling(boolean singlePageFling) {
94 | mSinglePageFling = singlePageFling;
95 | }
96 |
97 | public boolean isSinglePageFling() {
98 | return mSinglePageFling;
99 | }
100 |
101 | @Override
102 | protected void onRestoreInstanceState(Parcelable state) {
103 | try {
104 | Field fLayoutState = state.getClass().getDeclaredField("mLayoutState");
105 | fLayoutState.setAccessible(true);
106 | Object layoutState = fLayoutState.get(state);
107 | Field fAnchorOffset = layoutState.getClass().getDeclaredField("mAnchorOffset");
108 | Field fAnchorPosition = layoutState.getClass().getDeclaredField("mAnchorPosition");
109 | fAnchorPosition.setAccessible(true);
110 | fAnchorOffset.setAccessible(true);
111 | if (fAnchorOffset.getInt(layoutState) > 0) {
112 | fAnchorPosition.set(layoutState, fAnchorPosition.getInt(layoutState) - 1);
113 | } else if (fAnchorOffset.getInt(layoutState) < 0) {
114 | fAnchorPosition.set(layoutState, fAnchorPosition.getInt(layoutState) + 1);
115 | }
116 | fAnchorOffset.setInt(layoutState, 0);
117 | } catch (Throwable e) {
118 | e.printStackTrace();
119 | }
120 | super.onRestoreInstanceState(state);
121 | }
122 |
123 | @Override
124 | public void setAdapter(Adapter adapter) {
125 | mViewPagerAdapter = ensureRecyclerViewPagerAdapter(adapter);
126 | super.setAdapter(mViewPagerAdapter);
127 | }
128 |
129 | @Override
130 | public void swapAdapter(Adapter adapter, boolean removeAndRecycleExistingViews) {
131 | mViewPagerAdapter = ensureRecyclerViewPagerAdapter(adapter);
132 | super.swapAdapter(adapter, removeAndRecycleExistingViews);
133 | }
134 |
135 | @Override
136 | public Adapter getAdapter() {
137 | if (mViewPagerAdapter != null) {return mViewPagerAdapter.mAdapter;}
138 | return null;
139 | }
140 |
141 |
142 | @Override
143 | public void setLayoutManager(LayoutManager layout) {
144 | super.setLayoutManager(layout);
145 | if (layout instanceof LinearLayoutManager) {
146 | reverseLayout = ((LinearLayoutManager) layout).getReverseLayout();
147 | }
148 | }
149 |
150 | @Override
151 | public boolean fling(int velocityX, int velocityY) {
152 | boolean fling = super.fling((int) (velocityX * mFlingFactor), (int) (velocityY * mFlingFactor));
153 | if (fling) {
154 | if (getLayoutManager().canScrollHorizontally()) {
155 | adjustPositionX(velocityX);
156 | } else {
157 | adjustPositionY(velocityY);
158 | }
159 | }
160 | return fling;
161 | }
162 |
163 | @Override
164 | public void smoothScrollToPosition(int position) {
165 | mSmoothScrollTargetPosition = position;
166 | if (getLayoutManager() != null && getLayoutManager() instanceof LinearLayoutManager) {
167 | LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(getContext()) {
168 | @Override
169 | public PointF computeScrollVectorForPosition(int targetPosition) {
170 | if (getLayoutManager() == null) {return null;}
171 | return ((LinearLayoutManager) getLayoutManager()).computeScrollVectorForPosition(targetPosition);
172 | }
173 |
174 | @Override
175 | protected void onTargetFound(View targetView, State state, Action action) {
176 | if (getLayoutManager() == null) {return;}
177 | int dx = calculateDxToMakeVisible(targetView, getHorizontalSnapPreference());
178 | int dy = calculateDyToMakeVisible(targetView, getVerticalSnapPreference());
179 | if (dx > 0) {
180 | dx = dx - getLayoutManager().getLeftDecorationWidth(targetView);
181 | } else {
182 | dx = dx + getLayoutManager().getRightDecorationWidth(targetView);
183 | }
184 | if (dy > 0) {
185 | dy = dy - getLayoutManager()
186 | .getTopDecorationHeight(targetView);
187 | } else {
188 | dy = dy + getLayoutManager()
189 | .getBottomDecorationHeight(targetView);
190 | }
191 | final int distance = (int) Math.sqrt(dx * dx + dy * dy);
192 | final int time = calculateTimeForDeceleration(distance);
193 | if (time > 0) {
194 | action.update(-dx, -dy, time, mDecelerateInterpolator);
195 | }
196 | }
197 | };
198 | linearSmoothScroller.setTargetPosition(position);
199 | if (position == RecyclerView.NO_POSITION) {
200 | return;
201 | }
202 | getLayoutManager().startSmoothScroll(linearSmoothScroller);
203 |
204 | } else {
205 | super.smoothScrollToPosition(position);
206 | }
207 | }
208 |
209 | @Override
210 | public void scrollToPosition(int position) {
211 | mPositionBeforeScroll = getCurrentPosition();
212 | mSmoothScrollTargetPosition = position;
213 | super.scrollToPosition(position);
214 |
215 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
216 | @Override
217 | public void onGlobalLayout() {
218 | if (Build.VERSION.SDK_INT < 16) {
219 | getViewTreeObserver().removeGlobalOnLayoutListener(this);
220 | } else {
221 | getViewTreeObserver().removeOnGlobalLayoutListener(this);
222 | }
223 |
224 | if (mSmoothScrollTargetPosition >= 0 && mSmoothScrollTargetPosition < mViewPagerAdapter.getItemCount()) {
225 | if (mOnPageChangedListeners != null) {
226 | for (OnPageChangedListener onPageChangedListener : mOnPageChangedListeners) {
227 | if (onPageChangedListener != null) {
228 | onPageChangedListener.OnPageChanged(mPositionBeforeScroll, getCurrentPosition());
229 | }
230 | }
231 | }
232 | }
233 | }
234 | });
235 | }
236 |
237 | @Override
238 | public boolean dispatchTouchEvent(MotionEvent ev) {
239 | if (ev.getAction() == MotionEvent.ACTION_DOWN) {
240 | mPositionOnTouchDown = getLayoutManager().canScrollHorizontally() ?
241 | RecyclerviewUtils.getCenterXChildPosition(this)
242 | : RecyclerviewUtils.getCenterYChildPosition(this);
243 | }
244 | return super.dispatchTouchEvent(ev);
245 | }
246 |
247 | @Override
248 | public boolean onTouchEvent(MotionEvent e) {
249 | // recording the max/min value in touch track
250 | if (e.getAction() == MotionEvent.ACTION_MOVE) {
251 | if (mCurView != null) {
252 | mMaxLeftWhenDragging = Math.max(mCurView.getLeft(), mMaxLeftWhenDragging);
253 | mMaxTopWhenDragging = Math.max(mCurView.getTop(), mMaxTopWhenDragging);
254 | mMinLeftWhenDragging = Math.min(mCurView.getLeft(), mMinLeftWhenDragging);
255 | mMinTopWhenDragging = Math.min(mCurView.getTop(), mMinTopWhenDragging);
256 | }
257 | }
258 | return super.onTouchEvent(e);
259 | }
260 |
261 | @Override
262 | public void onScrollStateChanged(int state) {
263 | super.onScrollStateChanged(state);
264 | if (state == SCROLL_STATE_DRAGGING) {
265 | mNeedAdjust = true;
266 | mCurView = getLayoutManager().canScrollHorizontally() ? RecyclerviewUtils.getCenterXChild(this) :
267 | RecyclerviewUtils.getCenterYChild(this);
268 | if (mCurView != null) {
269 | if (mHasCalledOnPageChanged) {
270 | // While rvp is scrolling, mPositionBeforeScroll will be previous value.
271 | mPositionBeforeScroll = getChildLayoutPosition(mCurView);
272 | mHasCalledOnPageChanged = false;
273 | }
274 | mFirstLeftWhenDragging = mCurView.getLeft();
275 | mFirstTopWhenDragging = mCurView.getTop();
276 | } else {
277 | mPositionBeforeScroll = -1;
278 | }
279 | mTouchSpan = 0;
280 | } else if (state == SCROLL_STATE_SETTLING) {
281 | mNeedAdjust = false;
282 | if (mCurView != null) {
283 | if (getLayoutManager().canScrollHorizontally()) {
284 | mTouchSpan = mCurView.getLeft() - mFirstLeftWhenDragging;
285 | } else {
286 | mTouchSpan = mCurView.getTop() - mFirstTopWhenDragging;
287 | }
288 | } else {
289 | mTouchSpan = 0;
290 | }
291 | mCurView = null;
292 | } else if (state == SCROLL_STATE_IDLE) {
293 | if (mNeedAdjust) {
294 | int targetPosition = getLayoutManager().canScrollHorizontally() ? RecyclerviewUtils.getCenterXChildPosition(this) :
295 | RecyclerviewUtils.getCenterYChildPosition(this);
296 | if (mCurView != null) {
297 | targetPosition = getChildAdapterPosition(mCurView);
298 | if (getLayoutManager().canScrollHorizontally()) {
299 | int spanX = mCurView.getLeft() - mFirstLeftWhenDragging;
300 | // if user is tending to cancel paging action, don't perform position changing
301 | if (spanX > mCurView.getWidth() * mTriggerOffset && mCurView.getLeft() >= mMaxLeftWhenDragging) {
302 | if (!reverseLayout) {targetPosition--;} else {targetPosition++;}
303 | } else if (spanX < mCurView.getWidth() * -mTriggerOffset && mCurView.getLeft() <= mMinLeftWhenDragging) {
304 | if (!reverseLayout) {targetPosition++;} else {targetPosition--;}
305 | }
306 | } else {
307 | int spanY = mCurView.getTop() - mFirstTopWhenDragging;
308 | if (spanY > mCurView.getHeight() * mTriggerOffset && mCurView.getTop() >= mMaxTopWhenDragging) {
309 | if (!reverseLayout) {targetPosition--;} else {targetPosition++;}
310 | } else if (spanY < mCurView.getHeight() * -mTriggerOffset && mCurView.getTop() <= mMinTopWhenDragging) {
311 | if (!reverseLayout) {targetPosition++;} else {targetPosition--;}
312 | }
313 | }
314 | }
315 | smoothScrollToPosition(safeTargetPosition(targetPosition, mViewPagerAdapter.getItemCount()));
316 | mCurView = null;
317 | } else if (mSmoothScrollTargetPosition != mPositionBeforeScroll) {
318 | if (mOnPageChangedListeners != null) {
319 | for (OnPageChangedListener onPageChangedListener : mOnPageChangedListeners) {
320 | if (onPageChangedListener != null) {
321 | onPageChangedListener.OnPageChanged(mPositionBeforeScroll, mSmoothScrollTargetPosition);
322 | }
323 | }
324 | }
325 | mHasCalledOnPageChanged = true;
326 | mPositionBeforeScroll = mSmoothScrollTargetPosition;
327 | }
328 | // reset
329 | mMaxLeftWhenDragging = Integer.MIN_VALUE;
330 | mMinLeftWhenDragging = Integer.MAX_VALUE;
331 | mMaxTopWhenDragging = Integer.MIN_VALUE;
332 | mMinTopWhenDragging = Integer.MAX_VALUE;
333 | }
334 | }
335 |
336 |
337 | @NonNull
338 | protected RecyclerViewPagerAdapter ensureRecyclerViewPagerAdapter(Adapter adapter) {
339 | return (adapter instanceof RecyclerViewPagerAdapter)
340 | ? (RecyclerViewPagerAdapter) adapter
341 | : new RecyclerViewPagerAdapter(this, adapter);
342 | }
343 |
344 |
345 | public void addOnPageChangedListener(OnPageChangedListener listener) {
346 | if (mOnPageChangedListeners == null) {
347 | mOnPageChangedListeners = new ArrayList<>();
348 | }
349 | mOnPageChangedListeners.add(listener);
350 | }
351 |
352 | public void removeOnPageChangedListener(OnPageChangedListener listener) {
353 | if (mOnPageChangedListeners != null) {
354 | mOnPageChangedListeners.remove(listener);
355 | }
356 | }
357 |
358 | public void clearOnPageChangedListeners() {
359 | if (mOnPageChangedListeners != null) {
360 | mOnPageChangedListeners.clear();
361 | }
362 | }
363 |
364 | public void nextPage() {
365 | smoothScrollToPosition(getCurrentPosition() + 1);
366 | }
367 |
368 | public void prePage() {
369 | smoothScrollToPosition(getCurrentPosition() - 1);
370 | }
371 |
372 | public void backToCurrentPage() {
373 | smoothScrollToPosition(getCurrentPosition());
374 | }
375 |
376 | /**
377 | * get item position in center of viewpager
378 | */
379 | public int getCurrentPosition() {
380 | int curPosition = -1;
381 | if (getLayoutManager().canScrollHorizontally()) {
382 | curPosition = RecyclerviewUtils.getCenterXChildPosition(this);
383 | } else {
384 | curPosition = RecyclerviewUtils.getCenterYChildPosition(this);
385 | }
386 | if (curPosition < 0) {
387 | curPosition = mSmoothScrollTargetPosition;
388 | }
389 | return curPosition;
390 | }
391 |
392 |
393 | /**
394 | * adjust position before Touch event complete and fling action start.
395 | */
396 | private void adjustPositionX(int velocityX) {
397 | if (reverseLayout) { velocityX *= -1; }
398 |
399 | int childCount = getChildCount();
400 | if (childCount > 0) {
401 | int curPosition = RecyclerviewUtils.getCenterXChildPosition(this);
402 | int childWidth = getWidth() - getPaddingLeft() - getPaddingRight();
403 | int flingCount = getFlingCount(velocityX, childWidth);
404 | int targetPosition = curPosition + flingCount;
405 | if (mSinglePageFling) {
406 | flingCount = Math.max(-1, Math.min(1, flingCount));
407 | targetPosition = flingCount == 0 ? curPosition : mPositionOnTouchDown + flingCount;
408 | }
409 | targetPosition = Math.max(targetPosition, 0);
410 | targetPosition = Math.min(targetPosition, mViewPagerAdapter.getItemCount() - 1);
411 | if (targetPosition == curPosition
412 | && ((mSinglePageFling
413 | && mPositionOnTouchDown == curPosition)
414 | || !mSinglePageFling)) {
415 | View centerXChild = RecyclerviewUtils.getCenterXChild(this);
416 | if (centerXChild != null) {
417 | if (mTouchSpan > centerXChild.getWidth() * mTriggerOffset * mTriggerOffset && targetPosition != 0) {
418 | if (!reverseLayout) { targetPosition--; } else { targetPosition++; }
419 | } else if (mTouchSpan < centerXChild.getWidth() * -mTriggerOffset && targetPosition != mViewPagerAdapter.getItemCount() - 1) {
420 | if (!reverseLayout) { targetPosition++; } else { targetPosition--; }
421 | }
422 | }
423 | }
424 | smoothScrollToPosition(safeTargetPosition(targetPosition, mViewPagerAdapter.getItemCount()));
425 | }
426 | }
427 |
428 | /***
429 | * adjust position before Touch event complete and fling action start.
430 | */
431 | protected void adjustPositionY(int velocityY) {
432 | if (reverseLayout) { velocityY *= -1; }
433 |
434 | int childCount = getChildCount();
435 | if (childCount > 0) {
436 | int curPosition = RecyclerviewUtils.getCenterYChildPosition(this);
437 | int childHeight = getHeight() - getPaddingTop() - getPaddingBottom();
438 | int flingCount = getFlingCount(velocityY, childHeight);
439 | int targetPosition = curPosition + flingCount;
440 | if (mSinglePageFling) {
441 | flingCount = Math.max(-1, Math.min(1, flingCount));
442 | targetPosition = flingCount == 0 ? curPosition : mPositionOnTouchDown + flingCount;
443 | }
444 |
445 | targetPosition = Math.max(targetPosition, 0);
446 | targetPosition = Math.min(targetPosition, mViewPagerAdapter.getItemCount() - 1);
447 | if (targetPosition == curPosition
448 | && ((mSinglePageFling
449 | && mPositionOnTouchDown == curPosition)
450 | || !mSinglePageFling)) {
451 | View centerYChild = RecyclerviewUtils.getCenterYChild(this);
452 | if (centerYChild != null) {
453 | if (mTouchSpan > centerYChild.getHeight() * mTriggerOffset && targetPosition != 0) {
454 | if (!reverseLayout) { targetPosition--; } else { targetPosition++; }
455 | } else if (mTouchSpan < centerYChild.getHeight() * -mTriggerOffset && targetPosition != mViewPagerAdapter.getItemCount() - 1) {
456 | if (!reverseLayout) { targetPosition++; } else { targetPosition--; }
457 | }
458 | }
459 | }
460 | smoothScrollToPosition(safeTargetPosition(targetPosition, mViewPagerAdapter.getItemCount()));
461 | }
462 | }
463 |
464 | private int getFlingCount(int velocity, int cellSize) {
465 | if (velocity == 0) {
466 | return 0;
467 | }
468 | int sign = velocity > 0 ? 1 : -1;
469 | return (int) (sign * Math.ceil((velocity * sign * mFlingFactor / cellSize)
470 | - mTriggerOffset));
471 | }
472 |
473 | private int safeTargetPosition(int position, int count) {
474 | if (position < 0) {
475 | return 0;
476 | }
477 | if (position >= count) {
478 | return count - 1;
479 | }
480 | return position;
481 | }
482 |
483 | public interface OnPageChangedListener {
484 | void OnPageChanged(int oldPosition, int newPosition);
485 | }
486 | }
487 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/adapter/HorizontalAdapter.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.adapter;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.IntRange;
5 | import androidx.recyclerview.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.time.cat.dragboardview.callback.DragHorizontalAdapter;
11 | import com.time.cat.dragboardview.callback.DragHorizontalViewHolder;
12 | import com.time.cat.dragboardview.helper.DragHelper;
13 | import com.time.cat.dragboardview.model.DragColumn;
14 |
15 | import java.util.Collections;
16 | import java.util.List;
17 |
18 | import static com.time.cat.dragboardview.helper.DragHelper.TYPE_CONTENT;
19 | import static com.time.cat.dragboardview.helper.DragHelper.TYPE_FOOTER;
20 |
21 | /**
22 | * @author dlink
23 | * @email linxy59@mail2.sysu.edu.cn
24 | * @date 2018/4/3
25 | * @discription 水平排列的列表
26 | * @usage null
27 | */
28 | public abstract class HorizontalAdapter
29 | extends RecyclerView.Adapter
30 | implements DragHorizontalAdapter {
31 |
32 | protected Context mContext;
33 | private List mData;
34 | protected DragHelper dragHelper;
35 |
36 | private int mDragPosition;//正在拖动的 View 的 position
37 | private boolean mHideDragItem; // 是否隐藏正在拖动的 position
38 |
39 | public HorizontalAdapter(Context context) {
40 | this.mContext = context;
41 | }
42 |
43 | @Override
44 | public VH onCreateViewHolder(ViewGroup parent, int viewType) {
45 | if (needFooter() && viewType == TYPE_FOOTER) {
46 | View convertView = LayoutInflater.from(mContext)
47 | .inflate(getFooterLayoutRes(), parent, false);
48 | return onCreateViewHolder(convertView, TYPE_FOOTER);
49 | }
50 | View convertView = LayoutInflater.from(mContext)
51 | .inflate(getContentLayoutRes(), parent, false);
52 | return onCreateViewHolder(convertView, TYPE_CONTENT);
53 | }
54 |
55 | @Override
56 | public void onBindViewHolder(final VH holder, int position) {
57 | switch (getItemViewType(position)) {
58 | case TYPE_CONTENT:
59 | final DragColumn dragColumn = mData.get(position);
60 | if (position == mDragPosition && mHideDragItem) {
61 | holder.itemView.setVisibility(View.INVISIBLE);
62 | return;
63 | } else {
64 | holder.itemView.setVisibility(View.VISIBLE);
65 | }
66 | holder.itemView.setTag(dragColumn);
67 |
68 | onBindContentViewHolder(holder, dragColumn, position);
69 | break;
70 | case TYPE_FOOTER:
71 | onBindFooterViewHolder(holder, position);
72 | break;
73 | default:
74 | break;
75 | }
76 | }
77 |
78 | @Override
79 | public int getItemCount() {
80 | if (!needFooter()) {return mData.size();}
81 | return mData.size() + 1;
82 | }
83 |
84 | @Override
85 | public int getItemViewType(int position) {
86 | if (!needFooter()) {return TYPE_CONTENT;}
87 | if (position == getItemCount() - 1) {return TYPE_FOOTER;}
88 | return TYPE_CONTENT;
89 | }
90 |
91 | @Override
92 | public void onDrag(int position) {
93 | mDragPosition = position;
94 | mHideDragItem = true;
95 | notifyItemChanged(position);
96 | }
97 |
98 | @Override
99 | public void onDrop(int page, int position, DragColumn tag) {
100 | mHideDragItem = false;
101 | // notifyItemChanged(position);
102 | notifyDataSetChanged();
103 | }
104 |
105 | @Override
106 | public void onDragOut() {
107 | if (mDragPosition >= 0 && mDragPosition < mData.size()) {
108 | mData.remove(mDragPosition);
109 | notifyDataSetChanged();// 此处如果用 notifyItemRemove 下一次选定时的 position 是错的
110 | mDragPosition = -1;
111 | }
112 | }
113 |
114 | @Override
115 | public void onDragIn(int position, DragColumn dragColumnObject) {
116 | if (position > mData.size()) {// 如果拖进来时候的 position 比当前 列表的长度大,就添加到列表末端
117 | position = mData.size();
118 | }
119 | mData.add(position, dragColumnObject);
120 | notifyItemInserted(position);
121 | mDragPosition = position;
122 | mHideDragItem = true;
123 | }
124 |
125 | @Override
126 | public void updateDragItemVisibility(int position) {
127 | if (mDragPosition >= 0 && mDragPosition < mData.size() && position < mData.size() && mDragPosition != position) {
128 | if (Math.abs(mDragPosition - position) == 1) {
129 | notifyItemChanged(mDragPosition);
130 | Collections.swap(mData, mDragPosition, position);
131 | mDragPosition = position;
132 | notifyItemChanged(position);
133 | } else {
134 | notifyItemChanged(mDragPosition);
135 | if (mDragPosition > position) {
136 | for (int i = mDragPosition; i > position; i--) {
137 | Collections.swap(mData, i, i - 1);
138 | notifyItemChanged(i);
139 | }
140 | } else {
141 | for (int i = mDragPosition; i < position; i++) {
142 | Collections.swap(mData, i, i + 1);
143 | notifyItemChanged(i);
144 | }
145 | }
146 | mDragPosition = position;
147 | notifyItemChanged(position);
148 | }
149 | }
150 | }
151 |
152 | public List getData() {
153 | return mData;
154 | }
155 |
156 | public void setData(List mData) {
157 | this.mData = mData;
158 | }
159 |
160 | public void appendNewColumn(DragColumn dragColumn) {
161 | getData().add(dragColumn);
162 | notifyItemInserted(getItemCount() - 1);
163 | }
164 |
165 | public void addNewColumn(@IntRange(from = 0) int position, DragColumn dragColumn) {
166 | getData().add(position, dragColumn);
167 | notifyItemInserted(position);
168 | }
169 |
170 | public void setDragHelper(DragHelper dragHelper) {
171 | this.dragHelper = dragHelper;
172 | }
173 |
174 | public void dragCol(View columnView, int position) {
175 | if (dragHelper != null) {
176 | dragHelper.dragCol(columnView, position);
177 | }
178 | }
179 |
180 | public void dragCol(VH holder) {
181 | dragCol(holder.itemView, holder.getAdapterPosition());
182 | }
183 |
184 | public abstract int getContentLayoutRes();
185 |
186 | public abstract int getFooterLayoutRes();
187 |
188 | public abstract VH onCreateViewHolder(View parent, int viewType);
189 |
190 | public abstract void onBindContentViewHolder(final VH holder, DragColumn dragColumn, int position);
191 |
192 | public abstract void onBindFooterViewHolder(final VH holder, int position);
193 |
194 | public abstract boolean needFooter();
195 |
196 | public abstract class ViewHolder extends RecyclerView.ViewHolder implements DragHorizontalViewHolder {
197 |
198 | public ViewHolder(View convertView, int itemType) {
199 | super(convertView);
200 | if (itemType == TYPE_CONTENT) {
201 | findViewForContent(convertView);
202 | } else {
203 | findViewForFooter(convertView);
204 | }
205 | }
206 |
207 | @Override
208 | public abstract RecyclerView getRecyclerView();
209 |
210 | @Override
211 | public abstract void findViewForContent(View convertView);
212 |
213 | @Override
214 | public abstract void findViewForFooter(View convertView);
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/adapter/RecyclerViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.adapter;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.time.cat.dragboardview.PagerRecyclerView;
8 |
9 | /**
10 | * @author dlink
11 | * @email linxy59@mail2.sysu.edu.cn
12 | * @date 2018/4/3
13 | * @discription {@link PagerRecyclerView} 的Adapter
14 | * @usage null
15 | */
16 | public class RecyclerViewPagerAdapter extends RecyclerView.Adapter {
17 | private final RecyclerView mViewPager;
18 | public RecyclerView.Adapter mAdapter;
19 |
20 | public RecyclerViewPagerAdapter(RecyclerView viewPager, RecyclerView.Adapter adapter) {
21 | mAdapter = adapter;
22 | mViewPager = viewPager;
23 | setHasStableIds(mAdapter.hasStableIds());
24 | }
25 |
26 | @Override
27 | public VH onCreateViewHolder(ViewGroup parent, int viewType) {
28 | return mAdapter.onCreateViewHolder(parent, viewType);
29 | }
30 |
31 | @Override
32 | public void registerAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
33 | super.registerAdapterDataObserver(observer);
34 | mAdapter.registerAdapterDataObserver(observer);
35 | }
36 |
37 | @Override
38 | public void unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
39 | super.unregisterAdapterDataObserver(observer);
40 | mAdapter.unregisterAdapterDataObserver(observer);
41 | }
42 |
43 | @Override
44 | public void onViewRecycled(VH holder) {
45 | super.onViewRecycled(holder);
46 | mAdapter.onViewRecycled(holder);
47 | }
48 |
49 | @Override
50 | public boolean onFailedToRecycleView(VH holder) {
51 | return mAdapter.onFailedToRecycleView(holder);
52 | }
53 |
54 | @Override
55 | public void onViewAttachedToWindow(VH holder) {
56 | super.onViewAttachedToWindow(holder);
57 | mAdapter.onViewAttachedToWindow(holder);
58 | }
59 |
60 | @Override
61 | public void onViewDetachedFromWindow(VH holder) {
62 | super.onViewDetachedFromWindow(holder);
63 | mAdapter.onViewDetachedFromWindow(holder);
64 | }
65 |
66 | @Override
67 | public void onAttachedToRecyclerView(RecyclerView recyclerView) {
68 | super.onAttachedToRecyclerView(recyclerView);
69 | mAdapter.onAttachedToRecyclerView(recyclerView);
70 | }
71 |
72 | @Override
73 | public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
74 | super.onDetachedFromRecyclerView(recyclerView);
75 | mAdapter.onDetachedFromRecyclerView(recyclerView);
76 | }
77 |
78 | @Override
79 | public void onBindViewHolder(VH holder, int position) {
80 | mAdapter.onBindViewHolder(holder, position);
81 | final View itemView = holder.itemView;
82 | ViewGroup.LayoutParams lp;
83 | if (itemView.getLayoutParams() == null) {
84 | lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
85 | } else {
86 | lp = itemView.getLayoutParams();
87 | if (mViewPager.getLayoutManager().canScrollHorizontally()) {
88 | lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
89 | } else {
90 | lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
91 | }
92 | }
93 | itemView.setLayoutParams(lp);
94 | }
95 |
96 | @Override
97 | public void setHasStableIds(boolean hasStableIds) {
98 | super.setHasStableIds(hasStableIds);
99 | mAdapter.setHasStableIds(hasStableIds);
100 | }
101 |
102 | @Override
103 | public int getItemCount() {
104 | return mAdapter.getItemCount();
105 | }
106 |
107 | @Override
108 | public int getItemViewType(int position) {
109 | return mAdapter.getItemViewType(position);
110 | }
111 |
112 | @Override
113 | public long getItemId(int position) {
114 | return mAdapter.getItemId(position);
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/adapter/VerticalAdapter.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.adapter;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.NonNull;
5 | import androidx.recyclerview.widget.RecyclerView;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.time.cat.dragboardview.callback.DragVerticalAdapter;
10 | import com.time.cat.dragboardview.helper.DragHelper;
11 | import com.time.cat.dragboardview.model.DragItem;
12 |
13 | import java.util.ArrayList;
14 | import java.util.Collections;
15 | import java.util.List;
16 |
17 | /**
18 | * @author dlink
19 | * @email linxy59@mail2.sysu.edu.cn
20 | * @date 2018/4/3
21 | * @discription 垂直排列的子项卡片
22 | * @usage null
23 | */
24 | public abstract class VerticalAdapter
25 | extends RecyclerView.Adapter
26 | implements DragVerticalAdapter {
27 |
28 | protected Context mContext;
29 | private List mData;
30 | @NonNull
31 | private DragHelper dragHelper;
32 |
33 | private int mDragPosition;//正在拖动的 View 的 position
34 | private boolean mHideDragItem; // 是否隐藏正在拖动的 position
35 |
36 | public VerticalAdapter(Context context, @NonNull DragHelper dragHelper) {
37 | this.mContext = context;
38 | this.mData = new ArrayList<>();
39 | this.dragHelper = dragHelper;
40 | }
41 |
42 | @Override
43 | public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
44 |
45 | @Override
46 | public void onBindViewHolder(VH holder, final int position) {
47 | if (position == mDragPosition && mHideDragItem) {
48 | holder.itemView.setVisibility(View.INVISIBLE);
49 | } else {
50 | holder.itemView.setVisibility(View.VISIBLE);
51 | }
52 | final DragItem item = mData.get(holder.getAdapterPosition());
53 | holder.itemView.setTag(item);
54 |
55 | onBindViewHolder(mContext, holder, item, holder.getAdapterPosition());
56 | }
57 |
58 | @Override
59 | public int getItemCount() {
60 | return mData.size();
61 | }
62 |
63 | @Override
64 | public void onDrag(int position) {
65 | mDragPosition = position;
66 | mHideDragItem = true;
67 | notifyItemChanged(position);
68 | }
69 |
70 | @Override
71 | public void onDrop(int page, int position, DragItem tag) {
72 | mHideDragItem = false;
73 | notifyItemChanged(position);
74 | }
75 |
76 | @Override
77 | public void onDragOut() {
78 | if (mDragPosition >= 0 && mDragPosition < mData.size()) {
79 | mData.remove(mDragPosition);
80 | notifyDataSetChanged();// 此处如果用 notifyItemRemove 下一次选定时的 position 是错的
81 | mDragPosition = -1;
82 | }
83 | }
84 |
85 | @Override
86 | public void onDragIn(int position, DragItem item) {
87 | if (position > mData.size()) {// 如果拖进来时候的 position 比当前 列表的长度大,就添加到列表末端
88 | position = mData.size();
89 | }
90 | mData.add(position, item);
91 | notifyItemInserted(position);
92 | mDragPosition = position;
93 | mHideDragItem = true;
94 | }
95 |
96 | @Override
97 | public void updateDragItemVisibility(int position) {
98 | if (mDragPosition >= 0 && mDragPosition < mData.size() && position < mData.size() && mDragPosition != position) {
99 | if (Math.abs(mDragPosition - position) == 1) {
100 | notifyItemChanged(mDragPosition);
101 | Collections.swap(mData, mDragPosition, position);
102 | mDragPosition = position;
103 | notifyItemChanged(position);
104 | } else {
105 | notifyItemChanged(mDragPosition);
106 | if (mDragPosition > position) {
107 | for (int i = mDragPosition; i > position; i--) {
108 | Collections.swap(mData, i, i - 1);
109 | notifyItemChanged(i);
110 | }
111 | } else {
112 | for (int i = mDragPosition; i < position; i++) {
113 | Collections.swap(mData, i, i + 1);
114 | notifyItemChanged(i);
115 | }
116 | }
117 | mDragPosition = position;
118 | notifyItemChanged(position);
119 | }
120 | }
121 | }
122 |
123 | public void dragItem(View columnView, int position) {
124 | dragHelper.dragItem(columnView, position);
125 | }
126 |
127 | public void dragItem(VH holder) {
128 | dragItem(holder.itemView, holder.getAdapterPosition());
129 | }
130 |
131 | public void setDragHelper(DragHelper dragHelper) {
132 | this.dragHelper = dragHelper;
133 | }
134 |
135 | public abstract void onBindViewHolder(Context context, VH holder, @NonNull DragItem item, final int position);
136 |
137 | public void setData(List mData) {
138 | this.mData = mData;
139 | notifyDataSetChanged();
140 | }
141 |
142 | public List getData() {
143 | return mData;
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/callback/DragHorizontalAdapter.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.callback;
2 |
3 | import com.time.cat.dragboardview.model.DragColumn;
4 |
5 | /**
6 | * @author dlink
7 | * @email linxy59@mail2.sysu.edu.cn
8 | * @date 2018/4/3
9 | * @discription null
10 | * @usage null
11 | */
12 | public interface DragHorizontalAdapter {
13 | /**
14 | * call if on dragItem item
15 | * @param position item position in Item List (which in VerticalRecyclerView)
16 | * 0 <= position <= size()-1
17 | * 拖动的 View 在纵向 recyclerView 上的 position
18 | */
19 | void onDrag(int position);
20 |
21 | /**
22 | * call if on dropItem item
23 | * @param page item position in Entry List (which in HorizontalRecyclerView)
24 | * 拖动的 View 在横向 recyclerView 上的 position
25 | * @param position dropItem item to position in entry.getItemList()
26 | * 0 <= position <= size()-1
27 | * 拖动的 View 在纵向 recyclerView 上的 position
28 | */
29 | void onDrop(int page, int position, DragColumn tag);
30 |
31 | /**
32 | * call if on dragItem out of current entry page
33 | */
34 | void onDragOut();
35 |
36 | /**
37 | * call if on dragItem in current entry page
38 | *
39 | * @param position item position in Item List (which in VerticalRecyclerView)
40 | * 0 <= position <= size()-1
41 | * 拖动的 View 在纵向 recyclerView 上的 position
42 | * @param tag convert it to your Item object
43 | */
44 | void onDragIn(int position, DragColumn tag);
45 |
46 | /**
47 | * call if event.getAction() == MotionEvent.ACTION_MOVE
48 | *
49 | * @param position item position in Item List (VerticalRecyclerView)
50 | * 0 <= position <= size()-1
51 | * 拖动的 View 在纵向 recyclerView 上的 position
52 | */
53 | void updateDragItemVisibility(int position);
54 | }
55 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/callback/DragHorizontalViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.callback;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | /**
7 | * @author dlink
8 | * @email linxy59@mail2.sysu.edu.cn
9 | * @date 2018/4/3
10 | * @discription null
11 | * @usage null
12 | */
13 | public interface DragHorizontalViewHolder {
14 | /**
15 | * each Horizontal ViewHolder is supposed to have a RecycleView
16 | * @return RecycleView in ViewHolder which contains vertical items
17 | */
18 | RecyclerView getRecyclerView();
19 |
20 | void findViewForContent(View itemView);
21 |
22 | void findViewForFooter(View itemView);
23 | }
24 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/callback/DragVerticalAdapter.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.callback;
2 |
3 | import com.time.cat.dragboardview.model.DragItem;
4 |
5 | /**
6 | * @author dlink
7 | * @email linxy59@mail2.sysu.edu.cn
8 | * @date 2018/4/3
9 | * @discription null
10 | * @usage null
11 | */
12 | public interface DragVerticalAdapter {
13 | /**
14 | * call if on dragItem item
15 | * @param position item position in Item List (which in VerticalRecyclerView)
16 | * 0 <= position <= size()-1
17 | * 拖动的 View 在纵向 recyclerView 上的 position
18 | */
19 | void onDrag(int position);
20 |
21 | /**
22 | * call if on dropItem item
23 | * @param page item position in Entry List (which in HorizontalRecyclerView)
24 | * 拖动的 View 在横向 recyclerView 上的 position
25 | * @param position dropItem item to position in entry.getItemList()
26 | * 0 <= position <= size()-1
27 | * 拖动的 View 在纵向 recyclerView 上的 position
28 | * @param tag convert it to your Item object
29 | */
30 | void onDrop(int page, int position, DragItem tag);
31 |
32 | /**
33 | * call if on dragItem out of current entry page
34 | */
35 | void onDragOut();
36 |
37 | /**
38 | * call if on dragItem in of current entry page
39 | *
40 | * @param position item position in Item List (which in VerticalRecyclerView)
41 | * 0 <= position <= size()-1
42 | * 拖动的 View 在纵向 recyclerView 上的 position
43 | * @param tag convert it to your Item object
44 | */
45 | void onDragIn(int position, DragItem tag);
46 |
47 | /**
48 | * call if event.getAction() == MotionEvent.ACTION_MOVE
49 | *
50 | * @param position item position in Item List (VerticalRecyclerView)
51 | * 0 <= position <= size()-1
52 | * 拖动的 View 在纵向 recyclerView 上的 position
53 | */
54 | void updateDragItemVisibility(int position);
55 | }
56 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/callback/onDragColumnListener.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.callback;
2 |
3 | import android.view.MotionEvent;
4 | import android.view.View;
5 |
6 | /**
7 | * @author dlink
8 | * @email linxy59@mail2.sysu.edu.cn
9 | * @date 2018/6/2
10 | * @discription 设计监听,未使用
11 | * @usage null
12 | */
13 | public interface onDragColumnListener {
14 | void onStartDragColumn(View columnView, int startPosition);
15 |
16 | void onDraggingColumn(View columnView, MotionEvent event);
17 |
18 | void onEndDragColumn(View columnView, int startPosition, int endPosition);
19 | }
20 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/callback/onDragItemListener.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.callback;
2 |
3 | import android.view.MotionEvent;
4 | import android.view.View;
5 |
6 | /**
7 | * @author dlink
8 | * @email linxy59@mail2.sysu.edu.cn
9 | * @date 2018/6/2
10 | * @discription 设计监听,未使用
11 | * @usage null
12 | */
13 | public interface onDragItemListener {
14 | void onStartDragItem(View itemView, int startPosition);
15 |
16 | void onDraggingItem(View itemView, MotionEvent event);
17 |
18 | void onEndDragItem(View itemView, int startPosition, int endPosition);
19 | }
20 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/helper/DragHelper.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.helper;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.PixelFormat;
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.LinearLayoutManager;
9 | import androidx.recyclerview.widget.RecyclerView;
10 | import android.util.DisplayMetrics;
11 | import android.util.Log;
12 | import android.view.Gravity;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.view.WindowManager;
17 | import android.widget.ImageView;
18 |
19 | import com.time.cat.dragboardview.DragLayout;
20 | import com.time.cat.dragboardview.PagerRecyclerView;
21 | import com.time.cat.dragboardview.callback.DragHorizontalAdapter;
22 | import com.time.cat.dragboardview.callback.DragHorizontalViewHolder;
23 | import com.time.cat.dragboardview.callback.DragVerticalAdapter;
24 | import com.time.cat.dragboardview.model.DragColumn;
25 | import com.time.cat.dragboardview.model.DragItem;
26 |
27 | import java.util.Timer;
28 | import java.util.TimerTask;
29 |
30 | /**
31 | * @author dlink
32 | * @email linxy59@mail2.sysu.edu.cn
33 | * @date 2018/4/3
34 | * @discription view 的拖拽功能,给 {@link DragLayout} 用
35 | * @usage null
36 | */
37 | public class DragHelper {
38 | public static final int TYPE_CONTENT = 1;
39 | public static final int TYPE_FOOTER = 2;
40 |
41 | private WindowManager mWindowManager;
42 | private WindowManager.LayoutParams mWindowParams;
43 | private ImageView mDragImageView;
44 | private RecyclerView mCurrentVerticalRecycleView;
45 | private PagerRecyclerView mHorizontalRecyclerView;
46 |
47 | private DragItem dragItem;
48 | private boolean isDraggingItem = false;//抓起=true,否则=false
49 | private DragColumn dragColumn;
50 | private boolean isDraggingColumn = false;//是否正在拖拽一列,抓起=true,否则=false
51 |
52 | private float mBornLocationX, mBornLocationY;//抓起时 view 的坐标
53 | private int offsetX, offsetY;//抓起时 view 坐标和点击点的距离
54 | private boolean confirmOffset = false;//是否确定了 offset
55 |
56 | private Timer mHorizontalScrollTimer = new Timer();//横向滑动
57 | private TimerTask mHorizontalScrollTimerTask;//横向滑动
58 | private static final int HORIZONTAL_STEP = 30;// 横向滑动步伐.
59 | private static final int HORIZONTAL_SCROLL_PERIOD = 20;// 滑动时间间隔
60 | private int leftScrollBounce;// 拖动的时候,开始向左滚动的边界
61 | private int rightScrollBounce;// 拖动的时候,开始向右滚动的边界
62 |
63 | private Timer mVerticalScrollTimer = new Timer();//纵向滑动
64 | private TimerTask mVerticalScrollTimerTask;//纵向滑动
65 | private static final int VERTICAL_STEP = 10;// 纵向滑动步伐.
66 | private static final int VERTICAL_SCROLL_PERIOD = 10;
67 | private int upScrollBounce;// 拖动的时候,开始向上滚动的边界
68 | private int downScrollBounce;// 拖动的时候,开始向下滚动的边界
69 | private int mPosition = -1;// 拖动的 View 在纵向 recyclerView 上的 position
70 | private int mPagerPosition = -1;// 拖动的 View 在横向 recyclerView 上的 position
71 | private int screenWidth = 0;
72 |
73 | @SuppressLint("ClickableViewAccessibility")
74 | public DragHelper(Context activity) {
75 | mWindowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
76 | mWindowParams = new WindowManager.LayoutParams();
77 | mWindowParams.type = WindowManager.LayoutParams.TYPE_APPLICATION;
78 | mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
79 | mWindowParams.alpha = 1.0f;
80 | mWindowParams.format = PixelFormat.TRANSLUCENT;
81 | mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
82 | mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
83 | mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
84 | mWindowParams.x = 0;
85 | mWindowParams.y = 0;
86 |
87 | DisplayMetrics dm = new DisplayMetrics();
88 | mWindowManager.getDefaultDisplay().getMetrics(dm);
89 | screenWidth = dm.widthPixels;
90 |
91 | mDragImageView = new ImageView(activity);
92 | mDragImageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
93 | mDragImageView.setPadding(10, 10, 10, 10);
94 | mDragImageView.setOnTouchListener(new View.OnTouchListener() {
95 | @Override
96 | public boolean onTouch(View v, MotionEvent event) {
97 | if (event.getAction() == MotionEvent.ACTION_OUTSIDE || event.getAction() == MotionEvent.ACTION_DOWN) {
98 | if (isDraggingItem) {
99 | dropItem();
100 | } else if (isDraggingColumn) {
101 | dropCol();
102 | }
103 | }
104 | return false;
105 | }
106 | });
107 | }
108 |
109 |
110 | //region drag column
111 |
112 | /**
113 | * 是否在拖动一列
114 | */
115 | public boolean isDraggingColumn() {
116 | return isDraggingColumn;
117 | }
118 |
119 | /**
120 | * 抓起
121 | *
122 | * @param columnView 抓起的 View
123 | * @param position 抓起的 View 在 横向RecyclerView 的 position
124 | */
125 | public void dragCol(View columnView, int position) {
126 | columnView.destroyDrawingCache();
127 | columnView.setDrawingCacheEnabled(true);
128 | Bitmap bitmap = columnView.getDrawingCache();
129 | if (bitmap != null && !bitmap.isRecycled()) {
130 | mDragImageView.setImageBitmap(bitmap);
131 | mDragImageView.setRotation(1.5f);
132 | mDragImageView.setAlpha(0.8f);
133 |
134 | isDraggingColumn = true;
135 |
136 | if (columnView.getTag() instanceof DragColumn) {
137 | dragColumn = (DragColumn) columnView.getTag();
138 | }
139 | int dragPage = mHorizontalRecyclerView.getCurrentPosition();
140 | RecyclerView.ViewHolder holder = (RecyclerView.ViewHolder) mHorizontalRecyclerView.findViewHolderForAdapterPosition(dragPage);
141 | if (holder != null && holder.itemView != null && holder.getItemViewType() == TYPE_CONTENT) {
142 | mCurrentVerticalRecycleView = ((DragHorizontalViewHolder) holder).getRecyclerView();
143 | mPagerPosition = dragPage;
144 | }
145 |
146 | getTargetHorizontalRecyclerViewScrollBoundaries();
147 | getTargetVerticalRecyclerViewScrollBoundaries();
148 |
149 | int[] location = new int[2];
150 | columnView.getLocationOnScreen(location);
151 | mWindowParams.x = location[0];
152 | mWindowParams.y = location[1];
153 | mBornLocationX = location[0];
154 | mBornLocationY = location[1];
155 | confirmOffset = false;
156 | mPosition = position;
157 | mWindowManager.addView(mDragImageView, mWindowParams);
158 | getHorizontalAdapter().onDrag(position);
159 | }
160 | }
161 |
162 | /**
163 | * 放下
164 | */
165 | public void dropCol() {
166 | if (isDraggingColumn) {
167 | mWindowManager.removeView(mDragImageView);
168 | isDraggingColumn = false;
169 |
170 | if (mVerticalScrollTimerTask != null) {
171 | mVerticalScrollTimerTask.cancel();
172 | }
173 |
174 | if (mHorizontalScrollTimerTask != null) {
175 | mHorizontalScrollTimerTask.cancel();
176 | }
177 |
178 | if (mHorizontalRecyclerView != null) {
179 | mHorizontalRecyclerView.backToCurrentPage();
180 | }
181 |
182 | getHorizontalAdapter().onDrop(mPagerPosition, mPosition, dragColumn);
183 | }
184 | }
185 |
186 | /**
187 | * 更新当前拖动点下面的 RecyclerView
188 | */
189 | private void updateSlidingHorizontalRecyclerView(float x, float y) {
190 | int newPage = getHorizontalCurrentPosition(x, y); // 传入的是相对屏幕的 x,y
191 | if (mPagerPosition != newPage) {
192 | RecyclerView.ViewHolder holder = (RecyclerView.ViewHolder) mHorizontalRecyclerView.findViewHolderForAdapterPosition(newPage);
193 | if (holder != null && holder.itemView != null && holder.getItemViewType() == TYPE_CONTENT) {
194 | getHorizontalAdapter().onDragOut();
195 | mCurrentVerticalRecycleView = ((DragHorizontalViewHolder) holder).getRecyclerView();
196 | mPagerPosition = newPage;
197 | getHorizontalAdapter().onDragIn(mPosition, dragColumn);
198 |
199 | }
200 | }
201 | }
202 |
203 | /**
204 | * 获取当前拖动项的 position
205 | *
206 | * @param rowX 拖动点相对于屏幕的横坐标
207 | * @param rowY 拖动点相对于屏幕的纵坐标
208 | */
209 | private void findViewPositionInHorizontalRV(float rowX, float rowY) {
210 | int[] location = new int[2];
211 | mHorizontalRecyclerView.getLocationOnScreen(location);
212 | float x = rowX - location[0];
213 | float y = rowY - location[1];
214 | View child = mHorizontalRecyclerView.findChildViewUnder(x, y);// 这个方法传入的值是相对于 recyclerView 的
215 | int newPosition = mHorizontalRecyclerView.getChildAdapterPosition(child);
216 | int footerChildIndex = mHorizontalRecyclerView.getChildCount() + 1;//把抓住的加回去
217 | if (newPosition != RecyclerView.NO_POSITION
218 | && newPosition != footerChildIndex) {
219 | getHorizontalAdapter().updateDragItemVisibility(mPosition);
220 | if (mPosition != newPosition && mPosition < footerChildIndex) {
221 | mPosition = newPosition;
222 | }
223 | }
224 | }
225 |
226 | /**
227 | * 获取当前纵向 RecyclerView 的 Adapter
228 | *
229 | * @return Adapter
230 | */
231 | private DragHorizontalAdapter getHorizontalAdapter() {
232 | return (DragHorizontalAdapter) mHorizontalRecyclerView.getAdapter();
233 | }
234 |
235 | /**
236 | * 绑定 横向的 RecyclerView
237 | *
238 | * @param view 横向的 RecyclerView
239 | */
240 | public void bindHorizontalRecyclerView(@NonNull PagerRecyclerView view) {
241 | mHorizontalRecyclerView = view;
242 | RecyclerView.LayoutManager layoutManager = view.getLayoutManager();
243 | if (!(layoutManager instanceof LinearLayoutManager)) {
244 | throw new RuntimeException("LayoutManager must be LinearLayoutManager");
245 | }
246 | }
247 | //endregion
248 |
249 |
250 | //region drag item
251 |
252 | /**
253 | * 是否在拖动一项
254 | */
255 | public boolean isDraggingItem() {
256 | return isDraggingItem;
257 | }
258 |
259 | /**
260 | * 抓起
261 | *
262 | * @param dragger 抓起的 View
263 | * @param position 抓起的 View 在 RecyclerView 的 position
264 | */
265 | public void dragItem(View dragger, int position) {
266 | dragger.destroyDrawingCache();
267 | dragger.setDrawingCacheEnabled(true);
268 | Bitmap bitmap = dragger.getDrawingCache();
269 | if (bitmap != null && !bitmap.isRecycled()) {
270 | mDragImageView.setImageBitmap(bitmap);
271 | mDragImageView.setRotation(1.5f);
272 | mDragImageView.setAlpha(0.8f);
273 |
274 | isDraggingItem = true;
275 | if (dragger.getTag() instanceof DragItem) {
276 | dragItem = (DragItem) dragger.getTag();
277 | }
278 | int dragPage = mHorizontalRecyclerView.getCurrentPosition();
279 | RecyclerView.ViewHolder holder = (RecyclerView.ViewHolder) mHorizontalRecyclerView.findViewHolderForAdapterPosition(dragPage);
280 | if (holder != null && holder.itemView != null && holder.getItemViewType() == TYPE_CONTENT) {
281 | mCurrentVerticalRecycleView = ((DragHorizontalViewHolder) holder).getRecyclerView();
282 |
283 | mPagerPosition = dragPage;
284 | }
285 |
286 | getTargetHorizontalRecyclerViewScrollBoundaries();
287 | getTargetVerticalRecyclerViewScrollBoundaries();
288 |
289 | int[] location = new int[2];
290 | dragger.getLocationOnScreen(location);
291 | mWindowParams.x = location[0];
292 | mWindowParams.y = location[1];
293 | mBornLocationX = location[0];
294 | mBornLocationY = location[1];
295 | confirmOffset = false;
296 | mPosition = position;
297 | mWindowManager.addView(mDragImageView, mWindowParams);
298 | getCurrentVerticalAdapter().onDrag(position);
299 | }
300 | }
301 |
302 | /**
303 | * 放下
304 | */
305 | public void dropItem() {
306 | if (isDraggingItem) {
307 | mWindowManager.removeView(mDragImageView);
308 | isDraggingItem = false;
309 |
310 | if (mVerticalScrollTimerTask != null) {
311 | mVerticalScrollTimerTask.cancel();
312 | }
313 |
314 | if (mHorizontalScrollTimerTask != null) {
315 | mHorizontalScrollTimerTask.cancel();
316 | }
317 |
318 | if (mHorizontalRecyclerView != null) {
319 | mHorizontalRecyclerView.backToCurrentPage();
320 | }
321 |
322 | getCurrentVerticalAdapter().onDrop(mPagerPosition, mPosition, dragItem);
323 | }
324 | }
325 |
326 | /**
327 | * 更新当前拖动点下面的 RecyclerView
328 | */
329 | private void updateSlidingVerticalRecyclerView(float x, float y) {
330 | int newPage = getHorizontalCurrentPosition(x, y); // 传入的是相对屏幕的 x,y
331 | if (mPagerPosition != newPage) {
332 | RecyclerView.ViewHolder holder = (RecyclerView.ViewHolder) mHorizontalRecyclerView.findViewHolderForAdapterPosition(newPage);
333 | if (holder != null && holder.itemView != null && holder.getItemViewType() == TYPE_CONTENT) {
334 | getCurrentVerticalAdapter().onDragOut();
335 |
336 | mCurrentVerticalRecycleView = ((DragHorizontalViewHolder) holder).getRecyclerView();
337 | mPagerPosition = newPage;
338 |
339 | getCurrentVerticalAdapter().onDragIn(mPosition, dragItem);
340 | }
341 | }
342 | }
343 |
344 | /**
345 | * 获取当前拖动项的 position
346 | *
347 | * @param rowX 拖动点相对于屏幕的横坐标
348 | * @param rowY 拖动点相对于屏幕的纵坐标
349 | */
350 | private void findViewPositionInCurVerticalRV(float rowX, float rowY) {
351 | int[] location = new int[2];
352 | mCurrentVerticalRecycleView.getLocationOnScreen(location);
353 | float x = rowX - location[0];
354 | float y = rowY - location[1];
355 | View child = mCurrentVerticalRecycleView.findChildViewUnder(x, y);// 这个方法传入的值是相对于 recyclerView 的
356 | int newPosition = mCurrentVerticalRecycleView.getChildAdapterPosition(child);
357 | if (newPosition != RecyclerView.NO_POSITION) {
358 | getCurrentVerticalAdapter().updateDragItemVisibility(mPosition);
359 | if (mPosition != newPosition) {
360 | mPosition = newPosition;
361 | }
362 | }
363 | }
364 |
365 | /**
366 | * 获取当前纵向 RecyclerView 的 Adapter
367 | *
368 | * @return Adapter
369 | */
370 | private DragVerticalAdapter getCurrentVerticalAdapter() {
371 | return (DragVerticalAdapter) mCurrentVerticalRecycleView.getAdapter();
372 | }
373 | //endregion
374 |
375 |
376 | //region compute
377 |
378 | /**
379 | * 更新拖动点的坐标
380 | *
381 | * @param rowX 相对屏幕的横坐标
382 | * @param rowY 相对屏幕的纵坐标
383 | */
384 | public void updateDraggingPosition(float rowX, float rowY) {
385 | if (mWindowManager == null || mWindowParams == null) { return; }
386 | if (!confirmOffset) {
387 | calculateOffset(rowX, rowY);
388 | }
389 | if (isDraggingItem) {
390 | mWindowParams.x = (int) (rowX - offsetX);
391 | mWindowParams.y = (int) (rowY - offsetY);
392 | mWindowManager.updateViewLayout(mDragImageView, mWindowParams);
393 | updateSlidingVerticalRecyclerView(rowX, rowY);
394 | findViewPositionInCurVerticalRV(rowX, rowY);
395 | recyclerViewScrollHorizontal((int) rowX, (int) rowY);
396 | recyclerViewScrollVertical((int) rowX, (int) rowY);
397 | } else if (isDraggingColumn) {
398 | mWindowParams.x = (int) (rowX - offsetX);
399 | mWindowParams.y = (int) (rowY - offsetY);
400 | mWindowManager.updateViewLayout(mDragImageView, mWindowParams);
401 | updateSlidingHorizontalRecyclerView(rowX, rowY);
402 | findViewPositionInHorizontalRV(rowX, rowY);
403 | recyclerViewScrollHorizontal((int) rowX, (int) rowY);
404 | recyclerViewScrollVertical((int) rowX, (int) rowY);
405 | }
406 | }
407 |
408 | /**
409 | * 计算拖动点和生成的 ImageView 坐标的偏移
410 | *
411 | * @param x 横坐标
412 | * @param y 纵坐标
413 | */
414 | private void calculateOffset(float x, float y) {
415 | offsetX = (int) Math.abs(x - mBornLocationX);
416 | offsetY = (int) Math.abs(y - mBornLocationY);
417 | confirmOffset = true;
418 | }
419 |
420 | /**
421 | * 获取纵向滑动边界
422 | */
423 | private void getTargetVerticalRecyclerViewScrollBoundaries() {
424 | int[] location = new int[2];
425 | mCurrentVerticalRecycleView.getLocationOnScreen(location);
426 | upScrollBounce = location[1] + 150;
427 | downScrollBounce = location[1] + mCurrentVerticalRecycleView.getHeight() - 150;
428 | }
429 |
430 | /**
431 | * 获取横向滑动边界
432 | */
433 | private void getTargetHorizontalRecyclerViewScrollBoundaries() {
434 | leftScrollBounce = 200;
435 |
436 | rightScrollBounce = screenWidth - 200;
437 | Log.i("MyTag", "leftScrollBounce " + leftScrollBounce + " rightScrollBounce " + rightScrollBounce);
438 | }
439 |
440 | /**
441 | * 横向 RecyclerView 滑动
442 | *
443 | * @param x 拖动点横坐标
444 | */
445 | private void recyclerViewScrollHorizontal(final int x, final int y) {
446 | if (mHorizontalScrollTimerTask != null) { mHorizontalScrollTimerTask.cancel(); }
447 |
448 | if (x > rightScrollBounce) {
449 | mHorizontalScrollTimerTask = new TimerTask() {
450 | @Override
451 | public void run() {
452 | mHorizontalRecyclerView.post(new Runnable() {
453 | @Override
454 | public void run() {
455 | mHorizontalRecyclerView.scrollBy(HORIZONTAL_STEP, 0);
456 | findViewPositionInCurVerticalRV(x, y);
457 | }
458 | });
459 | }
460 | };
461 | mHorizontalScrollTimer.schedule(mHorizontalScrollTimerTask, 0, HORIZONTAL_SCROLL_PERIOD);
462 | } else if (x < leftScrollBounce) {
463 | mHorizontalScrollTimerTask = new TimerTask() {
464 | @Override
465 | public void run() {
466 | mHorizontalRecyclerView.post(new Runnable() {
467 | @Override
468 | public void run() {
469 | mHorizontalRecyclerView.scrollBy(-HORIZONTAL_STEP, 0);
470 | findViewPositionInCurVerticalRV(x, y);
471 | }
472 | });
473 | }
474 | };
475 | mHorizontalScrollTimer.schedule(mHorizontalScrollTimerTask, 0, HORIZONTAL_SCROLL_PERIOD);
476 | }
477 | }
478 |
479 | /**
480 | * 纵向 RecyclerView 滑动
481 | *
482 | * @param y 拖动点纵坐标
483 | */
484 | private void recyclerViewScrollVertical(final int x, final int y) {
485 | if (mVerticalScrollTimerTask != null) { mVerticalScrollTimerTask.cancel(); }
486 | if (y > downScrollBounce) {
487 | mVerticalScrollTimerTask = new TimerTask() {
488 | @Override
489 | public void run() {
490 | mCurrentVerticalRecycleView.post(new Runnable() {
491 | @Override
492 | public void run() {
493 | mCurrentVerticalRecycleView.scrollBy(0, VERTICAL_STEP);
494 | findViewPositionInCurVerticalRV(x, y);
495 | }
496 | });
497 | }
498 | };
499 | mVerticalScrollTimer.schedule(mVerticalScrollTimerTask, 0, VERTICAL_SCROLL_PERIOD);
500 | } else if (y < upScrollBounce) {
501 | mVerticalScrollTimerTask = new TimerTask() {
502 | @Override
503 | public void run() {
504 | mCurrentVerticalRecycleView.post(new Runnable() {
505 | @Override
506 | public void run() {
507 | mCurrentVerticalRecycleView.scrollBy(0, -VERTICAL_STEP);
508 | findViewPositionInCurVerticalRV(x, y);
509 | }
510 | });
511 | }
512 | };
513 | mVerticalScrollTimer.schedule(mVerticalScrollTimerTask, 0, VERTICAL_SCROLL_PERIOD);
514 | }
515 | }
516 |
517 |
518 | private int getHorizontalCurrentPosition(float rowX, float rowY) {
519 | int[] location = new int[2];
520 | mHorizontalRecyclerView.getLocationOnScreen(location);
521 | float x = rowX - location[0];
522 | float y = rowY - location[1];
523 | View child = mHorizontalRecyclerView.findChildViewUnder(x, y);
524 | if (child != null) {
525 | return mHorizontalRecyclerView.getChildAdapterPosition(child);
526 | }
527 | return mPagerPosition;
528 | }
529 | //endregion
530 | }
531 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/model/DragColumn.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.model;
2 |
3 | import androidx.annotation.IntRange;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @author dlink
9 | * @email linxy59@mail2.sysu.edu.cn
10 | * @date 2018/11/30
11 | * @discription null
12 | * @usage null
13 | */
14 | public interface DragColumn {
15 | List extends DragItem> getItemList();
16 |
17 | @IntRange(from = 0)
18 | int getColumnIndex();
19 |
20 | void setColumnIndex(@IntRange(from = 0) int columnIndexInHorizontalRecycleView);
21 | }
22 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/model/DragItem.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.model;
2 |
3 | import androidx.annotation.IntRange;
4 |
5 | /**
6 | * @author dlink
7 | * @email linxy59@mail2.sysu.edu.cn
8 | * @date 2018/11/30
9 | * @discription null
10 | * @usage null
11 | */
12 | public interface DragItem {
13 | @IntRange(from = 0)
14 | int getColumnIndex();
15 |
16 | @IntRange(from = 0)
17 | int getItemIndex();
18 |
19 | void setColumnIndex(@IntRange(from = 0) int columnIndexInHorizontalRecycleView);
20 |
21 | void setItemIndex(@IntRange(from = 0) int itemIndexInVerticalRecycleView);
22 | }
23 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/java/com/time/cat/dragboardview/utils/RecyclerviewUtils.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.dragboardview.utils;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | import com.time.cat.dragboardview.PagerRecyclerView;
7 |
8 | /**
9 | * @author dlink
10 | * @email linxy59@mail2.sysu.edu.cn
11 | * @date 2018/4/3
12 | * @discription Recyclerview工具类,给 {@link PagerRecyclerView} 用
13 | * @usage null
14 | */
15 | public class RecyclerviewUtils {
16 |
17 | /**
18 | * Get center child in X Axes
19 | */
20 | public static View getCenterXChild(RecyclerView recyclerView) {
21 | int childCount = recyclerView.getChildCount();
22 | if (childCount > 0) {
23 | for (int i = 0; i < childCount; i++) {
24 | View child = recyclerView.getChildAt(i);
25 | if (isChildInCenterX(recyclerView, child)) {
26 | return child;
27 | }
28 | }
29 | }
30 | return null;
31 | }
32 |
33 | /**
34 | * Get position of center child in X Axes
35 | */
36 | public static int getCenterXChildPosition(RecyclerView recyclerView) {
37 | int childCount = recyclerView.getChildCount();
38 | if (childCount > 0) {
39 | for (int i = 0; i < childCount; i++) {
40 | View child = recyclerView.getChildAt(i);
41 | if (isChildInCenterX(recyclerView, child)) {
42 | return recyclerView.getChildAdapterPosition(child);
43 | }
44 | }
45 | }
46 | return childCount;
47 | }
48 |
49 | /**
50 | * Get center child in Y Axes
51 | */
52 | public static View getCenterYChild(RecyclerView recyclerView) {
53 | int childCount = recyclerView.getChildCount();
54 | if (childCount > 0) {
55 | for (int i = 0; i < childCount; i++) {
56 | View child = recyclerView.getChildAt(i);
57 | if (isChildInCenterY(recyclerView, child)) {
58 | return child;
59 | }
60 | }
61 | }
62 | return null;
63 | }
64 |
65 | /**
66 | * Get position of center child in Y Axes
67 | */
68 | public static int getCenterYChildPosition(RecyclerView recyclerView) {
69 | int childCount = recyclerView.getChildCount();
70 | if (childCount > 0) {
71 | for (int i = 0; i < childCount; i++) {
72 | View child = recyclerView.getChildAt(i);
73 | if (isChildInCenterY(recyclerView, child)) {
74 | return recyclerView.getChildAdapterPosition(child);
75 | }
76 | }
77 | }
78 | return childCount;
79 | }
80 |
81 | public static boolean isChildInCenterX(RecyclerView recyclerView, View view) {
82 | int childCount = recyclerView.getChildCount();
83 | int[] lvLocationOnScreen = new int[2];
84 | int[] vLocationOnScreen = new int[2];
85 | recyclerView.getLocationOnScreen(lvLocationOnScreen);
86 | int middleX = lvLocationOnScreen[0] + recyclerView.getWidth() / 2;
87 | if (childCount > 0) {
88 | view.getLocationOnScreen(vLocationOnScreen);
89 | if (vLocationOnScreen[0] <= middleX && vLocationOnScreen[0] + view.getWidth() >= middleX) {
90 | return true;
91 | }
92 | }
93 | return false;
94 | }
95 |
96 | public static boolean isChildInCenterY(RecyclerView recyclerView, View view) {
97 | int childCount = recyclerView.getChildCount();
98 | int[] lvLocationOnScreen = new int[2];
99 | int[] vLocationOnScreen = new int[2];
100 | recyclerView.getLocationOnScreen(lvLocationOnScreen);
101 | int middleY = lvLocationOnScreen[1] + recyclerView.getHeight() / 2;
102 | if (childCount > 0) {
103 | view.getLocationOnScreen(vLocationOnScreen);
104 | if (vLocationOnScreen[1] <= middleY && vLocationOnScreen[1] + view.getHeight() >= middleY) {
105 | return true;
106 | }
107 | }
108 | return false;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/res/layout/view_drag_board.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/DragBoardView/src/main/res/values/attrs_pagerrecyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DragBoardView
2 |
3 | [](https://app.codacy.com/app/LinXueyuanStdio/DragBoardView?utm_source=github.com&utm_medium=referral&utm_content=LinXueyuanStdio/DragBoardView&utm_campaign=Badge_Grade_Dashboard)
4 |
5 |
6 | DragBoardView is a draggable kanban/board view for Android. it supports `drag item`, `drag column`, `auto center`
7 |
8 | You can just use it like a RecyclerView!
9 |
10 | ## Just use it like a RecyclerView! [中文文档](https://github.com/LinXueyuanStdio/DragBoardView/blob/master/README_zh.md)
11 |
12 | How to use Recyclerview:
13 |
14 |
15 | 1. Add dependency for recyclerview
16 |
17 | ```
18 | compile 'com.android.support:recyclerview-v7:23.1.0'
19 | ```
20 |
21 | Add recyclerview in main layout file
22 |
23 | ```xml
24 |
25 |
32 |
38 |
39 | ```
40 |
41 |
42 |
43 |
44 | 2. Make one item layout xml file
45 |
46 | ```xml
47 |
51 |
52 |
58 |
62 |
63 |
64 | ```
65 |
66 |
67 |
68 | 3. Make model class for each item in list.
69 |
70 | it can be any custom class.
71 |
72 | ```java
73 | public class Item {
74 |
75 | private String name;
76 |
77 | public Item(String n) {
78 | name = n;
79 | }
80 | public String getName() {
81 | return name;
82 | }
83 |
84 | public void setName(String name) {
85 | this.name = name;
86 | }
87 | }
88 | ```
89 |
90 |
91 |
92 | 4. make adapter for recyclerview
93 |
94 | ```java
95 | import androidx.recyclerview.widget.RecyclerView;
96 | import android.util.Log;
97 | import android.view.LayoutInflater;
98 | import android.view.View;
99 | import android.view.ViewGroup;
100 | import android.widget.TextView;
101 | import com.codexpedia.list.viewholder.R;
102 | import java.util.ArrayList;
103 |
104 | public class ItemArrayAdapter extends RecyclerView.Adapter {
105 |
106 | //All methods in this adapter are required for a bare minimum recyclerview adapter
107 | private int listItemLayout;
108 | private ArrayList- itemList;
109 | // Constructor of the class
110 | public ItemArrayAdapter(int layoutId, ArrayList
- itemList) {
111 | listItemLayout = layoutId;
112 | this.itemList = itemList;
113 | }
114 |
115 | // get the size of the list
116 | @Override
117 | public int getItemCount() {
118 | return itemList == null ? 0 : itemList.size();
119 | }
120 |
121 |
122 | // specify the row layout file and click for each row
123 | @Override
124 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
125 | View view = LayoutInflater.from(parent.getContext()).inflate(listItemLayout, parent, false);
126 | ViewHolder myViewHolder = new ViewHolder(view);
127 | return myViewHolder;
128 | }
129 |
130 | // load data in each row element
131 | @Override
132 | public void onBindViewHolder(final ViewHolder holder, final int listPosition) {
133 | TextView item = holder.item;
134 | item.setText(itemList.get(listPosition).getName());
135 | }
136 |
137 | // Static inner class to initialize the views of rows
138 | static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
139 | public TextView item;
140 | public ViewHolder(View itemView) {
141 | super(itemView);
142 | itemView.setOnClickListener(this);
143 | item = (TextView) itemView.findViewById(R.id.txtChords);
144 | }
145 | @Override
146 | public void onClick(View view) {
147 | Log.d("onclick", "onClick " + getLayoutPosition() + " " + item.getText());
148 | }
149 | }
150 | ```
151 |
152 |
153 |
154 |
155 | 5. bind adapter with recyclerview
156 |
157 | ```java
158 | import android.os.Bundle;
159 | import androidx.appcompat.app.AppCompatActivity;
160 | import androidx.recyclerview.widget.DefaultItemAnimator;
161 | import androidx.recyclerview.widget.LinearLayoutManager;
162 | import androidx.recyclerview.widget.RecyclerView;
163 |
164 | import com.codexpedia.list.viewholder.R;
165 |
166 | import java.util.ArrayList;
167 |
168 | public class MainActivity extends AppCompatActivity {
169 |
170 | RecyclerView recyclerView;
171 |
172 | @Override
173 | protected void onCreate(Bundle savedInstanceState) {
174 | super.onCreate(savedInstanceState);
175 | setContentView(R.layout.activity_main);
176 |
177 | // Initializing list view with the custom adapter
178 | ArrayList - itemList = new ArrayList
- ();
179 |
180 | ItemArrayAdapter itemArrayAdapter = new ItemArrayAdapter(R.layout.list_item, itemList);
181 | recyclerView = (RecyclerView) findViewById(R.id.item_list);
182 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
183 | recyclerView.setItemAnimator(new DefaultItemAnimator());
184 | recyclerView.setAdapter(itemArrayAdapter);
185 |
186 | // Populating list items
187 | for(int i=0; i<100; i++) {
188 | itemList.add(new Item("Item " + i));
189 | }
190 |
191 | }
192 |
193 | }
194 | ```
195 |
196 |
197 |
198 |
199 |
200 | As for DragBoardView, it's all the same.
201 |
202 | How to use DragBoardView:
203 |
204 |
205 | 1. Add dependency for DragBoardView
206 |
207 | Add it in your `root` `build.gradle` at the end of repositories:
208 | ```gradle
209 | allprojects {
210 | repositories {
211 | ...
212 | maven { url 'https://jitpack.io' }
213 | }
214 | }
215 | ```
216 | Add the dependency
217 | ```gradle
218 | dependencies {
219 | compile 'com.github.LinXueyuanStdio:DragBoardView:v1.0.0'
220 | }
221 | ```
222 |
223 | declare it in your main layout xml file:
224 |
225 | ```xml
226 |
227 |
228 |
232 |
233 |
238 |
239 |
244 |
245 |
246 | ```
247 |
248 |
249 |
250 |
251 | 2. Make two item layout xml files.
252 |
253 | One for each column item. it should contains a `RecyclerView`
254 |
255 | ```xml
256 |
257 |
262 |
263 |
267 |
268 |
269 | ```
270 |
271 | One for the item in each column.
272 |
273 | ```xml
274 |
279 | ```
280 |
281 |
282 |
283 |
284 | 3. Make model class for each column and each item in list.
285 |
286 | for each column, it should implement `DragColumn` interface.
287 |
288 | ```java
289 | public class Entry implements DragColumn {
290 | private final String name;
291 | private int columnIndex;
292 | private final List itemList;
293 |
294 | public Entry(String name, int columnIndex, List items) {
295 | this.name = name;
296 | this.columnIndex = columnIndex;
297 | this.itemList = items;
298 | }
299 |
300 | public String getName() {
301 | return name;
302 | }
303 |
304 | public List getItemList() {
305 | return itemList;
306 | }
307 |
308 | @Override
309 | public int getColumnIndex() {
310 | return columnIndex;
311 | }
312 |
313 | @Override
314 | public void setColumnIndex(int columnIndexInHorizontalRecycleView) {
315 | //save to database here
316 | }
317 | }
318 |
319 | ```
320 |
321 | for each item in the column, it should implement `DragItem` interface.
322 |
323 | ```java
324 | public class Item implements DragItem {
325 | private final String itemName;
326 | private int colIndex;
327 | private int itemIndex;
328 |
329 | public Item(String itemName, int colIndex, int itemIndex) {
330 | this.itemName = itemName;
331 | this.colIndex = colIndex;
332 | this.itemIndex = itemIndex;
333 | }
334 |
335 | public String getItemName() {
336 | return itemName;
337 | }
338 |
339 | @Override
340 | public int getColumnIndex() {
341 | return colIndex;
342 | }
343 |
344 | @Override
345 | public int getItemIndex() {
346 | return itemIndex;
347 | }
348 |
349 | @Override
350 | public void setColumnIndex(int columnIndexInHorizontalRecycleView) {
351 | //save to database here
352 | }
353 |
354 | @Override
355 | public void setItemIndex(int itemIndexInVerticalRecycleView) {
356 | //save to database here
357 | }
358 | }
359 | ```
360 |
361 |
362 |
363 |
364 | 4. make adapter for DragBoardView
365 |
366 | ```java
367 | public class ColumnAdapter extends HorizontalAdapter
368 | public class ItemAdapter extends VerticalAdapter
369 | ```
370 |
371 |
372 |
373 |
374 | 5. bind adapter with DragBoardView
375 |
376 | ```java
377 | public class MainActivity extends AppCompatActivity {
378 |
379 | DragBoardView dragBoardView;
380 | List mData = new ArrayList<>();
381 |
382 | @Override
383 | protected void onCreate(Bundle savedInstanceState) {
384 | super.onCreate(savedInstanceState);
385 | setContentView(R.layout.activity_main);
386 |
387 | dragBoardView = findViewById(R.id.layout_main);
388 | mAdapter = new ColumnAdapter(this);
389 | mAdapter.setData(mData);
390 | dragBoardView.setHorizontalAdapter(mAdapter);
391 | }
392 |
393 | }
394 | ```
395 |
396 |
397 |
398 | ## gif
399 |
400 |
401 |
402 | ## ScreenShot
403 |
404 | | | | |
405 | |:---:|:---:|:---:|
406 | ||||
407 | |||
408 |
409 | ## Advance
410 |
411 | Meanwhile, PagerRecyclerView is able to be customized by these 3 params:
412 |
413 | |name|format|description|
414 | |:---:|:---:|:---:|
415 | | singlePageFling | boolean | single Page Fling, default false |
416 | | triggerOffset | float | trigger offset, default 0.25f |
417 | | flingFactor | float | fling factor, default 0.15f |
418 |
419 | demo is more clear
420 |
421 | ## demo apk
422 | [download](art/app-debug.apk)
423 |
--------------------------------------------------------------------------------
/README_zh.md:
--------------------------------------------------------------------------------
1 | # DragBoardView
2 |
3 | Android 可拖拽的看板视图, 支持项拖拽、列拖拽,支持自动居中。
4 |
5 | 简单易用,和 `RecyclerView` 用法完全一样!
6 |
7 | ## 像 `RecyclerView` 一样使用 `DragBoardView` ! [中文文档](https://github.com/LinXueyuanStdio/DragBoardView/blob/master/README_zh.md)
8 |
9 | `Recyclerview` 的用法:
10 |
11 |
12 | 1. 添加 recyclerview 的依赖
13 |
14 | ```
15 | compile 'com.android.support:recyclerview-v7:23.1.0'
16 | ```
17 |
18 | 在 xml 布局文件中声明:
19 |
20 | ```xml
21 |
22 |
27 |
28 |
32 |
33 | ```
34 |
35 |
36 |
37 | 2. 写 item 的布局
38 |
39 | ```xml
40 |
44 |
45 |
51 |
55 |
56 |
57 | ```
58 |
59 |
60 |
61 | 3. 写 item 对应的数据类.
62 |
63 | 什么类都行
64 |
65 | ```java
66 | public class Item {
67 |
68 | private String name;
69 |
70 | public Item(String n) {
71 | name = n;
72 | }
73 | public String getName() {
74 | return name;
75 | }
76 |
77 | public void setName(String name) {
78 | this.name = name;
79 | }
80 | }
81 | ```
82 |
83 |
84 |
85 | 4. 写适配器 adapter
86 |
87 | ```java
88 | public class ItemArrayAdapter extends RecyclerView.Adapter {
89 |
90 | //All methods in this adapter are required for a bare minimum recyclerview adapter
91 | private int listItemLayout;
92 | private ArrayList- itemList;
93 | // Constructor of the class
94 | public ItemArrayAdapter(int layoutId, ArrayList
- itemList) {
95 | listItemLayout = layoutId;
96 | this.itemList = itemList;
97 | }
98 |
99 | // get the size of the list
100 | @Override
101 | public int getItemCount() {
102 | return itemList == null ? 0 : itemList.size();
103 | }
104 |
105 |
106 | // specify the row layout file and click for each row
107 | @Override
108 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
109 | View view = LayoutInflater.from(parent.getContext()).inflate(listItemLayout, parent, false);
110 | ViewHolder myViewHolder = new ViewHolder(view);
111 | return myViewHolder;
112 | }
113 |
114 | // load data in each row element
115 | @Override
116 | public void onBindViewHolder(final ViewHolder holder, final int listPosition) {
117 | TextView item = holder.item;
118 | item.setText(itemList.get(listPosition).getName());
119 | }
120 |
121 | // Static inner class to initialize the views of rows
122 | static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
123 | public TextView item;
124 | public ViewHolder(View itemView) {
125 | super(itemView);
126 | itemView.setOnClickListener(this);
127 | item = (TextView) itemView.findViewById(R.id.txtChords);
128 | }
129 | @Override
130 | public void onClick(View view) {
131 | Log.d("onclick", "onClick " + getLayoutPosition() + " " + item.getText());
132 | }
133 | }
134 | ```
135 |
136 |
137 |
138 |
139 | 5. 将适配器 adapter 和 recyclerview 绑定
140 |
141 | ```java
142 | public class MainActivity extends AppCompatActivity {
143 |
144 | RecyclerView recyclerView;
145 |
146 | @Override
147 | protected void onCreate(Bundle savedInstanceState) {
148 | super.onCreate(savedInstanceState);
149 | setContentView(R.layout.activity_main);
150 |
151 | // Initializing list view with the custom adapter
152 | ArrayList - itemList = new ArrayList
- ();
153 |
154 | ItemArrayAdapter itemArrayAdapter = new ItemArrayAdapter(R.layout.list_item, itemList);
155 | recyclerView = (RecyclerView) findViewById(R.id.item_list);
156 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
157 | recyclerView.setItemAnimator(new DefaultItemAnimator());
158 | recyclerView.setAdapter(itemArrayAdapter);
159 |
160 | // Populating list items
161 | for(int i=0; i<100; i++) {
162 | itemList.add(new Item("Item " + i));
163 | }
164 |
165 | }
166 |
167 | }
168 | ```
169 |
170 |
171 |
172 | `DragBoardView` 的用法和 `RecyclerView` 一样。
173 |
174 | `DragBoardView` 的用法:
175 |
176 |
177 | 1. 添加 DragBoardView 的依赖
178 |
179 | 在项目根目录的 `build.gradle` 添加:
180 | ```gradle
181 | allprojects {
182 | repositories {
183 | ...
184 | maven { url 'https://jitpack.io' }
185 | }
186 | }
187 | ```
188 |
189 | 添加依赖
190 |
191 | ```gradle
192 | dependencies {
193 | compile 'com.github.LinXueyuanStdio:DragBoardView:v1.0.0'
194 | }
195 | ```
196 |
197 | 在 `xml` 中声明使用
198 |
199 | ```xml
200 |
201 |
205 |
206 |
211 |
212 |
217 |
218 |
219 | ```
220 |
221 |
222 |
223 |
224 | 2. 写 column 和 item 的布局文件.
225 |
226 | column 是列,它必须包含一个 `RecyclerView`
227 |
228 | ```xml
229 |
230 |
235 |
236 |
240 |
241 |
242 | ```
243 |
244 | item 是列中的项,它的布局请随便写
245 |
246 | ```xml
247 |
252 | ```
253 |
254 |
255 |
256 |
257 | 3. 写 column 和 item 对应的数据类
258 |
259 | column 类必须实现 `DragColumn` 接口.
260 |
261 | ```java
262 | public class Entry implements DragColumn {
263 | private final String name;
264 | private int columnIndex;
265 | private final List itemList;
266 |
267 | public Entry(String name, int columnIndex, List items) {
268 | this.name = name;
269 | this.columnIndex = columnIndex;
270 | this.itemList = items;
271 | }
272 |
273 | public String getName() {
274 | return name;
275 | }
276 |
277 | public List getItemList() {
278 | return itemList;
279 | }
280 |
281 | @Override
282 | public int getColumnIndex() {
283 | return columnIndex;
284 | }
285 |
286 | @Override
287 | public void setColumnIndex(int columnIndexInHorizontalRecycleView) {
288 | //save to database here
289 | }
290 | }
291 |
292 | ```
293 |
294 | item 类必须实现 `DragItem` 接口.
295 |
296 | ```java
297 | public class Item implements DragItem {
298 | private final String itemName;
299 | private int colIndex;
300 | private int itemIndex
301 |
302 | public Item(String itemName, int colIndex, int itemIndex) {
303 | this.itemName = itemName;
304 | this.colIndex = colIndex;
305 | this.itemIndex = itemIndex;
306 | }
307 |
308 | public String getItemName() {
309 | return itemName;
310 | }
311 |
312 | @Override
313 | public int getColumnIndex() {
314 | return colIndex;
315 | }
316 |
317 | @Override
318 | public int getItemIndex() {
319 | return itemIndex;
320 | }
321 |
322 | @Override
323 | public void setColumnIndex(int columnIndexInHorizontalRecycleView) {
324 | //save to database here
325 | }
326 |
327 | @Override
328 | public void setItemIndex(int itemIndexInVerticalRecycleView) {
329 | //save to database here
330 | }
331 | }
332 | ```
333 |
334 |
335 |
336 |
337 | 4. 写适配器 adapter
338 |
339 | 有两个适配器,一个是列适配器,一个是列中包含的 `RecyclerView` 所需的适配器
340 |
341 | ```java
342 | public class ColumnAdapter extends HorizontalAdapter {...}
343 | public class ItemAdapter extends VerticalAdapter {...}
344 | ```
345 |
346 |
347 |
348 |
349 | 5. 将适配器 adapter 和 DragBoardView 绑定
350 |
351 | ```java
352 | public class MainActivity extends AppCompatActivity {
353 |
354 | DragBoardView dragBoardView;
355 | List mData = new ArrayList<>();
356 |
357 | @Override
358 | protected void onCreate(Bundle savedInstanceState) {
359 | super.onCreate(savedInstanceState);
360 | setContentView(R.layout.activity_main);
361 |
362 | dragBoardView = findViewById(R.id.layout_main);
363 | mAdapter = new ColumnAdapter(this);
364 | mAdapter.setData(mData);
365 | dragBoardView.setHorizontalAdapter(mAdapter);
366 | }
367 |
368 | }
369 | ```
370 |
371 |
372 |
373 | ## gif
374 |
375 |
376 |
377 | ## 截图
378 |
379 | | | | |
380 | |:---:|:---:|:---:|
381 | ||||
382 | |||
383 |
384 | ## 进阶
385 |
386 | Meanwhile, PagerRecyclerView is able to be customized by these 3 params:
387 |
388 | |name|format|description|
389 | |:---:|:---:|:---:|
390 | | singlePageFling | boolean | single Page Fling, default false |
391 | | triggerOffset | float | trigger offset, default 0.25f |
392 | | flingFactor | float | fling factor, default 0.15f |
393 |
394 | demo 给出了最小实现。
395 |
396 | ## demo apk
397 | [download](art/app-debug.apk)
398 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion '28.0.3'
6 | defaultConfig {
7 | applicationId "com.time.cat.dragboardview"
8 | minSdkVersion 22
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'androidx.appcompat:appcompat:1.0.0'
24 | implementation "androidx.cardview:cardview:1.0.0"
25 | // material dialog
26 | implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
27 |
28 | implementation project(path: ':DragBoardView')
29 | // implementation 'com.github.LinXueyuanStdio:DragBoardView:v1.0.0'
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/time/cat/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.demo;
2 |
3 | import android.os.Bundle;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.appcompat.widget.Toolbar;
6 |
7 | import com.time.cat.demo.adapter.ColumnAdapter;
8 | import com.time.cat.demo.data.Entry;
9 | import com.time.cat.demo.data.Item;
10 | import com.time.cat.dragboardview.DragBoardView;
11 | import com.time.cat.dragboardview.model.DragColumn;
12 | import com.time.cat.dragboardview.model.DragItem;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /**
18 | * @author dlink
19 | * @email linxy59@mail2.sysu.edu.cn
20 | * @date 2018/4/3
21 | * @discription 主界面
22 | * @usage null
23 | */
24 | public class MainActivity extends AppCompatActivity {
25 |
26 | private ColumnAdapter mAdapter;
27 | DragBoardView dragBoardView;
28 | private List mData = new ArrayList<>();
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 |
35 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
36 | setSupportActionBar(toolbar);
37 |
38 | dragBoardView = findViewById(R.id.layout_main);
39 | mAdapter = new ColumnAdapter(this);
40 | mAdapter.setData(mData);
41 | dragBoardView.setHorizontalAdapter(mAdapter);
42 |
43 | getDataAndRefreshView();
44 | }
45 |
46 | private void getDataAndRefreshView() {
47 | for (int i = 0; i < 3; i++) {
48 | List itemList = new ArrayList<>();
49 | for (int j = 0; j < 5; j++) {
50 | itemList.add(new Item("entry " + i + " item id " + j, "item name " + j, "info " + j));
51 | }
52 | mData.add(new Entry("entry id " + i, "name " + i, itemList));
53 | }
54 | mAdapter.notifyDataSetChanged();
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/time/cat/demo/adapter/ColumnAdapter.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.demo.adapter;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.NonNull;
5 | import androidx.recyclerview.widget.LinearLayoutManager;
6 | import androidx.recyclerview.widget.RecyclerView;
7 | import android.text.TextUtils;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 | import android.widget.ImageView;
12 | import android.widget.RelativeLayout;
13 | import android.widget.TextView;
14 |
15 | import com.afollestad.materialdialogs.DialogAction;
16 | import com.afollestad.materialdialogs.MaterialDialog;
17 | import com.time.cat.demo.R;
18 | import com.time.cat.demo.data.Entry;
19 | import com.time.cat.demo.data.Item;
20 | import com.time.cat.dragboardview.adapter.HorizontalAdapter;
21 | import com.time.cat.dragboardview.model.DragColumn;
22 | import com.time.cat.dragboardview.model.DragItem;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | /**
28 | * @author dlink
29 | * @email linxy59@mail2.sysu.edu.cn
30 | * @date 2018/4/3
31 | * @discription 水平排列的列表
32 | * @usage null
33 | */
34 | public class ColumnAdapter extends HorizontalAdapter {
35 |
36 | public ColumnAdapter(Context context) {
37 | super(context);
38 | }
39 |
40 | @Override
41 | public boolean needFooter() {
42 | return true;
43 | }
44 |
45 | @Override
46 | public int getContentLayoutRes() {
47 | return R.layout.recyclerview_item_entry;
48 | }
49 |
50 | @Override
51 | public int getFooterLayoutRes() {
52 | return R.layout.recyclerview_footer_addlist;
53 | }
54 |
55 | @Override
56 | public ViewHolder onCreateViewHolder(View parent, int viewType) {
57 | return new ViewHolder(parent, viewType);
58 | }
59 |
60 | @Override
61 | public void onBindContentViewHolder(final ViewHolder holder, DragColumn dragColumn, int position) {
62 | holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
63 | @Override
64 | public boolean onLongClick(View v) {
65 | dragCol(holder);
66 | return true;
67 | }
68 | });
69 |
70 | final Entry entry = (Entry) dragColumn;
71 | holder.tv_title.setText(entry.getId());
72 | final List itemList = entry.getItemList();
73 | LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
74 | holder.rv_item.setLayoutManager(layoutManager);
75 | final ItemAdapter itemAdapter = new ItemAdapter(mContext, dragHelper);
76 | itemAdapter.setData(itemList);
77 | holder.rv_item.setAdapter(itemAdapter);
78 | holder.add_task.setOnClickListener(new View.OnClickListener() {
79 | @Override
80 | public void onClick(View v) {
81 | //do something
82 | // plz replace below with your action
83 | new MaterialDialog.Builder(mContext)
84 | .content("添加一个卡片")
85 | .positiveText("添加")
86 | .onPositive(new MaterialDialog.SingleButtonCallback() {
87 | @Override
88 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
89 | // add new Item instantly
90 | itemList.add(new Item(
91 | "entry " + " item id ",
92 | "item name : new Item",
93 | "info : new Item"));
94 | itemAdapter.notifyItemInserted(itemAdapter.getItemCount() - 1);
95 | // then add new Item to your database in io thread
96 | // then view will auto-refresh
97 | }
98 | })
99 | .negativeText("取消")
100 | .onNegative(new MaterialDialog.SingleButtonCallback() {
101 | @Override
102 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
103 | dialog.dismiss();
104 | }
105 | })
106 | .show();
107 | }
108 | });
109 | }
110 |
111 | @Override
112 | public void onBindFooterViewHolder(final ViewHolder holder, int position) {
113 | holder.add_subPlan.setOnClickListener(new View.OnClickListener() {
114 | @Override
115 | public void onClick(View v) {
116 | holder.add_subPlan.setVisibility(View.GONE);
117 | holder.edit_sub_plan.setVisibility(View.VISIBLE);
118 | }
119 | });
120 | holder.btn_cancel.setOnClickListener(new View.OnClickListener() {
121 | @Override
122 | public void onClick(View v) {
123 | holder.add_subPlan.setVisibility(View.VISIBLE);
124 | holder.edit_sub_plan.setVisibility(View.GONE);
125 | }
126 | });
127 | holder.btn_ok.setOnClickListener(new View.OnClickListener() {
128 | @Override
129 | public void onClick(View v) {
130 | String name = holder.editText.getText().toString();
131 | if (!TextUtils.isEmpty(name)) {
132 | appendNewColumn(new Entry(
133 | "entry id " + name,
134 | "name : new entry",
135 | new ArrayList()));
136 | }
137 | }
138 | });
139 | }
140 |
141 | public class ViewHolder extends HorizontalAdapter.ViewHolder {
142 |
143 | RelativeLayout col_content_container;
144 | ImageView title_icon;
145 | TextView tv_title;
146 | RecyclerView rv_item;
147 | RelativeLayout add_task;
148 |
149 | RelativeLayout add_subPlan;
150 | RelativeLayout edit_sub_plan;
151 | Button btn_cancel;
152 | Button btn_ok;
153 | EditText editText;
154 |
155 | public ViewHolder(View convertView, int itemType) {
156 | super(convertView, itemType);
157 | }
158 |
159 | @Override
160 | public RecyclerView getRecyclerView() {
161 | return rv_item;
162 | }
163 |
164 | @Override
165 | public void findViewForContent(View convertView) {
166 | col_content_container = convertView.findViewById(R.id.col_content_container);
167 | title_icon = convertView.findViewById(R.id.title_icon);
168 | tv_title = convertView.findViewById(R.id.tv_title);
169 | rv_item = convertView.findViewById(R.id.rv);
170 | add_task = convertView.findViewById(R.id.add);
171 | }
172 |
173 | @Override
174 | public void findViewForFooter(View convertView) {
175 | add_subPlan = convertView.findViewById(R.id.add_sub_plan);
176 | edit_sub_plan = convertView.findViewById(R.id.edit_sub_plan);
177 | btn_cancel = convertView.findViewById(R.id.add_cancel);
178 | btn_ok = convertView.findViewById(R.id.add_ok);
179 | editText = convertView.findViewById(R.id.add_et);
180 | }
181 | }
182 | }
183 |
184 |
185 |
--------------------------------------------------------------------------------
/app/src/main/java/com/time/cat/demo/adapter/ItemAdapter.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.demo.adapter;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.NonNull;
5 | import androidx.recyclerview.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.time.cat.demo.R;
12 | import com.time.cat.demo.data.Item;
13 | import com.time.cat.dragboardview.adapter.VerticalAdapter;
14 | import com.time.cat.dragboardview.helper.DragHelper;
15 | import com.time.cat.dragboardview.model.DragItem;
16 |
17 | /**
18 | * @author dlink
19 | * @email linxy59@mail2.sysu.edu.cn
20 | * @date 2018/4/3
21 | * @discription 垂直排列的子项卡片
22 | * @usage null
23 | */
24 | public class ItemAdapter extends VerticalAdapter {
25 |
26 | public ItemAdapter(Context context, DragHelper dragHelper) {
27 | super(context, dragHelper);
28 | }
29 |
30 | @Override
31 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
32 | View convertView = LayoutInflater.from(mContext).inflate(R.layout.recyclerview_item_item, parent, false);
33 | return new ViewHolder(convertView);
34 | }
35 |
36 | @Override
37 | public void onBindViewHolder(Context context, final ViewHolder holder, @NonNull DragItem item, final int position) {
38 | holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
39 | @Override
40 | public boolean onLongClick(View v) {
41 | dragItem(holder);
42 | return true;
43 | }
44 | });
45 | holder.item_title.setText(((Item) item).getItemName());
46 | }
47 |
48 | static class ViewHolder extends RecyclerView.ViewHolder {
49 | TextView item_title;
50 |
51 | public ViewHolder(View itemView) {
52 | super(itemView);
53 | item_title = itemView.findViewById(R.id.item_title);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/time/cat/demo/data/Entry.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.demo.data;
2 |
3 | import com.time.cat.dragboardview.model.DragColumn;
4 | import com.time.cat.dragboardview.model.DragItem;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @author dlink
10 | * @email linxy59@mail2.sysu.edu.cn
11 | * @date 2018/4/3
12 | * @discription 列表项,每个列表项包含一个子项的List {@link List- }
13 | * @usage null
14 | */
15 | public class Entry implements DragColumn {
16 | private final String id;
17 | private final String name;
18 | private final List itemList;
19 |
20 | public Entry(String id, String name, List items) {
21 | this.id = id;
22 | this.name = name;
23 | this.itemList = items;
24 | }
25 |
26 | public String getId() {
27 | return id;
28 | }
29 |
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | public List getItemList() {
35 | return itemList;
36 | }
37 |
38 | @Override
39 | public int getColumnIndex() {
40 | return 0;
41 | }
42 |
43 | @Override
44 | public void setColumnIndex(int columnIndexInHorizontalRecycleView) {
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/time/cat/demo/data/Item.java:
--------------------------------------------------------------------------------
1 | package com.time.cat.demo.data;
2 |
3 | import com.time.cat.dragboardview.model.DragItem;
4 |
5 | /**
6 | * @author dlink
7 | * @email linxy59@mail2.sysu.edu.cn
8 | * @date 2018/4/3
9 | * @discription 子项
10 | * @usage null
11 | */
12 | public class Item implements DragItem {
13 | private final String itemId;
14 | private final String itemName;
15 | private final String info;
16 |
17 | public Item(String itemId, String itemName, String info) {
18 | this.itemId = itemId;
19 | this.itemName = itemName;
20 | this.info = info;
21 | }
22 |
23 | public String getItemId() {
24 | return itemId;
25 | }
26 |
27 | public String getItemName() {
28 | return itemName;
29 | }
30 |
31 | public String getInfo() {
32 | return info;
33 | }
34 |
35 | @Override
36 | public int getColumnIndex() {
37 | return 0;
38 | }
39 |
40 | @Override
41 | public int getItemIndex() {
42 | return 0;
43 | }
44 |
45 | @Override
46 | public void setColumnIndex(int columnIndexInHorizontalRecycleView) {
47 |
48 | }
49 |
50 | @Override
51 | public void setItemIndex(int itemIndexInVerticalRecycleView) {
52 |
53 | }
54 | }
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_action_add.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_more_grey_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_rectangle_with_radius.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/recyclerview_footer_addlist.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
24 |
25 |
31 |
32 |
39 |
40 |
41 |
48 |
49 |
61 |
62 |
72 |
73 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/recyclerview_item_entry.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
24 |
25 |
33 |
34 |
43 |
44 |
45 |
54 |
55 |
62 |
63 |
69 |
70 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/recyclerview_item_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
28 |
29 |
30 |
36 |
37 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #03A9F4
4 | #0288D1
5 | #FF4081
6 |
7 | #fff
8 | #000
9 | #00000000
10 | #30000000
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DragBoardView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/art/device-2018-04-04-085351.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/art/device-2018-04-04-085351.gif
--------------------------------------------------------------------------------
/art/device-2018-04-04-085942.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/art/device-2018-04-04-085942.png
--------------------------------------------------------------------------------
/art/device-2018-04-04-090017.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/art/device-2018-04-04-090017.png
--------------------------------------------------------------------------------
/art/device-2018-04-04-090030.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/art/device-2018-04-04-090030.png
--------------------------------------------------------------------------------
/art/device-2018-04-04-090047.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/art/device-2018-04-04-090047.png
--------------------------------------------------------------------------------
/art/device-2018-04-04-090115.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/art/device-2018-04-04-090115.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:4.1.2'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | maven { url "https://jitpack.io" }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/DragBoardView/0f2a676b4528b92bef2a62be903fcf385ffa0cd1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jun 06 18:38:42 CST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':DragBoardView'
2 |
--------------------------------------------------------------------------------