From 3416574cc5b1469d79b69da1f53ce686ad78b62c Mon Sep 17 00:00:00 2001 From: Fred Ross-Perry Date: Fri, 28 Oct 2016 14:34:54 -0700 Subject: Android example - smoother flinging scale the fling distance and time to the fling velocity. fling farther and for longer when the velocity is higher. --- .../com/artifex/mupdf/android/DocViewBase.java | 49 +++++++++------------- 1 file changed, 19 insertions(+), 30 deletions(-) (limited to 'platform') diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java index 10cf78ca..4d35aa96 100755 --- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java +++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java @@ -68,8 +68,15 @@ public class DocViewBase private static final int MOVING_UP = 3; private static final int MOVING_DOWN = 4; - private static final float MIN_FLING_VELOCITY = 1500.0f; - private static final long FLING_THROTTLE_TIME = 20; + private static final float MIN_FLING_VELOCITY = 750.0f; + private static final float MAX_FLING_VELOCITY = 16000.0f; + private static final long FLING_THROTTLE_TIME = 10; + + private static final int MIN_FLING_TIME = 400; + private static final int MAX_FLING_TIME = 1000; + + private static final float MIN_FLING_FACTOR = 0.333f; + private static final float MAX_FLING_FACTOR = 1.0f; private Scroller mScroller; private Stepper mStepper; @@ -208,7 +215,6 @@ public class DocViewBase public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - // not while we're scaling if (mScaling) return true; @@ -218,28 +224,21 @@ public class DocViewBase return true; // must be really flinging - float vel = Math.max(Math.abs(velocityX), Math.abs(velocityY)); - if (vel < MIN_FLING_VELOCITY) + float vel = Math.max(Math.abs(velocityX),Math.abs(velocityY)); + if (vel 2 * Math.abs(vy)) - return (vx > 0) ? MOVING_RIGHT : MOVING_LEFT; - else if (Math.abs(vy) > 2 * Math.abs(vx)) - return (vy > 0) ? MOVING_DOWN : MOVING_UP; - else - return MOVING_DIAGONALLY; - } - public void onLongPress(MotionEvent e) { } -- cgit v1.2.3