diff options
author | Tony Wickham <twickham@google.com> | 2016-04-05 18:31:43 -0700 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2016-04-06 14:13:29 -0700 |
commit | 012734d7c40bcd14a4f9a93bae8639e4ea8b2cb0 (patch) | |
tree | c69e6ab88d3d45ea44d982c847a0eefce4b55610 /src/com/android/launcher3/PinchToOverviewListener.java | |
parent | b4c4dceb83e098392930a3daa934dfb8fbf55db8 (diff) | |
download | android_packages_apps_Trebuchet-012734d7c40bcd14a4f9a93bae8639e4ea8b2cb0.tar.gz android_packages_apps_Trebuchet-012734d7c40bcd14a4f9a93bae8639e4ea8b2cb0.tar.bz2 android_packages_apps_Trebuchet-012734d7c40bcd14a4f9a93bae8639e4ea8b2cb0.zip |
Add velocity threshold so that fast pinches (flings) are detected.
Bug: 27676309
Change-Id: Id3ba05c67abac8847fcff22532ea9da9ef10a5ae
Diffstat (limited to 'src/com/android/launcher3/PinchToOverviewListener.java')
-rw-r--r-- | src/com/android/launcher3/PinchToOverviewListener.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/com/android/launcher3/PinchToOverviewListener.java b/src/com/android/launcher3/PinchToOverviewListener.java index 74e6b39cd..f32c8455e 100644 --- a/src/com/android/launcher3/PinchToOverviewListener.java +++ b/src/com/android/launcher3/PinchToOverviewListener.java @@ -33,6 +33,11 @@ import android.view.ScaleGestureDetector; public class PinchToOverviewListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { private static final float OVERVIEW_PROGRESS = 0f; private static final float WORKSPACE_PROGRESS = 1f; + /** + * The velocity threshold at which a pinch will be completed instead of canceled, + * even if the first threshold has not been passed. Measured in progress / millisecond + */ + private static final float FLING_VELOCITY = 0.003f; private ScaleGestureDetector mPinchDetector; private Launcher mLauncher; @@ -110,17 +115,20 @@ public class PinchToOverviewListener extends ScaleGestureDetector.SimpleOnScaleG public void onScaleEnd(ScaleGestureDetector detector) { super.onScaleEnd(detector); + float progressVelocity = mProgressDelta / mTimeDelta; float passedThreshold = mThresholdManager.getPassedThreshold(); + boolean isFling = mWorkspace.isInOverviewMode() && progressVelocity >= FLING_VELOCITY + || !mWorkspace.isInOverviewMode() && progressVelocity <= -FLING_VELOCITY; + boolean shouldCancelPinch = !isFling && passedThreshold < PinchThresholdManager.THRESHOLD_ONE; // If we are going towards overview, mPreviousProgress is how much further we need to // go, since it is going from 1 to 0. If we are going to workspace, we want // 1 - mPreviousProgress. float remainingProgress = mPreviousProgress; - if (mWorkspace.isInOverviewMode() || passedThreshold < PinchThresholdManager.THRESHOLD_ONE) { + if (mWorkspace.isInOverviewMode() || shouldCancelPinch) { remainingProgress = 1f - mPreviousProgress; } - int duration = computeDuration(remainingProgress, mProgressDelta, mTimeDelta); - - if (passedThreshold < PinchThresholdManager.THRESHOLD_ONE) { + int duration = computeDuration(remainingProgress, progressVelocity); + if (shouldCancelPinch) { cancelPinch(mPreviousProgress, duration); } else if (passedThreshold < PinchThresholdManager.THRESHOLD_THREE) { float toProgress = mWorkspace.isInOverviewMode() ? @@ -138,8 +146,8 @@ public class PinchToOverviewListener extends ScaleGestureDetector.SimpleOnScaleG * Compute the amount of time required to complete the transition based on the current pinch * speed. If this time is too long, instead return the normal duration, ignoring the speed. */ - private int computeDuration(float remainingProgress, float progressDelta, long timeDelta) { - float progressSpeed = Math.abs(progressDelta) / timeDelta; + private int computeDuration(float remainingProgress, float progressVelocity) { + float progressSpeed = Math.abs(progressVelocity); int remainingMillis = (int) (remainingProgress / progressSpeed); return Math.min(remainingMillis, mAnimationManager.getNormalOverviewTransitionDuration()); } |