diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-10-08 22:53:33 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2010-10-08 22:53:33 -0700 |
commit | 0db354cba9c29ea7bd5b736ae05f625a6acf8c88 (patch) | |
tree | 74583ab7a397e930fc86c20ae427363e2e2dc6a0 /src/com | |
parent | 1a1c76e69ab43b8519e94cc6dc0c1165c03873d9 (diff) | |
download | packages_apps_trebuchet-0db354cba9c29ea7bd5b736ae05f625a6acf8c88.zip packages_apps_trebuchet-0db354cba9c29ea7bd5b736ae05f625a6acf8c88.tar.gz packages_apps_trebuchet-0db354cba9c29ea7bd5b736ae05f625a6acf8c88.tar.bz2 |
Snap workspace back to screen on ACTION_CANCEL.
Bug: 3066123
Change-Id: Icbdf3ef241ec44b5569e7490c1b950d80699ddc8
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 7761cb3..c182209 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -653,10 +653,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag return true; } - if (mVelocityTracker == null) { - mVelocityTracker = VelocityTracker.obtain(); - } - mVelocityTracker.addMovement(ev); + acquireVelocityTrackerAndAddMovement(ev); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_MOVE: { @@ -741,12 +738,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; mAllowLongPress = false; - - if (mVelocityTracker != null) { - mVelocityTracker.recycle(); - mVelocityTracker = null; - } - + releaseVelocityTracker(); break; case MotionEvent.ACTION_POINTER_UP: @@ -846,10 +838,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag return false; // We don't want the events. Let them fall through to the all apps view. } - if (mVelocityTracker == null) { - mVelocityTracker = VelocityTracker.obtain(); - } - mVelocityTracker.addMovement(ev); + acquireVelocityTrackerAndAddMovement(ev); final int action = ev.getAction(); @@ -922,18 +911,20 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag } else { snapToScreen(whichScreen, 0, true); } - - if (mVelocityTracker != null) { - mVelocityTracker.recycle(); - mVelocityTracker = null; - } } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; + releaseVelocityTracker(); break; case MotionEvent.ACTION_CANCEL: + if (mTouchState == TOUCH_STATE_SCROLLING) { + final int screenWidth = getWidth(); + final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth; + snapToScreen(whichScreen, 0, true); + } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; + releaseVelocityTracker(); break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); @@ -943,6 +934,20 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag 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; + } + } + void snapToScreen(int whichScreen) { snapToScreen(whichScreen, 0, false); } |