mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
better curl animation
This commit is contained in:
parent
64cd0279b5
commit
01594d8cf9
9 changed files with 152 additions and 95 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue