diff options
-rw-r--r-- | platform/android/AndroidManifest.xml | 2 | ||||
-rw-r--r-- | platform/android/project.properties | 2 | ||||
-rw-r--r-- | platform/android/src/com/artifex/mupdfdemo/ReaderView.java | 20 | ||||
-rw-r--r-- | platform/android/src/com/artifex/mupdfdemo/Stepper.java | 42 |
4 files changed, 56 insertions, 10 deletions
diff --git a/platform/android/AndroidManifest.xml b/platform/android/AndroidManifest.xml index 040663e4..91875e87 100644 --- a/platform/android/AndroidManifest.xml +++ b/platform/android/AndroidManifest.xml @@ -11,7 +11,7 @@ android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" /> - <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="11"/> + <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/> <application android:label="@string/app_name" android:icon="@drawable/icon" diff --git a/platform/android/project.properties b/platform/android/project.properties index d79abae1..895c9ce2 100644 --- a/platform/android/project.properties +++ b/platform/android/project.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-11 +target=android-16 diff --git a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java index fe183945..c2093534 100644 --- a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java +++ b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java @@ -53,6 +53,7 @@ public class ReaderView private final ScaleGestureDetector mScaleGestureDetector; private final Scroller mScroller; + private final Stepper mStepper; private int mScrollerLastX; private int mScrollerLastY; private boolean mScrollDisabled; @@ -66,6 +67,7 @@ public class ReaderView mGestureDetector = new GestureDetector(this); mScaleGestureDetector = new ScaleGestureDetector(context, this); mScroller = new Scroller(context); + mStepper = new Stepper(this, this); } public ReaderView(Context context, AttributeSet attrs) { @@ -73,6 +75,7 @@ public class ReaderView mGestureDetector = new GestureDetector(this); mScaleGestureDetector = new ScaleGestureDetector(context, this); mScroller = new Scroller(context); + mStepper = new Stepper(this, this); } public ReaderView(Context context, AttributeSet attrs, int defStyle) { @@ -80,6 +83,7 @@ public class ReaderView mGestureDetector = new GestureDetector(this); mScaleGestureDetector = new ScaleGestureDetector(context, this); mScroller = new Scroller(context); + mStepper = new Stepper(this, this); } public int getDisplayedViewIndex() { @@ -203,7 +207,7 @@ public class ReaderView } mScrollerLastX = mScrollerLastY = 0; mScroller.startScroll(0, 0, remainingX - xOffset, remainingY - yOffset, 400); - post(this); + mStepper.prod(); } public void smartMoveBackwards() { @@ -275,7 +279,7 @@ public class ReaderView } mScrollerLastX = mScrollerLastY = 0; mScroller.startScroll(0, 0, remainingX - xOffset, remainingY - yOffset, 400); - post(this); + mStepper.prod(); } public void resetupChildren() { @@ -331,7 +335,7 @@ public class ReaderView mScrollerLastX = x; mScrollerLastY = y; requestLayout(); - post(this); + mStepper.prod(); } else if (!mUserInteracting) { // End of an inertial scroll and the user is not interacting. @@ -395,7 +399,7 @@ public class ReaderView if(withinBoundsInDirectionOfTravel(bounds, velocityX, velocityY) && expandedBounds.contains(0, 0)) { mScroller.fling(0, 0, (int)velocityX, (int)velocityY, bounds.left, bounds.right, bounds.top, bounds.bottom); - post(this); + mStepper.prod(); } } @@ -536,7 +540,7 @@ public class ReaderView postUnsettle(cv); // post to invoke test for end of animation // where we must set hq area for the new current view - post(this); + mStepper.prod(); onMoveOffChild(mCurrent); mCurrent++; @@ -547,7 +551,7 @@ public class ReaderView postUnsettle(cv); // post to invoke test for end of animation // where we must set hq area for the new current view - post(this); + mStepper.prod(); onMoveOffChild(mCurrent); mCurrent--; @@ -592,7 +596,7 @@ public class ReaderView } // post to ensure generation of hq area - post(this); + mStepper.prod(); } // Ensure current view is present @@ -777,7 +781,7 @@ public class ReaderView if (corr.x != 0 || corr.y != 0) { mScrollerLastX = mScrollerLastY = 0; mScroller.startScroll(0, 0, corr.x, corr.y, 400); - post(this); + mStepper.prod(); } } diff --git a/platform/android/src/com/artifex/mupdfdemo/Stepper.java b/platform/android/src/com/artifex/mupdfdemo/Stepper.java new file mode 100644 index 00000000..d22240ef --- /dev/null +++ b/platform/android/src/com/artifex/mupdfdemo/Stepper.java @@ -0,0 +1,42 @@ +package com.artifex.mupdfdemo; + +import android.annotation.SuppressLint; +import android.os.Build; +import android.view.View; + +public class Stepper { + protected final View mPoster; + protected final Runnable mTask; + protected boolean mPending; + + public Stepper(View v, Runnable r) { + mPoster = v; + mTask = r; + mPending = false; + } + + @SuppressLint("NewApi") + public void prod() { + if (!mPending) { + mPending = true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + mPoster.postOnAnimation(new Runnable() { + @Override + public void run() { + mPending = false; + mTask.run(); + } + }); + } else { + mPoster.post(new Runnable() { + @Override + public void run() { + mPending = false; + mTask.run(); + } + }); + + } + } + } +} |