mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
refactoring: ZLView.Direction is used instead of 'boolean horizontal'
This commit is contained in:
parent
3074f93d8d
commit
f8b653b06b
14 changed files with 84 additions and 52 deletions
|
@ -188,7 +188,7 @@ public final class FBView extends ZLTextView {
|
|||
return false;
|
||||
}
|
||||
if (!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst()) {
|
||||
myReader.scrollViewManually(myStartX, myStartY, x, y, horizontal);
|
||||
myReader.scrollViewManually(myStartX, myStartY, x, y, Direction.rightToLeft);
|
||||
}
|
||||
} else if (diff < 0) {
|
||||
final ZLTextWordCursor cursor = getEndCursor();
|
||||
|
@ -196,7 +196,7 @@ public final class FBView extends ZLTextView {
|
|||
return false;
|
||||
}
|
||||
if (!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast()) {
|
||||
myReader.scrollViewManually(myStartX, myStartY, x, y, horizontal);
|
||||
myReader.scrollViewManually(myStartX, myStartY, x, y, Direction.up);
|
||||
}
|
||||
} else {
|
||||
myReader.scrollViewToCenter();
|
||||
|
@ -243,7 +243,7 @@ public final class FBView extends ZLTextView {
|
|||
? PageIndex.current
|
||||
: (diff < 0 ? PageIndex.next : PageIndex.previous);
|
||||
if (getAnimationType() != Animation.none) {
|
||||
startAutoScrolling(pageIndex, horizontal);
|
||||
startAutoScrolling(pageIndex, horizontal ? Direction.rightToLeft : Direction.up);
|
||||
} else {
|
||||
myReader.scrollViewToCenter();
|
||||
onScrollingFinished(pageIndex);
|
||||
|
|
|
@ -61,6 +61,7 @@ class TurnPageAction extends FBAction {
|
|||
view.startAutoScrolling(
|
||||
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up
|
||||
);
|
||||
} else {
|
||||
view.scrollPage(myForward, FBView.ScrollingMode.NO_OVERLAPPING, 0);
|
||||
|
|
|
@ -59,6 +59,7 @@ class VolumeKeyTurnPageAction extends FBAction {
|
|||
view.startAutoScrolling(
|
||||
forward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||
preferences.HorizontalOption.getValue()
|
||||
? FBView.Direction.rightToLeft : FBView.Direction.up
|
||||
);
|
||||
} else {
|
||||
view.scrollPage(forward, FBView.ScrollingMode.NO_OVERLAPPING, 0);
|
||||
|
|
|
@ -68,9 +68,9 @@ public abstract class ZLApplication {
|
|||
}
|
||||
}
|
||||
|
||||
public final void scrollViewManually(int startX, int startY, int endX, int endY, boolean horizontally) {
|
||||
public final void scrollViewManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||
if (myWindow != null) {
|
||||
myWindow.scrollViewManually(startX, startY, endX, endY, horizontally);
|
||||
myWindow.scrollViewManually(startX, startY, endX, endY, direction);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,9 +80,9 @@ public abstract class ZLApplication {
|
|||
}
|
||||
}
|
||||
|
||||
public final void startViewAutoScrolling(ZLView.PageIndex pageIndex, boolean horizontally) {
|
||||
public final void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction) {
|
||||
if (myWindow != null) {
|
||||
myWindow.startViewAutoScrolling(pageIndex, horizontally);
|
||||
myWindow.startViewAutoScrolling(pageIndex, direction);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@ abstract public class ZLApplicationWindow {
|
|||
abstract protected void refreshMenu();
|
||||
|
||||
abstract protected void repaintView();
|
||||
abstract protected void scrollViewManually(int startX, int startY, int endX, int endY, boolean horizontally);
|
||||
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, boolean horizontally);
|
||||
abstract protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction);
|
||||
|
||||
abstract protected void rotate();
|
||||
abstract protected boolean canRotate();
|
||||
|
|
|
@ -37,7 +37,17 @@ abstract public class ZLView {
|
|||
current, previous, next
|
||||
};
|
||||
public static enum Direction {
|
||||
leftToRight, rightToLeft, up, down
|
||||
leftToRight(true), rightToLeft(true), up(false), down(false);
|
||||
|
||||
private final boolean myIsHorizontal;
|
||||
|
||||
Direction(boolean isHorizontal) {
|
||||
myIsHorizontal = isHorizontal;
|
||||
}
|
||||
|
||||
public boolean isHorizontal() {
|
||||
return myIsHorizontal;
|
||||
}
|
||||
};
|
||||
public static enum Animation {
|
||||
none, curl, slide, shift
|
||||
|
|
|
@ -199,13 +199,13 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
myScrollingIsActive = active;
|
||||
}
|
||||
|
||||
public final synchronized void startAutoScrolling(PageIndex pageIndex, boolean horizontally) {
|
||||
public final synchronized void startAutoScrolling(PageIndex pageIndex, Direction direction) {
|
||||
if (isScrollingActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setScrollingActive(true);
|
||||
ZLApplication.Instance().startViewAutoScrolling(pageIndex, horizontally);
|
||||
ZLApplication.Instance().startViewAutoScrolling(pageIndex, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -75,10 +75,10 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void scrollViewManually(int startX, int startY, int endX, int endY, boolean horizontally) {
|
||||
protected void scrollViewManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||
final ZLAndroidWidget widget =
|
||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
||||
widget.scrollManually(startX, startY, endX, endY, horizontally);
|
||||
widget.scrollManually(startX, startY, endX, endY, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,10 +89,10 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, boolean horizontally) {
|
||||
protected void startViewAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction) {
|
||||
final ZLAndroidWidget widget =
|
||||
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
|
||||
widget.startAutoScrolling(pageIndex, horizontally);
|
||||
widget.startAutoScrolling(pageIndex, direction);
|
||||
}
|
||||
|
||||
public void rotate() {
|
||||
|
|
|
@ -29,7 +29,7 @@ abstract class AnimationProvider {
|
|||
protected int myStartY;
|
||||
protected int myEndX;
|
||||
protected int myEndY;
|
||||
protected boolean myHorizontal;
|
||||
protected ZLView.Direction myDirection;
|
||||
|
||||
protected int myWidth;
|
||||
protected int myHeight;
|
||||
|
@ -39,15 +39,15 @@ abstract class AnimationProvider {
|
|||
}
|
||||
|
||||
int getScrollingShift() {
|
||||
return myHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
||||
return myDirection.isHorizontal() ? myEndX - myStartX : myEndY - myStartY;
|
||||
}
|
||||
|
||||
void setup(int startX, int startY, int endX, int endY, boolean horizontal, int width, int height) {
|
||||
void setup(int startX, int startY, int endX, int endY, ZLView.Direction direction, int width, int height) {
|
||||
myStartX = startX;
|
||||
myStartY = startY;
|
||||
myEndX = endX;
|
||||
myEndY = endY;
|
||||
myHorizontal = horizontal;
|
||||
myDirection = direction;
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class CurlAnimationProvider extends AnimationProvider {
|
|||
final int oppositeX = Math.abs(myWidth - cornerX);
|
||||
final int oppositeY = Math.abs(myHeight - cornerY);
|
||||
final int x, y;
|
||||
if (myHorizontal) {
|
||||
if (myDirection.isHorizontal()) {
|
||||
x = Math.max(1, Math.min(myWidth - 1, myEndX));
|
||||
if (cornerY == 0) {
|
||||
y = Math.max(1, Math.min(myHeight / 2, myEndY));
|
||||
|
@ -88,8 +88,16 @@ class CurlAnimationProvider extends AnimationProvider {
|
|||
}
|
||||
|
||||
ZLView.PageIndex getPageToScrollTo() {
|
||||
return myHorizontal
|
||||
? (myStartX < myWidth / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next)
|
||||
: (myStartY < myHeight / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next);
|
||||
switch (myDirection) {
|
||||
case leftToRight:
|
||||
return myStartX < myWidth / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next;
|
||||
case rightToLeft:
|
||||
return myStartX < myWidth / 2 ? ZLView.PageIndex.next : ZLView.PageIndex.previous;
|
||||
case up:
|
||||
return myStartY < myHeight / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next;
|
||||
case down:
|
||||
return myStartY < myHeight / 2 ? ZLView.PageIndex.next : ZLView.PageIndex.previous;
|
||||
}
|
||||
return ZLView.PageIndex.current;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class ShiftAnimationProvider extends SimpleAnimationProvider {
|
|||
@Override
|
||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||
myPaint.setColor(Color.rgb(127, 127, 127));
|
||||
if (myHorizontal) {
|
||||
if (myDirection.isHorizontal()) {
|
||||
final int dX = myEndX - myStartX;
|
||||
canvas.drawBitmap(bgBitmap, dX > 0 ? dX - myWidth : dX + myWidth, 0, myPaint);
|
||||
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
|
||||
|
|
|
@ -29,8 +29,16 @@ abstract class SimpleAnimationProvider extends AnimationProvider {
|
|||
}
|
||||
|
||||
ZLView.PageIndex getPageToScrollTo() {
|
||||
return myHorizontal
|
||||
? (myStartX < myEndX ? ZLView.PageIndex.previous : ZLView.PageIndex.next)
|
||||
: (myStartY < myEndY ? ZLView.PageIndex.previous : ZLView.PageIndex.next);
|
||||
switch (myDirection) {
|
||||
case rightToLeft:
|
||||
return myStartX < myEndX ? ZLView.PageIndex.previous : ZLView.PageIndex.next;
|
||||
case leftToRight:
|
||||
return myStartX < myEndX ? ZLView.PageIndex.next : ZLView.PageIndex.previous;
|
||||
case up:
|
||||
return myStartY < myEndY ? ZLView.PageIndex.previous : ZLView.PageIndex.next;
|
||||
case down:
|
||||
return myStartY < myEndY ? ZLView.PageIndex.next : ZLView.PageIndex.previous;
|
||||
}
|
||||
return ZLView.PageIndex.current;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class SlideAnimationProvider extends SimpleAnimationProvider {
|
|||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
||||
myPaint.setColor(Color.rgb(127, 127, 127));
|
||||
if (myHorizontal) {
|
||||
if (myDirection.isHorizontal()) {
|
||||
final int dX = myEndX - myStartX;
|
||||
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
|
||||
if (dX > 0 && dX < myWidth) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
private int myEndY;
|
||||
|
||||
private ZLView.PageIndex myPageToScrollTo = ZLView.PageIndex.current;
|
||||
private boolean myScrollHorizontally;
|
||||
private ZLView.Direction myScrollingDirection;
|
||||
|
||||
private float myScrollingSpeed;
|
||||
|
||||
|
@ -159,20 +159,29 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
boolean doStopScrolling = false;
|
||||
if (myScrollingState == ScrollingState.AutoScrollingForward ||
|
||||
myScrollingState == ScrollingState.AutoScrollingBackward) {
|
||||
if (myScrollHorizontally) {
|
||||
switch (myScrollingDirection) {
|
||||
case leftToRight:
|
||||
myEndX -= (int)myScrollingSpeed;
|
||||
break;
|
||||
case rightToLeft:
|
||||
myEndX += (int)myScrollingSpeed;
|
||||
} else {
|
||||
break;
|
||||
case up:
|
||||
myEndY += (int)myScrollingSpeed;
|
||||
break;
|
||||
case down:
|
||||
myEndY -= (int)myScrollingSpeed;
|
||||
break;
|
||||
}
|
||||
final int bound;
|
||||
if (myScrollingState == ScrollingState.AutoScrollingForward) {
|
||||
bound = myScrollHorizontally ? getWidth() : getMainAreaHeight();
|
||||
bound = myScrollingDirection.isHorizontal() ? getWidth() : getMainAreaHeight();
|
||||
} else {
|
||||
bound = 0;
|
||||
}
|
||||
if (myScrollingSpeed > 0) {
|
||||
if (getAnimationProvider().getScrollingShift() >= bound) {
|
||||
if (myScrollHorizontally) {
|
||||
if (myScrollingDirection.isHorizontal()) {
|
||||
myEndX = myStartX + bound;
|
||||
} else {
|
||||
myEndY = myStartY + bound;
|
||||
|
@ -181,7 +190,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
}
|
||||
} else {
|
||||
if (getAnimationProvider().getScrollingShift() <= -bound) {
|
||||
if (myScrollHorizontally) {
|
||||
if (myScrollingDirection.isHorizontal()) {
|
||||
myEndX = myStartX - bound;
|
||||
} else {
|
||||
myEndY = myStartY - bound;
|
||||
|
@ -211,7 +220,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
getAnimationProvider().setup(
|
||||
myStartX, myStartY,
|
||||
myEndX, myEndY,
|
||||
myScrollHorizontally,
|
||||
myScrollingDirection,
|
||||
getWidth(), getMainAreaHeight()
|
||||
);
|
||||
getAnimationProvider().draw(
|
||||
|
@ -234,13 +243,13 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
}
|
||||
}
|
||||
|
||||
public void scrollManually(int startX, int startY, int endX, int endY, boolean horizontally) {
|
||||
public void scrollManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||
if (myMainBitmap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
myScrollingState = ScrollingState.ManualScrolling;
|
||||
myScrollHorizontally = horizontally;
|
||||
myScrollingDirection = direction;
|
||||
myStartX = startX;
|
||||
myStartY = startY;
|
||||
myEndX = endX;
|
||||
|
@ -249,7 +258,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
getAnimationProvider().setup(
|
||||
startX, startY,
|
||||
endX, endY,
|
||||
horizontally,
|
||||
direction,
|
||||
getWidth(), getMainAreaHeight()
|
||||
);
|
||||
setPageToScrollTo(getAnimationProvider().getPageToScrollTo());
|
||||
|
@ -267,11 +276,11 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
postInvalidate();
|
||||
}
|
||||
|
||||
public void startAutoScrolling(ZLView.PageIndex pageIndex, boolean horizontally) {
|
||||
public void startAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction) {
|
||||
if (myMainBitmap == null) {
|
||||
return;
|
||||
}
|
||||
myScrollHorizontally = horizontally;
|
||||
myScrollingDirection = direction;
|
||||
boolean doSetup = myScrollingState == ScrollingState.NoScrolling;
|
||||
switch (pageIndex) {
|
||||
case current:
|
||||
|
@ -301,13 +310,8 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
setPageToScrollTo(pageIndex);
|
||||
break;
|
||||
}
|
||||
System.err.println(doSetup + ":" + myScrollingState);
|
||||
if (doSetup && myScrollingState != ScrollingState.NoScrolling) {
|
||||
//getAnimationProvider().setup(
|
||||
// myScrollHorizontally,
|
||||
// getWidth(), getMainAreaHeight()
|
||||
//);
|
||||
if (myScrollHorizontally) {
|
||||
if (myScrollingDirection.isHorizontal()) {
|
||||
myStartX = myScrollingSpeed < 0 ? getWidth() : 0;
|
||||
myStartY = 0;
|
||||
} else {
|
||||
|
@ -319,7 +323,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
getAnimationProvider().setup(
|
||||
myStartX, myStartY,
|
||||
myEndX, myEndY,
|
||||
myScrollHorizontally,
|
||||
myScrollingDirection,
|
||||
getWidth(), getMainAreaHeight()
|
||||
);
|
||||
}
|
||||
|
@ -593,7 +597,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
} else {
|
||||
final int from = view.getScrollbarThumbLength(ZLView.PageIndex.current);
|
||||
final int to = view.getScrollbarThumbLength(myPageToScrollTo);
|
||||
final int size = myScrollHorizontally ? getWidth() : getMainAreaHeight();
|
||||
final int size = myScrollingDirection.isHorizontal() ? getWidth() : getMainAreaHeight();
|
||||
final int shift = Math.abs(getAnimationProvider().getScrollingShift());
|
||||
return (from * (size - shift) + to * shift) / size;
|
||||
}
|
||||
|
@ -609,7 +613,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
} else {
|
||||
final int from = view.getScrollbarThumbPosition(ZLView.PageIndex.current);
|
||||
final int to = view.getScrollbarThumbPosition(myPageToScrollTo);
|
||||
final int size = myScrollHorizontally ? getWidth() : getMainAreaHeight();
|
||||
final int size = myScrollingDirection.isHorizontal() ? getWidth() : getMainAreaHeight();
|
||||
final int shift = Math.abs(getAnimationProvider().getScrollingShift());
|
||||
return (from * (size - shift) + to * shift) / size;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue