Skip to content

Commit

Permalink
Merge pull request #17 from PeterCxy/master
Browse files Browse the repository at this point in the history
ViewDragHelper: allow only one edge to be touched by one finger
  • Loading branch information
Issacw0ng authored and Issacw0ng committed Feb 9, 2014
2 parents b8ffffb + 4af1413 commit bd50aaa
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public class ViewDragHelper {

private float[] mLastMotionY;

private int[] mInitialEdgesTouched;
private int[] mInitialEdgeTouched;

private int[] mEdgeDragsInProgress;

Expand Down Expand Up @@ -857,7 +857,7 @@ private void clearMotionHistory() {
Arrays.fill(mInitialMotionY, 0);
Arrays.fill(mLastMotionX, 0);
Arrays.fill(mLastMotionY, 0);
Arrays.fill(mInitialEdgesTouched, 0);
Arrays.fill(mInitialEdgeTouched, 0);
Arrays.fill(mEdgeDragsInProgress, 0);
Arrays.fill(mEdgeDragsLocked, 0);
mPointersDown = 0;
Expand All @@ -871,7 +871,7 @@ private void clearMotionHistory(int pointerId) {
mInitialMotionY[pointerId] = 0;
mLastMotionX[pointerId] = 0;
mLastMotionY[pointerId] = 0;
mInitialEdgesTouched[pointerId] = 0;
mInitialEdgeTouched[pointerId] = 0;
mEdgeDragsInProgress[pointerId] = 0;
mEdgeDragsLocked[pointerId] = 0;
mPointersDown &= ~(1 << pointerId);
Expand All @@ -892,7 +892,7 @@ private void ensureMotionHistorySizeForId(int pointerId) {
System.arraycopy(mInitialMotionY, 0, imy, 0, mInitialMotionY.length);
System.arraycopy(mLastMotionX, 0, lmx, 0, mLastMotionX.length);
System.arraycopy(mLastMotionY, 0, lmy, 0, mLastMotionY.length);
System.arraycopy(mInitialEdgesTouched, 0, iit, 0, mInitialEdgesTouched.length);
System.arraycopy(mInitialEdgeTouched, 0, iit, 0, mInitialEdgeTouched.length);
System.arraycopy(mEdgeDragsInProgress, 0, edip, 0, mEdgeDragsInProgress.length);
System.arraycopy(mEdgeDragsLocked, 0, edl, 0, mEdgeDragsLocked.length);
}
Expand All @@ -901,7 +901,7 @@ private void ensureMotionHistorySizeForId(int pointerId) {
mInitialMotionY = imy;
mLastMotionX = lmx;
mLastMotionY = lmy;
mInitialEdgesTouched = iit;
mInitialEdgeTouched = iit;
mEdgeDragsInProgress = edip;
mEdgeDragsLocked = edl;
}
Expand All @@ -911,7 +911,7 @@ private void saveInitialMotion(float x, float y, int pointerId) {
ensureMotionHistorySizeForId(pointerId);
mInitialMotionX[pointerId] = mLastMotionX[pointerId] = x;
mInitialMotionY[pointerId] = mLastMotionY[pointerId] = y;
mInitialEdgesTouched[pointerId] = getEdgesTouched((int) x, (int) y);
mInitialEdgeTouched[pointerId] = getEdgeTouched((int) x, (int) y);
mPointersDown |= 1 << pointerId;
}

Expand Down Expand Up @@ -1056,7 +1056,7 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
tryCaptureViewForDrag(toCapture, pointerId);
}

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

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

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

final int edgesTouched = mInitialEdgesTouched[pointerId];
final int edgesTouched = mInitialEdgeTouched[pointerId];
if ((edgesTouched & mTrackingEdges) != 0) {
mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId);
}
Expand Down Expand Up @@ -1319,7 +1319,7 @@ private boolean checkNewEdgeDrag(float delta, float odelta, int pointerId, int e
final float absDelta = Math.abs(delta);
final float absODelta = Math.abs(odelta);

if ((mInitialEdgesTouched[pointerId] & edge) != edge || (mTrackingEdges & edge) == 0
if ((mInitialEdgeTouched[pointerId] & edge) != edge || (mTrackingEdges & edge) == 0
|| (mEdgeDragsLocked[pointerId] & edge) == edge
|| (mEdgeDragsInProgress[pointerId] & edge) == edge
|| (absDelta <= mTouchSlop && absODelta <= mTouchSlop)) {
Expand Down Expand Up @@ -1436,7 +1436,7 @@ public boolean checkTouchSlop(int directions, int pointerId) {
* current gesture
*/
public boolean isEdgeTouched(int edges) {
final int count = mInitialEdgesTouched.length;
final int count = mInitialEdgeTouched.length;
for (int i = 0; i < count; i++) {
if (isEdgeTouched(edges, i)) {
return true;
Expand All @@ -1458,7 +1458,7 @@ public boolean isEdgeTouched(int edges) {
* current gesture
*/
public boolean isEdgeTouched(int edges, int pointerId) {
return isPointerDown(pointerId) && (mInitialEdgesTouched[pointerId] & edges) != 0;
return isPointerDown(pointerId) && (mInitialEdgeTouched[pointerId] & edges) != 0;
}

private void releaseViewForPointerUp() {
Expand Down Expand Up @@ -1548,17 +1548,17 @@ public View findTopChildUnder(int x, int y) {
return null;
}

private int getEdgesTouched(int x, int y) {
private int getEdgeTouched(int x, int y) {
int result = 0;

if (x < mParentView.getLeft() + mEdgeSize)
result |= EDGE_LEFT;
result = EDGE_LEFT;
if (y < mParentView.getTop() + mEdgeSize)
result |= EDGE_TOP;
result = EDGE_TOP;
if (x > mParentView.getRight() - mEdgeSize)
result |= EDGE_RIGHT;
result = EDGE_RIGHT;
if (y > mParentView.getBottom() - mEdgeSize)
result |= EDGE_BOTTOM;
result = EDGE_BOTTOM;

return result;
}
Expand Down

0 comments on commit bd50aaa

Please sign in to comment.