Snap workspace back to screen on ACTION_CANCEL.

Bug: 3066123
Change-Id: Icbdf3ef241ec44b5569e7490c1b950d80699ddc8
This commit is contained in:
Jeff Brown
2010-10-08 22:53:33 -07:00
parent 1a1c76e69a
commit 0db354cba9
+24 -19
View File
@@ -653,10 +653,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
return true; return true;
} }
if (mVelocityTracker == null) { acquireVelocityTrackerAndAddMovement(ev);
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(ev);
switch (action & MotionEvent.ACTION_MASK) { switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_MOVE: { case MotionEvent.ACTION_MOVE: {
@@ -741,12 +738,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
mTouchState = TOUCH_STATE_REST; mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER; mActivePointerId = INVALID_POINTER;
mAllowLongPress = false; mAllowLongPress = false;
releaseVelocityTracker();
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
break; break;
case MotionEvent.ACTION_POINTER_UP: 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. return false; // We don't want the events. Let them fall through to the all apps view.
} }
if (mVelocityTracker == null) { acquireVelocityTrackerAndAddMovement(ev);
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(ev);
final int action = ev.getAction(); final int action = ev.getAction();
@@ -922,18 +911,20 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
} else { } else {
snapToScreen(whichScreen, 0, true); snapToScreen(whichScreen, 0, true);
} }
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
} }
mTouchState = TOUCH_STATE_REST; mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER; mActivePointerId = INVALID_POINTER;
releaseVelocityTracker();
break; break;
case MotionEvent.ACTION_CANCEL: 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; mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER; mActivePointerId = INVALID_POINTER;
releaseVelocityTracker();
break; break;
case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_UP:
onSecondaryPointerUp(ev); onSecondaryPointerUp(ev);
@@ -943,6 +934,20 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
return true; 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) { void snapToScreen(int whichScreen) {
snapToScreen(whichScreen, 0, false); snapToScreen(whichScreen, 0, false);
} }