am c48701a1: am 641d8aff: Merge "Fix possible invalid pointer index in swipe dismiss." into klp-modular-dev

* commit 'c48701a134d3ba05e35d94da921abe1120b67185':
  Fix possible invalid pointer index in swipe dismiss.
This commit is contained in:
Justin Koh
2014-03-12 00:49:44 +00:00
committed by Android Git Automerger

View File

@ -126,6 +126,20 @@ public class SwipeDismissLayout extends FrameLayout {
mVelocityTracker.addMovement(ev); mVelocityTracker.addMovement(ev);
break; 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_CANCEL:
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
resetMembers(); resetMembers();
@ -137,6 +151,11 @@ public class SwipeDismissLayout extends FrameLayout {
} }
int pointerIndex = ev.findPointerIndex(mActiveTouchId); int pointerIndex = ev.findPointerIndex(mActiveTouchId);
if (pointerIndex == -1) {
Log.e(TAG, "Invalid pointer index: ignoring.");
mDiscardIntercept = true;
break;
}
float dx = ev.getRawX() - mDownX; float dx = ev.getRawX() - mDownX;
float x = ev.getX(pointerIndex); float x = ev.getX(pointerIndex);
float y = ev.getY(pointerIndex); float y = ev.getY(pointerIndex);
@ -228,11 +247,11 @@ public class SwipeDismissLayout extends FrameLayout {
} }
private void updateDismiss(MotionEvent ev) { private void updateDismiss(MotionEvent ev) {
float deltaX = ev.getRawX() - mDownX;
if (!mDismissed) { if (!mDismissed) {
mVelocityTracker.addMovement(ev); mVelocityTracker.addMovement(ev);
mVelocityTracker.computeCurrentVelocity(1000); mVelocityTracker.computeCurrentVelocity(1000);
float deltaX = ev.getRawX() - mDownX;
float velocityX = mVelocityTracker.getXVelocity(); float velocityX = mVelocityTracker.getXVelocity();
float absVelocityX = Math.abs(velocityX); float absVelocityX = Math.abs(velocityX);
float absVelocityY = Math.abs(mVelocityTracker.getYVelocity()); float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
@ -247,6 +266,13 @@ public class SwipeDismissLayout extends FrameLayout {
mDismissed = true; 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;
}
}
} }
/** /**