Snap workspace back to screen on ACTION_CANCEL.
Bug: 3066123
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 2a96736..8332053 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -747,10 +747,7 @@
@Override
public boolean onTouchEvent(MotionEvent ev) {
- if (mVelocityTracker == null) {
- mVelocityTracker = VelocityTracker.obtain();
- }
- mVelocityTracker.addMovement(ev);
+ acquireVelocityTrackerAndAddMovement(ev);
final int action = ev.getAction();
@@ -834,11 +831,6 @@
} else {
snapToDestination();
}
-
- if (mVelocityTracker != null) {
- mVelocityTracker.recycle();
- mVelocityTracker = null;
- }
} else if (mTouchState == TOUCH_STATE_PREV_PAGE && !handlePagingClicks()) {
// at this point we have not moved beyond the touch slop
// (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
@@ -862,11 +854,16 @@
}
mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER;
+ releaseVelocityTracker();
break;
case MotionEvent.ACTION_CANCEL:
+ if (mTouchState == TOUCH_STATE_SCROLLING) {
+ snapToDestination();
+ }
mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER;
+ releaseVelocityTracker();
break;
case MotionEvent.ACTION_POINTER_UP:
@@ -877,6 +874,20 @@
return true;
}
+ private void acquireVelocityTrackerAndAddMovement(MotionEvent ev) {
+ if (mVelocityTracker == null) {
+ mVelocityTracker = VelocityTracker.obtain();
+ }
+ mVelocityTracker.addMovement(ev);
+ }
+
+ private void releaseVelocityTracker() {
+ if (mVelocityTracker != null) {
+ mVelocityTracker.recycle();
+ mVelocityTracker = null;
+ }
+ }
+
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
MotionEvent.ACTION_POINTER_INDEX_SHIFT;