From 55555a3dab1f3b99a3299b90851624e9dc10f3cc Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Fri, 24 Apr 2015 11:47:27 -0400 Subject: Fixes rejected dismiss gestures (framework version of ag/677161) Gus's original change description: This change modifies the logic in SwipeDismissLayout which determines whether or not a gesture should be interpreted as a dismiss gesture. Previously, on the first touch move event, the gesture was classified as a dismiss gesture if the X movement exceeded the touch slop and the Y movement did not. At this point the gesture was not intercepted and the underlying widget (in the case of the cue card, the GridViewPager) received all subsequent move events. In the case of a very fast gesture at a slight vertical angle, it was easy for the total Y movement to exceed the touch slop. This change only rejects the gesture if the Y movement exceeds the X movement, which is consistent with how GridViewPager distinguishes horizontal vs. vertical swipes. This change also cancels the dismissal if the end of the gesture is a leftwards flight. BUG: 20542762 (Same as b/20350515 but for Activity dismissal at the system level.) Change-Id: I6e3fb646c42dda0d1c1f5552d91b27c6374fc08c --- .../java/com/android/internal/widget/SwipeDismissLayout.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'core/java') diff --git a/core/java/com/android/internal/widget/SwipeDismissLayout.java b/core/java/com/android/internal/widget/SwipeDismissLayout.java index 89990c2..191662c 100644 --- a/core/java/com/android/internal/widget/SwipeDismissLayout.java +++ b/core/java/com/android/internal/widget/SwipeDismissLayout.java @@ -111,7 +111,7 @@ public class SwipeDismissLayout extends FrameLayout { } private void init(Context context) { - ViewConfiguration vc = ViewConfiguration.get(getContext()); + ViewConfiguration vc = ViewConfiguration.get(context); mSlop = vc.getScaledTouchSlop(); mMinFlingVelocity = vc.getScaledMinimumFlingVelocity(); mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); @@ -290,7 +290,7 @@ public class SwipeDismissLayout extends FrameLayout { float deltaX = ev.getRawX() - mDownX; float deltaY = ev.getRawY() - mDownY; if ((deltaX * deltaX) + (deltaY * deltaY) > mSlop * mSlop) { - mSwiping = deltaX > mSlop * 2 && Math.abs(deltaY) < mSlop * 2; + mSwiping = deltaX > mSlop * 2 && Math.abs(deltaY) < Math.abs(deltaX); } else { mSwiping = false; } @@ -299,9 +299,9 @@ public class SwipeDismissLayout extends FrameLayout { private void updateDismiss(MotionEvent ev) { float deltaX = ev.getRawX() - mDownX; + mVelocityTracker.addMovement(ev); + mVelocityTracker.computeCurrentVelocity(1000); if (!mDismissed) { - mVelocityTracker.addMovement(ev); - mVelocityTracker.computeCurrentVelocity(1000); if (deltaX > (getWidth() * DISMISS_MIN_DRAG_WIDTH_RATIO) && ev.getRawX() >= mLastX) { @@ -311,7 +311,9 @@ public class SwipeDismissLayout extends FrameLayout { // Check if the user tried to undo this. if (mDismissed && mSwiping) { // Check if the user's finger is actually back - if (deltaX < (getWidth() * DISMISS_MIN_DRAG_WIDTH_RATIO)) { + if (deltaX < (getWidth() * DISMISS_MIN_DRAG_WIDTH_RATIO) || + // or user is flinging back left + mVelocityTracker.getXVelocity() < -mMinFlingVelocity) { mDismissed = false; } } -- cgit v1.1