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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
myReader.doAction(getZoneMap().getActionByCoordinates(
|
myReader.doActionWithCoordinates(getZoneMap().getActionByCoordinates(
|
||||||
x, y, myContext.getWidth(), myContext.getHeight(),
|
x, y, myContext.getWidth(), myContext.getHeight(),
|
||||||
isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap
|
isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap
|
||||||
));
|
), x, y);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -116,9 +116,9 @@ public final class FBView extends ZLTextView {
|
||||||
if (super.onFingerDoubleTap(x, y)) {
|
if (super.onFingerDoubleTap(x, y)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
myReader.doAction(getZoneMap().getActionByCoordinates(
|
myReader.doActionWithCoordinates(getZoneMap().getActionByCoordinates(
|
||||||
x, y, myContext.getWidth(), myContext.getHeight(), TapZoneMap.Tap.doubleTap
|
x, y, myContext.getWidth(), myContext.getHeight(), TapZoneMap.Tap.doubleTap
|
||||||
));
|
), x, y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,4 +68,20 @@ class TurnPageAction extends FBAction {
|
||||||
Reader.repaintView();
|
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() {
|
public final void onRepaintFinished() {
|
||||||
if (myWindow != null) {
|
if (myWindow != null) {
|
||||||
myWindow.refreshMenu();
|
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
|
//may be protected
|
||||||
abstract public ZLKeyBindings keyBindings();
|
abstract public ZLKeyBindings keyBindings();
|
||||||
|
|
||||||
|
@ -182,6 +195,10 @@ public abstract class ZLApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected void run();
|
abstract protected void run();
|
||||||
|
|
||||||
|
protected void runWithCoordinates(int x, int y) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public interface ButtonPanel {
|
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 scrollViewManually(int startX, int startY, int endX, int endY, ZLView.Direction direction);
|
||||||
abstract protected void scrollViewToCenter();
|
abstract protected void scrollViewToCenter();
|
||||||
abstract protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction);
|
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 void rotate();
|
||||||
abstract protected boolean canRotate();
|
abstract protected boolean canRotate();
|
||||||
|
|
|
@ -208,6 +208,15 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction);
|
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
|
@Override
|
||||||
public synchronized void onScrollingFinished(PageIndex pageIndex) {
|
public synchronized void onScrollingFinished(PageIndex pageIndex) {
|
||||||
setScrollingActive(false);
|
setScrollingActive(false);
|
||||||
|
|
|
@ -92,7 +92,14 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
||||||
protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction) {
|
protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction) {
|
||||||
final ZLAndroidWidget widget =
|
final ZLAndroidWidget widget =
|
||||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
((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() {
|
public void rotate() {
|
||||||
|
|
|
@ -67,15 +67,16 @@ abstract class AnimationProvider {
|
||||||
setup(startX, startY, endX, endY, direction, w, h);
|
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()) {
|
if (!inProgress()) {
|
||||||
final int x, y;
|
if (x == null || y == null) {
|
||||||
if (direction.IsHorizontal) {
|
if (direction.IsHorizontal) {
|
||||||
x = speed < 0 ? w : 0;
|
x = speed < 0 ? w : 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
} else {
|
} else {
|
||||||
x = 0;
|
x = 0;
|
||||||
y = speed < 0 ? h : 0;
|
y = speed < 0 ? h : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setup(x, y, x, y, direction, w, h);
|
setup(x, y, x, y, direction, w, h);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,19 +45,25 @@ class CurlAnimationProvider extends AnimationProvider {
|
||||||
final int x, y;
|
final int x, y;
|
||||||
if (myDirection.IsHorizontal) {
|
if (myDirection.IsHorizontal) {
|
||||||
x = myEndX;
|
x = myEndX;
|
||||||
//x = Math.max(1, Math.min(myWidth - 1, myEndX));
|
if (getMode().Auto) {
|
||||||
if (cornerY == 0) {
|
y = myEndY;
|
||||||
y = Math.max(1, Math.min(myHeight / 2, myEndY));
|
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
y = myEndY;
|
y = myEndY;
|
||||||
//y = Math.max(1, Math.min(myHeight - 1, myEndY));
|
if (getMode().Auto) {
|
||||||
if (cornerX == 0) {
|
x = myEndX;
|
||||||
x = Math.max(1, Math.min(myWidth / 2, myEndX));
|
|
||||||
} else {
|
} 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));
|
final int dX = Math.max(1, Math.abs(x - cornerX));
|
||||||
|
@ -123,81 +129,81 @@ class CurlAnimationProvider extends AnimationProvider {
|
||||||
return ZLView.PageIndex.current;
|
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
|
@Override
|
||||||
void doStep() {
|
void doStep() {
|
||||||
if (!getMode().Auto) {
|
if (!getMode().Auto) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (myDirection) {
|
final int cornerX = myStartX > myWidth / 2 ? myWidth : 0;
|
||||||
case leftToRight:
|
final int cornerY = myStartY > myHeight / 2 ? myHeight : 0;
|
||||||
myEndX -= (int)mySpeed;
|
final int speed = (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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mySpeed *= 1.5;
|
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();
|
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) {
|
if (myMainBitmap == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -216,19 +216,19 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
animator.terminate();
|
animator.terminate();
|
||||||
break;
|
break;
|
||||||
case previous:
|
case previous:
|
||||||
animator.startAutoScrolling(false, -3, direction, w, h);
|
animator.startAutoScrolling(false, -3, direction, w, h, x, y);
|
||||||
break;
|
break;
|
||||||
case next:
|
case next:
|
||||||
animator.startAutoScrolling(false, 3, direction, w, h);
|
animator.startAutoScrolling(false, 3, direction, w, h, x, y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case previous:
|
case previous:
|
||||||
animator.startAutoScrolling(true, 3, direction, w, h);
|
animator.startAutoScrolling(true, 3, direction, w, h, x, y);
|
||||||
setPageToScrollTo(pageIndex);
|
setPageToScrollTo(pageIndex);
|
||||||
break;
|
break;
|
||||||
case next:
|
case next:
|
||||||
animator.startAutoScrolling(true, -3, direction, w, h);
|
animator.startAutoScrolling(true, -3, direction, w, h, x, y);
|
||||||
setPageToScrollTo(pageIndex);
|
setPageToScrollTo(pageIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue