diff options
| author | 2014-03-12 19:57:14 +0000 | |
|---|---|---|
| committer | 2014-03-12 19:57:14 +0000 | |
| commit | c8dbd29fc9b22ab0715dbe6181d53b24fa366332 (patch) | |
| tree | e6a7bc6ed1e8776aa2b563ac73b5b28de22fdb73 | |
| parent | b552362bbc9001274f4022d8a494de6129f2723b (diff) | |
| parent | c65caed6dabe9eed3551c412427df81cd881496a (diff) | |
am c65caed6: am c48701a1: am 641d8aff: Merge "Fix possible invalid pointer index in swipe dismiss." into klp-modular-dev
* commit 'c65caed6dabe9eed3551c412427df81cd881496a':
Fix possible invalid pointer index in swipe dismiss.
| -rw-r--r-- | core/java/com/android/internal/widget/SwipeDismissLayout.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/core/java/com/android/internal/widget/SwipeDismissLayout.java b/core/java/com/android/internal/widget/SwipeDismissLayout.java index cc8ce2c9e304..467d42e1d326 100644 --- a/core/java/com/android/internal/widget/SwipeDismissLayout.java +++ b/core/java/com/android/internal/widget/SwipeDismissLayout.java @@ -126,6 +126,20 @@ public class SwipeDismissLayout extends FrameLayout { mVelocityTracker.addMovement(ev); break; + case MotionEvent.ACTION_POINTER_DOWN: + int actionIndex = ev.getActionIndex(); + mActiveTouchId = ev.getPointerId(actionIndex); + break; + case MotionEvent.ACTION_POINTER_UP: + actionIndex = ev.getActionIndex(); + int pointerId = ev.getPointerId(actionIndex); + if (pointerId == mActiveTouchId) { + // This was our active pointer going up. Choose a new active pointer. + int newActionIndex = actionIndex == 0 ? 1 : 0; + mActiveTouchId = ev.getPointerId(newActionIndex); + } + break; + case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: resetMembers(); @@ -137,6 +151,11 @@ public class SwipeDismissLayout extends FrameLayout { } int pointerIndex = ev.findPointerIndex(mActiveTouchId); + if (pointerIndex == -1) { + Log.e(TAG, "Invalid pointer index: ignoring."); + mDiscardIntercept = true; + break; + } float dx = ev.getRawX() - mDownX; float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); @@ -228,11 +247,11 @@ public class SwipeDismissLayout extends FrameLayout { } private void updateDismiss(MotionEvent ev) { + float deltaX = ev.getRawX() - mDownX; if (!mDismissed) { mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); - float deltaX = ev.getRawX() - mDownX; float velocityX = mVelocityTracker.getXVelocity(); float absVelocityX = Math.abs(velocityX); float absVelocityY = Math.abs(mVelocityTracker.getYVelocity()); @@ -247,6 +266,13 @@ public class SwipeDismissLayout extends FrameLayout { mDismissed = true; } } + // Check if the user tried to undo this. + if (mDismissed && mSwiping) { + // Check if the user's finger is actually back + if (deltaX < getWidth() / 2) { + mDismissed = false; + } + } } /** |