diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index 9015a4e4d..21c119f49 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -98,10 +98,10 @@ public final class FBView extends ZLTextView { return true; } - myReader.doAction(getZoneMap().getActionByCoordinates( + myReader.doActionWithCoordinates(getZoneMap().getActionByCoordinates( x, y, myContext.getWidth(), myContext.getHeight(), isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap - )); + ), x, y); return true; } @@ -116,9 +116,9 @@ public final class FBView extends ZLTextView { if (super.onFingerDoubleTap(x, y)) { return true; } - myReader.doAction(getZoneMap().getActionByCoordinates( + myReader.doActionWithCoordinates(getZoneMap().getActionByCoordinates( x, y, myContext.getWidth(), myContext.getHeight(), TapZoneMap.Tap.doubleTap - )); + ), x, y); return true; } diff --git a/src/org/geometerplus/fbreader/fbreader/TurnPageAction.java b/src/org/geometerplus/fbreader/fbreader/TurnPageAction.java index a08b8de12..da0b64e1e 100644 --- a/src/org/geometerplus/fbreader/fbreader/TurnPageAction.java +++ b/src/org/geometerplus/fbreader/fbreader/TurnPageAction.java @@ -68,4 +68,20 @@ class TurnPageAction extends FBAction { Reader.repaintView(); } } + + public void runWithCoordinates(int x, int y) { + final ScrollingPreferences preferences = ScrollingPreferences.Instance(); + final FBView view = Reader.getTextView(); + if (view.getAnimationType() != FBView.Animation.none) { + view.startAutoScrolling( + myForward ? FBView.PageIndex.next : FBView.PageIndex.previous, + preferences.HorizontalOption.getValue() + ? FBView.Direction.rightToLeft : FBView.Direction.up, + x, y + ); + } else { + view.scrollPage(myForward, FBView.ScrollingMode.NO_OVERLAPPING, 0); + Reader.repaintView(); + } + } } diff --git a/src/org/geometerplus/zlibrary/core/application/ZLApplication.java b/src/org/geometerplus/zlibrary/core/application/ZLApplication.java index db4828755..f3d7c1d52 100644 --- a/src/org/geometerplus/zlibrary/core/application/ZLApplication.java +++ b/src/org/geometerplus/zlibrary/core/application/ZLApplication.java @@ -86,6 +86,12 @@ public abstract class ZLApplication { } } + public final void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int x, int y) { + if (myWindow != null) { + myWindow.startViewAutoScrolling(pageIndex, direction, x, y); + } + } + public final void onRepaintFinished() { if (myWindow != null) { myWindow.refreshMenu(); @@ -120,6 +126,13 @@ public abstract class ZLApplication { } } + public final void doActionWithCoordinates(String actionId, int x, int y) { + final ZLAction action = myIdToActionMap.get(actionId); + if (action != null && action.isEnabled()) { + action.runWithCoordinates(x, y); + } + } + //may be protected abstract public ZLKeyBindings keyBindings(); @@ -182,6 +195,10 @@ public abstract class ZLApplication { } abstract protected void run(); + + protected void runWithCoordinates(int x, int y) { + run(); + } } static public interface ButtonPanel { diff --git a/src/org/geometerplus/zlibrary/core/application/ZLApplicationWindow.java b/src/org/geometerplus/zlibrary/core/application/ZLApplicationWindow.java index 8944e4131..f9d2bb1d1 100644 --- a/src/org/geometerplus/zlibrary/core/application/ZLApplicationWindow.java +++ b/src/org/geometerplus/zlibrary/core/application/ZLApplicationWindow.java @@ -39,6 +39,7 @@ abstract public class ZLApplicationWindow { abstract protected void scrollViewManually(int startX, int startY, int endX, int endY, ZLView.Direction direction); abstract protected void scrollViewToCenter(); abstract protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction); + abstract protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int x, int y); abstract protected void rotate(); abstract protected boolean canRotate(); diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java index 7695dca64..e6932fc12 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java @@ -208,6 +208,15 @@ public abstract class ZLTextView extends ZLTextViewBase { ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction); } + public final synchronized void startAutoScrolling(PageIndex pageIndex, Direction direction, int x, int y) { + if (isScrollingActive()) { + return; + } + + setScrollingActive(true); + ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction, x, y); + } + @Override public synchronized void onScrollingFinished(PageIndex pageIndex) { setScrollingActive(false); diff --git a/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java b/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java index 0399d94b8..48c34268c 100644 --- a/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java +++ b/src/org/geometerplus/zlibrary/ui/android/application/ZLAndroidApplicationWindow.java @@ -92,7 +92,14 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow { protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction) { final ZLAndroidWidget widget = ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget(); - widget.startAutoScrolling(pageIndex, direction); + widget.startAutoScrolling(pageIndex, direction, null, null); + } + + @Override + protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int x, int y) { + final ZLAndroidWidget widget = + ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget(); + widget.startAutoScrolling(pageIndex, direction, x, y); } public void rotate() { diff --git a/src/org/geometerplus/zlibrary/ui/android/view/AnimationProvider.java b/src/org/geometerplus/zlibrary/ui/android/view/AnimationProvider.java index 19c828d0f..b1e4d0a7a 100644 --- a/src/org/geometerplus/zlibrary/ui/android/view/AnimationProvider.java +++ b/src/org/geometerplus/zlibrary/ui/android/view/AnimationProvider.java @@ -67,15 +67,16 @@ abstract class AnimationProvider { setup(startX, startY, endX, endY, direction, w, h); } - void startAutoScrolling(boolean forward, float speed, ZLView.Direction direction, int w, int h) { + void startAutoScrolling(boolean forward, float speed, ZLView.Direction direction, int w, int h, Integer x, Integer y) { if (!inProgress()) { - final int x, y; - if (direction.IsHorizontal) { - x = speed < 0 ? w : 0; - y = 0; - } else { - x = 0; - y = speed < 0 ? h : 0; + if (x == null || y == null) { + if (direction.IsHorizontal) { + x = speed < 0 ? w : 0; + y = 0; + } else { + x = 0; + y = speed < 0 ? h : 0; + } } setup(x, y, x, y, direction, w, h); } diff --git a/src/org/geometerplus/zlibrary/ui/android/view/CurlAnimationProvider.java b/src/org/geometerplus/zlibrary/ui/android/view/CurlAnimationProvider.java index e0bd10dd2..caeb52b81 100644 --- a/src/org/geometerplus/zlibrary/ui/android/view/CurlAnimationProvider.java +++ b/src/org/geometerplus/zlibrary/ui/android/view/CurlAnimationProvider.java @@ -45,19 +45,25 @@ class CurlAnimationProvider extends AnimationProvider { final int x, y; if (myDirection.IsHorizontal) { x = myEndX; - //x = Math.max(1, Math.min(myWidth - 1, myEndX)); - if (cornerY == 0) { - y = Math.max(1, Math.min(myHeight / 2, myEndY)); + if (getMode().Auto) { + y = myEndY; } else { - y = Math.max(myHeight / 2, Math.min(myHeight - 1, myEndY)); + if (cornerY == 0) { + y = Math.max(1, Math.min(myHeight / 2, myEndY)); + } else { + y = Math.max(myHeight / 2, Math.min(myHeight - 1, myEndY)); + } } } else { y = myEndY; - //y = Math.max(1, Math.min(myHeight - 1, myEndY)); - if (cornerX == 0) { - x = Math.max(1, Math.min(myWidth / 2, myEndX)); + if (getMode().Auto) { + x = myEndX; } else { - x = Math.max(myWidth / 2, Math.min(myWidth - 1, myEndX)); + if (cornerX == 0) { + x = Math.max(1, Math.min(myWidth / 2, myEndX)); + } else { + x = Math.max(myWidth / 2, Math.min(myWidth - 1, myEndX)); + } } } final int dX = Math.max(1, Math.abs(x - cornerX)); @@ -123,81 +129,81 @@ class CurlAnimationProvider extends AnimationProvider { return ZLView.PageIndex.current; } + @Override + void startAutoScrolling(boolean forward, float speed, ZLView.Direction direction, int w, int h, Integer x, Integer y) { + if (x != null) { + if (x < w / 2) { + x = Math.min(x, w / 5); + } else { + x = Math.max(x, 4 * w / 5); + } + } + if (y != null) { + if (y < h / 2) { + y = Math.min(y, h / 5); + } else { + y = Math.max(y, 4 * h / 5); + } + } + super.startAutoScrolling(forward, Math.abs(speed), direction, w, h, x, y); + } + @Override void doStep() { if (!getMode().Auto) { return; } - switch (myDirection) { - case leftToRight: - myEndX -= (int)mySpeed; - if (myStartY < myHeight / 2) { - myEndY += (int)Math.abs(mySpeed / 2); - } else { - myEndY -= (int)Math.abs(mySpeed / 2); - } - break; - case rightToLeft: - myEndX += (int)mySpeed; - if (myStartY < myHeight / 2) { - myEndY += (int)Math.abs(mySpeed / 2); - } else { - myEndY -= (int)Math.abs(mySpeed / 2); - } - break; - case up: - myEndY += (int)mySpeed; - if (myStartX < myWidth / 2) { - myEndX += (int)Math.abs(mySpeed / 2); - } else { - myEndX -= (int)Math.abs(mySpeed / 2); - } - break; - case down: - myEndY -= (int)mySpeed; - if (myStartX < myWidth / 2) { - myEndX += (int)Math.abs(mySpeed / 2); - } else { - myEndX -= (int)Math.abs(mySpeed / 2); - } - break; - } - final int bound; - if (getMode() == Mode.AutoScrollingForward) { - bound = myDirection.IsHorizontal ? myWidth : myHeight; - } else { - bound = 0; - } - if (mySpeed > 0) { - if (myDirection.IsHorizontal) { - if (myEndX >= 2 * bound) { - myEndX = 2 * bound; - terminate(); - return; - } - } else { - if (myEndY >= 2 * bound) { - myEndY = 2 * bound; - terminate(); - return; - } - } - } else { - if (myDirection.IsHorizontal) { - if (myEndX <= -2 * bound) { - myEndX = -2 * bound; - terminate(); - return; - } - } else { - if (myEndY <= -2 * bound) { - myEndY = -2 * bound; - terminate(); - return; - } - } - } + final int cornerX = myStartX > myWidth / 2 ? myWidth : 0; + final int cornerY = myStartY > myHeight / 2 ? myHeight : 0; + final int speed = (int)mySpeed; mySpeed *= 1.5; + + final int boundX, boundY; + final boolean xOver, yOver; + if (getMode() == Mode.AutoScrollingForward) { + if (cornerX == 0) { + myEndX += speed; + boundX = 2 * myWidth; + xOver = myEndX >= boundX; + } else { + myEndX -= speed; + boundX = - myWidth; + xOver = myEndX <= boundX; + } + if (cornerY == 0) { + myEndY += speed; + boundY = 2 * myHeight; + yOver = myEndY >= boundY; + } else { + myEndY -= speed; + boundY = - myHeight; + yOver = myEndY <= boundY; + } + } else { + boundX = cornerX; + boundY = cornerY; + if (cornerX == 0) { + myEndX -= speed; + xOver = myEndX <= boundX; + } else { + myEndX += speed; + xOver = myEndX >= boundX; + } + if (cornerY == 0) { + myEndY -= speed; + yOver = myEndY <= boundY; + } else { + myEndY += speed; + yOver = myEndY >= boundY; + } + } + if (xOver && yOver) { + terminate(); + } else if (xOver) { + myEndX = boundX; + } else if (yOver) { + myEndY = boundY; + } } } diff --git a/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java b/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java index f5dbca774..112397bc3 100644 --- a/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java +++ b/src/org/geometerplus/zlibrary/ui/android/view/ZLAndroidWidget.java @@ -202,7 +202,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener { postInvalidate(); } - public void startAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction) { + public void startAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, Integer x, Integer y) { if (myMainBitmap == null) { return; } @@ -216,19 +216,19 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener { animator.terminate(); break; case previous: - animator.startAutoScrolling(false, -3, direction, w, h); + animator.startAutoScrolling(false, -3, direction, w, h, x, y); break; case next: - animator.startAutoScrolling(false, 3, direction, w, h); + animator.startAutoScrolling(false, 3, direction, w, h, x, y); break; } break; case previous: - animator.startAutoScrolling(true, 3, direction, w, h); + animator.startAutoScrolling(true, 3, direction, w, h, x, y); setPageToScrollTo(pageIndex); break; case next: - animator.startAutoScrolling(true, -3, direction, w, h); + animator.startAutoScrolling(true, -3, direction, w, h, x, y); setPageToScrollTo(pageIndex); break; }