Skip to content

Commit 4af1413

Browse files
author
PeterCxy
committed
ViewDragHelper: allow only one edge to be touched by one finger
this fixes the bug when drag a corner of the view, without this you're going to see the view being draged to a different direction from which is set by class SwipeBackLayout
1 parent b8ffffb commit 4af1413

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

library/src/main/java/me/imid/swipebacklayout/lib/ViewDragHelper.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class ViewDragHelper {
120120

121121
private float[] mLastMotionY;
122122

123-
private int[] mInitialEdgesTouched;
123+
private int[] mInitialEdgeTouched;
124124

125125
private int[] mEdgeDragsInProgress;
126126

@@ -857,7 +857,7 @@ private void clearMotionHistory() {
857857
Arrays.fill(mInitialMotionY, 0);
858858
Arrays.fill(mLastMotionX, 0);
859859
Arrays.fill(mLastMotionY, 0);
860-
Arrays.fill(mInitialEdgesTouched, 0);
860+
Arrays.fill(mInitialEdgeTouched, 0);
861861
Arrays.fill(mEdgeDragsInProgress, 0);
862862
Arrays.fill(mEdgeDragsLocked, 0);
863863
mPointersDown = 0;
@@ -871,7 +871,7 @@ private void clearMotionHistory(int pointerId) {
871871
mInitialMotionY[pointerId] = 0;
872872
mLastMotionX[pointerId] = 0;
873873
mLastMotionY[pointerId] = 0;
874-
mInitialEdgesTouched[pointerId] = 0;
874+
mInitialEdgeTouched[pointerId] = 0;
875875
mEdgeDragsInProgress[pointerId] = 0;
876876
mEdgeDragsLocked[pointerId] = 0;
877877
mPointersDown &= ~(1 << pointerId);
@@ -892,7 +892,7 @@ private void ensureMotionHistorySizeForId(int pointerId) {
892892
System.arraycopy(mInitialMotionY, 0, imy, 0, mInitialMotionY.length);
893893
System.arraycopy(mLastMotionX, 0, lmx, 0, mLastMotionX.length);
894894
System.arraycopy(mLastMotionY, 0, lmy, 0, mLastMotionY.length);
895-
System.arraycopy(mInitialEdgesTouched, 0, iit, 0, mInitialEdgesTouched.length);
895+
System.arraycopy(mInitialEdgeTouched, 0, iit, 0, mInitialEdgeTouched.length);
896896
System.arraycopy(mEdgeDragsInProgress, 0, edip, 0, mEdgeDragsInProgress.length);
897897
System.arraycopy(mEdgeDragsLocked, 0, edl, 0, mEdgeDragsLocked.length);
898898
}
@@ -901,7 +901,7 @@ private void ensureMotionHistorySizeForId(int pointerId) {
901901
mInitialMotionY = imy;
902902
mLastMotionX = lmx;
903903
mLastMotionY = lmy;
904-
mInitialEdgesTouched = iit;
904+
mInitialEdgeTouched = iit;
905905
mEdgeDragsInProgress = edip;
906906
mEdgeDragsLocked = edl;
907907
}
@@ -911,7 +911,7 @@ private void saveInitialMotion(float x, float y, int pointerId) {
911911
ensureMotionHistorySizeForId(pointerId);
912912
mInitialMotionX[pointerId] = mLastMotionX[pointerId] = x;
913913
mInitialMotionY[pointerId] = mLastMotionY[pointerId] = y;
914-
mInitialEdgesTouched[pointerId] = getEdgesTouched((int) x, (int) y);
914+
mInitialEdgeTouched[pointerId] = getEdgeTouched((int) x, (int) y);
915915
mPointersDown |= 1 << pointerId;
916916
}
917917

@@ -1056,7 +1056,7 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
10561056
tryCaptureViewForDrag(toCapture, pointerId);
10571057
}
10581058

1059-
final int edgesTouched = mInitialEdgesTouched[pointerId];
1059+
final int edgesTouched = mInitialEdgeTouched[pointerId];
10601060
if ((edgesTouched & mTrackingEdges) != 0) {
10611061
mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId);
10621062
}
@@ -1072,7 +1072,7 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
10721072

10731073
// A ViewDragHelper can only manipulate one view at a time.
10741074
if (mDragState == STATE_IDLE) {
1075-
final int edgesTouched = mInitialEdgesTouched[pointerId];
1075+
final int edgesTouched = mInitialEdgeTouched[pointerId];
10761076
if ((edgesTouched & mTrackingEdges) != 0) {
10771077
mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId);
10781078
}
@@ -1166,7 +1166,7 @@ public void processTouchEvent(MotionEvent ev) {
11661166
// Start immediately if possible.
11671167
tryCaptureViewForDrag(toCapture, pointerId);
11681168

1169-
final int edgesTouched = mInitialEdgesTouched[pointerId];
1169+
final int edgesTouched = mInitialEdgeTouched[pointerId];
11701170
if ((edgesTouched & mTrackingEdges) != 0) {
11711171
mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId);
11721172
}
@@ -1188,7 +1188,7 @@ public void processTouchEvent(MotionEvent ev) {
11881188
final View toCapture = findTopChildUnder((int) x, (int) y);
11891189
tryCaptureViewForDrag(toCapture, pointerId);
11901190

1191-
final int edgesTouched = mInitialEdgesTouched[pointerId];
1191+
final int edgesTouched = mInitialEdgeTouched[pointerId];
11921192
if ((edgesTouched & mTrackingEdges) != 0) {
11931193
mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId);
11941194
}
@@ -1319,7 +1319,7 @@ private boolean checkNewEdgeDrag(float delta, float odelta, int pointerId, int e
13191319
final float absDelta = Math.abs(delta);
13201320
final float absODelta = Math.abs(odelta);
13211321

1322-
if ((mInitialEdgesTouched[pointerId] & edge) != edge || (mTrackingEdges & edge) == 0
1322+
if ((mInitialEdgeTouched[pointerId] & edge) != edge || (mTrackingEdges & edge) == 0
13231323
|| (mEdgeDragsLocked[pointerId] & edge) == edge
13241324
|| (mEdgeDragsInProgress[pointerId] & edge) == edge
13251325
|| (absDelta <= mTouchSlop && absODelta <= mTouchSlop)) {
@@ -1436,7 +1436,7 @@ public boolean checkTouchSlop(int directions, int pointerId) {
14361436
* current gesture
14371437
*/
14381438
public boolean isEdgeTouched(int edges) {
1439-
final int count = mInitialEdgesTouched.length;
1439+
final int count = mInitialEdgeTouched.length;
14401440
for (int i = 0; i < count; i++) {
14411441
if (isEdgeTouched(edges, i)) {
14421442
return true;
@@ -1458,7 +1458,7 @@ public boolean isEdgeTouched(int edges) {
14581458
* current gesture
14591459
*/
14601460
public boolean isEdgeTouched(int edges, int pointerId) {
1461-
return isPointerDown(pointerId) && (mInitialEdgesTouched[pointerId] & edges) != 0;
1461+
return isPointerDown(pointerId) && (mInitialEdgeTouched[pointerId] & edges) != 0;
14621462
}
14631463

14641464
private void releaseViewForPointerUp() {
@@ -1548,17 +1548,17 @@ public View findTopChildUnder(int x, int y) {
15481548
return null;
15491549
}
15501550

1551-
private int getEdgesTouched(int x, int y) {
1551+
private int getEdgeTouched(int x, int y) {
15521552
int result = 0;
15531553

15541554
if (x < mParentView.getLeft() + mEdgeSize)
1555-
result |= EDGE_LEFT;
1555+
result = EDGE_LEFT;
15561556
if (y < mParentView.getTop() + mEdgeSize)
1557-
result |= EDGE_TOP;
1557+
result = EDGE_TOP;
15581558
if (x > mParentView.getRight() - mEdgeSize)
1559-
result |= EDGE_RIGHT;
1559+
result = EDGE_RIGHT;
15601560
if (y > mParentView.getBottom() - mEdgeSize)
1561-
result |= EDGE_BOTTOM;
1561+
result = EDGE_BOTTOM;
15621562

15631563
return result;
15641564
}

0 commit comments

Comments
 (0)