Skip to content

Commit e55970b

Browse files
committed
Revalidate against 24.2.0 removing deprecation
1 parent 3ee525b commit e55970b

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TranslationViewDragHelper.Callback mCallback = new TranslationViewDragHelper.Cal
4444
See the sample [custom view](https://github.com/Commit451/TranslationViewDragHelper/blob/master/app/src/main/java/com/commit451/betterviewdraghelper/sample/AllowsForDragFrameLayout.java) for a more complete example
4545

4646
# Basis
47-
The current version of this helper is derived from `ViewDragHelper` source from `24.0.0` of the Support Library. Due to private constructor access on ViewDragHelper, the source has to be copied out into the TranslationViewDragHelper
47+
The current version of this helper is derived from `ViewDragHelper` source from `24.0.0` of the Support Library. Due to private constructor access on ViewDragHelper, the source has to be copied out into the `TranslationViewDragHelper`. You can check the diff [here](https://www.diffchecker.com/)
4848

4949
License
5050
--------

translationviewdraghelper/src/main/java/com/commit451/translationviewdraghelper/TranslationViewDragHelper.java

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
import java.util.Arrays;
3434

3535
/**
36-
* Modified version of {@link android.support.v4.widget.ViewDragHelper} which accounts for if views
36+
* Modified version of ViewDragHelper which accounts for if views
3737
* have been translated using {@link View#setX(float)} {@link View#setY(float)} or
3838
* {@link View#setTranslationX(float)} and {@link View#setTranslationY(float)}
3939
*/
4040
public class TranslationViewDragHelper {
41-
private static final String TAG = "TranslationViewDragHelper";
41+
private static final String TAG = "TransViewDragHelper";
4242

4343
/**
4444
* A null/invalid pointer ID.
@@ -326,13 +326,15 @@ public int clampViewPositionVertical(View child, int top, int dy) {
326326
* Interpolator defining the animation curve for mScroller
327327
*/
328328
private static final Interpolator sInterpolator = new Interpolator() {
329+
@Override
329330
public float getInterpolation(float t) {
330331
t -= 1.0f;
331332
return t * t * t * t * t + 1.0f;
332333
}
333334
};
334335

335336
private final Runnable mSetIdleRunnable = new Runnable() {
337+
@Override
336338
public void run() {
337339
setDragState(STATE_IDLE);
338340
}
@@ -790,7 +792,7 @@ private void clearMotionHistory() {
790792
}
791793

792794
private void clearMotionHistory(int pointerId) {
793-
if (mInitialMotionX == null) {
795+
if (mInitialMotionX == null || !isPointerDown(pointerId)) {
794796
return;
795797
}
796798
mInitialMotionX[pointerId] = 0;
@@ -842,11 +844,15 @@ private void saveInitialMotion(float x, float y, int pointerId) {
842844
}
843845

844846
private void saveLastMotion(MotionEvent ev) {
845-
final int pointerCount = MotionEventCompat.getPointerCount(ev);
847+
final int pointerCount = ev.getPointerCount();
846848
for (int i = 0; i < pointerCount; i++) {
847-
final int pointerId = MotionEventCompat.getPointerId(ev, i);
848-
final float x = MotionEventCompat.getX(ev, i);
849-
final float y = MotionEventCompat.getY(ev, i);
849+
final int pointerId = ev.getPointerId(i);
850+
// If pointer is invalid then skip saving on ACTION_MOVE.
851+
if (!isValidPointerForActionMove(pointerId)) {
852+
continue;
853+
}
854+
final float x = ev.getX(i);
855+
final float y = ev.getY(i);
850856
mLastMotionX[pointerId] = x;
851857
mLastMotionY[pointerId] = y;
852858
}
@@ -964,7 +970,7 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
964970
case MotionEvent.ACTION_DOWN: {
965971
final float x = ev.getX();
966972
final float y = ev.getY();
967-
final int pointerId = MotionEventCompat.getPointerId(ev, 0);
973+
final int pointerId = ev.getPointerId(0);
968974
saveInitialMotion(x, y, pointerId);
969975

970976
final View toCapture = findTopChildUnder((int) x, (int) y);
@@ -982,9 +988,9 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
982988
}
983989

984990
case MotionEventCompat.ACTION_POINTER_DOWN: {
985-
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
986-
final float x = MotionEventCompat.getX(ev, actionIndex);
987-
final float y = MotionEventCompat.getY(ev, actionIndex);
991+
final int pointerId = ev.getPointerId(actionIndex);
992+
final float x = ev.getX(actionIndex);
993+
final float y = ev.getY(actionIndex);
988994

989995
saveInitialMotion(x, y, pointerId);
990996

@@ -1008,15 +1014,15 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
10081014
if (mInitialMotionX == null || mInitialMotionY == null) break;
10091015

10101016
// First to cross a touch slop over a draggable view wins. Also report edge drags.
1011-
final int pointerCount = MotionEventCompat.getPointerCount(ev);
1017+
final int pointerCount = ev.getPointerCount();
10121018
for (int i = 0; i < pointerCount; i++) {
1013-
final int pointerId = MotionEventCompat.getPointerId(ev, i);
1019+
final int pointerId = ev.getPointerId(i);
10141020

10151021
// If pointer is invalid then skip the ACTION_MOVE.
10161022
if (!isValidPointerForActionMove(pointerId)) continue;
10171023

1018-
final float x = MotionEventCompat.getX(ev, i);
1019-
final float y = MotionEventCompat.getY(ev, i);
1024+
final float x = ev.getX(i);
1025+
final float y = ev.getY(i);
10201026
final float dx = x - mInitialMotionX[pointerId];
10211027
final float dy = y - mInitialMotionY[pointerId];
10221028

@@ -1060,7 +1066,7 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
10601066
}
10611067

10621068
case MotionEventCompat.ACTION_POINTER_UP: {
1063-
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
1069+
final int pointerId = ev.getPointerId(actionIndex);
10641070
clearMotionHistory(pointerId);
10651071
break;
10661072
}
@@ -1100,7 +1106,7 @@ public void processTouchEvent(MotionEvent ev) {
11001106
case MotionEvent.ACTION_DOWN: {
11011107
final float x = ev.getX();
11021108
final float y = ev.getY();
1103-
final int pointerId = MotionEventCompat.getPointerId(ev, 0);
1109+
final int pointerId = ev.getPointerId(0);
11041110
final View toCapture = findTopChildUnder((int) x, (int) y);
11051111

11061112
saveInitialMotion(x, y, pointerId);
@@ -1118,9 +1124,9 @@ public void processTouchEvent(MotionEvent ev) {
11181124
}
11191125

11201126
case MotionEventCompat.ACTION_POINTER_DOWN: {
1121-
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
1122-
final float x = MotionEventCompat.getX(ev, actionIndex);
1123-
final float y = MotionEventCompat.getY(ev, actionIndex);
1127+
final int pointerId = ev.getPointerId(actionIndex);
1128+
final float x = ev.getX(actionIndex);
1129+
final float y = ev.getY(actionIndex);
11241130

11251131
saveInitialMotion(x, y, pointerId);
11261132

@@ -1150,9 +1156,9 @@ public void processTouchEvent(MotionEvent ev) {
11501156
// If pointer is invalid then skip the ACTION_MOVE.
11511157
if (!isValidPointerForActionMove(mActivePointerId)) break;
11521158

1153-
final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
1154-
final float x = MotionEventCompat.getX(ev, index);
1155-
final float y = MotionEventCompat.getY(ev, index);
1159+
final int index = ev.findPointerIndex(mActivePointerId);
1160+
final float x = ev.getX(index);
1161+
final float y = ev.getY(index);
11561162
final int idx = (int) (x - mLastMotionX[mActivePointerId]);
11571163
final int idy = (int) (y - mLastMotionY[mActivePointerId]);
11581164

@@ -1161,15 +1167,15 @@ public void processTouchEvent(MotionEvent ev) {
11611167
saveLastMotion(ev);
11621168
} else {
11631169
// Check to see if any pointer is now over a draggable view.
1164-
final int pointerCount = MotionEventCompat.getPointerCount(ev);
1170+
final int pointerCount = ev.getPointerCount();
11651171
for (int i = 0; i < pointerCount; i++) {
1166-
final int pointerId = MotionEventCompat.getPointerId(ev, i);
1172+
final int pointerId = ev.getPointerId(i);
11671173

11681174
// If pointer is invalid then skip the ACTION_MOVE.
11691175
if (!isValidPointerForActionMove(pointerId)) continue;
11701176

1171-
final float x = MotionEventCompat.getX(ev, i);
1172-
final float y = MotionEventCompat.getY(ev, i);
1177+
final float x = ev.getX(i);
1178+
final float y = ev.getY(i);
11731179
final float dx = x - mInitialMotionX[pointerId];
11741180
final float dy = y - mInitialMotionY[pointerId];
11751181

@@ -1191,20 +1197,20 @@ public void processTouchEvent(MotionEvent ev) {
11911197
}
11921198

11931199
case MotionEventCompat.ACTION_POINTER_UP: {
1194-
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
1200+
final int pointerId = ev.getPointerId(actionIndex);
11951201
if (mDragState == STATE_DRAGGING && pointerId == mActivePointerId) {
11961202
// Try to find another pointer that's still holding on to the captured view.
11971203
int newActivePointer = INVALID_POINTER;
1198-
final int pointerCount = MotionEventCompat.getPointerCount(ev);
1204+
final int pointerCount = ev.getPointerCount();
11991205
for (int i = 0; i < pointerCount; i++) {
1200-
final int id = MotionEventCompat.getPointerId(ev, i);
1206+
final int id = ev.getPointerId(i);
12011207
if (id == mActivePointerId) {
12021208
// This one's going away, skip.
12031209
continue;
12041210
}
12051211

1206-
final float x = MotionEventCompat.getX(ev, i);
1207-
final float y = MotionEventCompat.getY(ev, i);
1212+
final float x = ev.getX(i);
1213+
final float y = ev.getY(i);
12081214
if (findTopChildUnder((int) x, (int) y) == mCapturedView &&
12091215
tryCaptureViewForDrag(mCapturedView, id)) {
12101216
newActivePointer = mActivePointerId;

0 commit comments

Comments
 (0)