From 9cfd25f16739548111ba8fc6ba8cd83010eccef6 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Sun, 24 Oct 2010 16:09:28 -0700 Subject: [PATCH] Adding distance threshold to initiate paging regardless of velocity. Change-Id: I275417ca69bcaa0b643dab7f3f552d973a194ce6 --- src/com/android/launcher2/PagedView.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index 4ccc4aeab0..9739b156fd 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -53,7 +53,9 @@ public abstract class PagedView extends ViewGroup { protected static final int INVALID_PAGE = -1; // the min drag distance for a fling to register, to prevent random page shifts - private static final int MIN_LENGTH_FOR_FLING = 50; + private static final int MIN_LENGTH_FOR_FLING = 25; + // The min drag distance to trigger a page shift (regardless of velocity) + private static final int MIN_LENGTH_FOR_MOVE = 200; private static final int PAGE_SNAP_ANIMATION_DURATION = 1000; protected static final float NANOTIME_DIV = 1000000000.0f; @@ -836,12 +838,17 @@ public abstract class PagedView extends ViewGroup { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(activePointerId); - boolean isfling = Math.abs(mDownMotionX - x) > MIN_LENGTH_FOR_FLING; + final int deltaX = (int) (x - mDownMotionX); + boolean isfling = Math.abs(deltaX) > MIN_LENGTH_FOR_FLING; + boolean isSignificantMove = Math.abs(deltaX) > MIN_LENGTH_FOR_MOVE; final int snapVelocity = mSnapVelocity; - if (isfling && velocityX > snapVelocity && mCurrentPage > 0) { + if ((isSignificantMove && deltaX > 0 || + (isfling && velocityX > snapVelocity)) && + mCurrentPage > 0) { snapToPageWithVelocity(mCurrentPage - 1, velocityX); - } else if (isfling && velocityX < -snapVelocity && + } else if ((isSignificantMove && deltaX < 0 || + (isfling && velocityX < -snapVelocity)) && mCurrentPage < getChildCount() - 1) { snapToPageWithVelocity(mCurrentPage + 1, velocityX); } else {