summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorFred Ross-Perry <fred.ross-perry@artifex.com>2016-10-28 14:34:54 -0700
committerFred Ross-Perry <fred.ross-perry@artifex.com>2016-11-15 12:31:08 -0800
commit3416574cc5b1469d79b69da1f53ce686ad78b62c (patch)
tree58a55ffca61bda3b897dd19c7bac794e9b45de33 /platform
parent4ba8685340b5b54f3716d429b7bf35490f137e78 (diff)
downloadmupdf-3416574cc5b1469d79b69da1f53ce686ad78b62c.tar.xz
Android example - smoother flinging
scale the fling distance and time to the fling velocity. fling farther and for longer when the velocity is higher.
Diffstat (limited to 'platform')
-rwxr-xr-xplatform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java49
1 files changed, 19 insertions, 30 deletions
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<MIN_FLING_VELOCITY)
return false;
- // what direction?
- int direction = directionOfTravel(velocityX, velocityY);
-
mFlingStartTime = System.currentTimeMillis();
- switch (direction)
- {
- case MOVING_DOWN:
- smoothScrollBy(0, getHeight() / 2);
- break;
-
- case MOVING_UP:
- smoothScrollBy(0, -getHeight() / 2);
- break;
+ // adjust the distance and the time based on fling velocity
+ float ratio =(Math.abs(velocityY)-MIN_FLING_VELOCITY)/(MAX_FLING_VELOCITY-MIN_FLING_VELOCITY);
+ float dy = getHeight()*MIN_FLING_FACTOR + ratio*getHeight()*(MAX_FLING_FACTOR-MIN_FLING_FACTOR);
+ float dt = MIN_FLING_TIME + ratio*(MAX_FLING_TIME-MIN_FLING_TIME);
- default:
- break;
- }
+ if (velocityY<0)
+ smoothScrollBy(0, -(int)dy, (int)dt);
+ else
+ smoothScrollBy(0, (int)dy, (int)dt);
return true;
}
@@ -249,16 +248,6 @@ public class DocViewBase
mScale = val;
}
- private static int directionOfTravel(float vx, float vy)
- {
- if (Math.abs(vx) > 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)
{
}