Limit workspace flings to one screen at a time.
This prevents users from scrolling left slightly, flinging right, and scrolling by two screens as a result (and vice versa). Change-Id: I04c60438c022b24defcd8e4cbedf1c6b07c24423
This commit is contained in:
1 parent
8b5eef7d3f
commit
327a9a3a30
1 file changed
+10
-3
@@ -838,13 +838,20 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
|
||||
|
||||
final int screenWidth = getWidth();
|
||||
final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;
|
||||
final float scrolledPos = (float) mScrollX / screenWidth;
|
||||
|
||||
if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
|
||||
// Fling hard enough to move left
|
||||
snapToScreen(Math.min(whichScreen, mCurrentScreen - 1));
|
||||
// Fling hard enough to move left.
|
||||
// Don't fling across more than one screen at a time.
|
||||
final int bound = scrolledPos < whichScreen ?
|
||||
mCurrentScreen - 1 : mCurrentScreen;
|
||||
snapToScreen(Math.min(whichScreen, bound));
|
||||
} else if (velocityX < -SNAP_VELOCITY && mCurrentScreen < getChildCount() - 1) {
|
||||
// Fling hard enough to move right
|
||||
snapToScreen(Math.max(whichScreen, mCurrentScreen + 1));
|
||||
// Don't fling across more than one screen at a time.
|
||||
final int bound = scrolledPos > whichScreen ?
|
||||
mCurrentScreen + 1 : mCurrentScreen;
|
||||
snapToScreen(Math.max(whichScreen, bound));
|
||||
} else {
|
||||
snapToDestination();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user