diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-01-24 17:32:56 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-01-25 18:18:42 +0000 |
commit | e6f5e24b5d145cb571f82b2e01178be4c3eff662 (patch) | |
tree | 90d20c8343ad0b8bf9d0a5d4da04c205c0caa73a /android | |
parent | 211435a9daaf0ee29bbd6356913e95584b1b4371 (diff) | |
download | mupdf-e6f5e24b5d145cb571f82b2e01178be4c3eff662.tar.xz |
Android: Refine Smart Motion to avoid tiny scrolls at end of pages
Tor observes that when advancing down a page, it's annoying to have a
tiny scroll at the end to expose the last pixel. To avoid this, he
suggests making the amount we scroll dynamic; rather than always
moving by 90% of the screen height, we allow ourselves to move between
80% and 95% of the screen height if it means that we'll exactly meet
the end of the page.
This seems to work well.
Diffstat (limited to 'android')
-rw-r--r-- | android/src/com/artifex/mupdfdemo/ReaderView.java | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/android/src/com/artifex/mupdfdemo/ReaderView.java b/android/src/com/artifex/mupdfdemo/ReaderView.java index 4d84d03b..1ef8db70 100644 --- a/android/src/com/artifex/mupdfdemo/ReaderView.java +++ b/android/src/com/artifex/mupdfdemo/ReaderView.java @@ -105,6 +105,31 @@ public class ReaderView extends AdapterView<Adapter> slideViewOntoScreen(v); } + // When advancing down the page, we want to advance by about + // 90% of a screenful. But we'd be happy to advance by between + // 80% and 95% if it means we hit the bottom in a whole number + // of steps. + private int smartAdvanceAmount(int screenHeight, int max) { + int advance = (int)(screenHeight * 0.9 + 0.5); + int leftOver = max % advance; + int steps = max / advance; + if (leftOver == 0) { + // We'll make it exactly. No adjustment + } else if ((float)leftOver / steps <= screenHeight * 0.05) { + // We can adjust up by less than 5% to make it exact. + advance += (int)((float)leftOver/steps + 0.5); + } else { + int overshoot = advance - leftOver; + if ((float)overshoot / steps <= screenHeight * 0.1) { + // We can adjust down by less than 10% to make it exact. + advance -= (int)((float)overshoot/steps + 0.5); + } + } + if (advance > max) + advance = max; + return advance; + } + public void smartMoveForwards() { View v = mChildViews.get(mCurrent); if (v == null) @@ -171,9 +196,7 @@ public class ReaderView extends AdapterView<Adapter> } else { // Advance by 90% of the screen height downwards (in case lines are partially cut off) xOffset = 0; - yOffset = (int)(screenHeight * 0.9 + 0.5); - if (yOffset + bottom > docHeight) - yOffset = docHeight - bottom; + yOffset = smartAdvanceAmount(screenHeight, docHeight - bottom); } mScrollerLastX = mScrollerLastY = 0; mScroller.startScroll(0, 0, remainingX - xOffset, remainingY - yOffset, 400); @@ -246,9 +269,7 @@ public class ReaderView extends AdapterView<Adapter> } else { // Retreat by 90% of the screen height downwards (in case lines are partially cut off) xOffset = 0; - yOffset = - (int)(screenHeight * 0.9 + 0.5); - if (yOffset < -top) - yOffset = -top; + yOffset = -smartAdvanceAmount(screenHeight, top); } mScrollerLastX = mScrollerLastY = 0; mScroller.startScroll(0, 0, remainingX - xOffset, remainingY - yOffset, 400); |