mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
refactoring: scrolling start position is only stored in an animation provider
This commit is contained in:
parent
91906854da
commit
0b41534a03
4 changed files with 13 additions and 57 deletions
|
@ -50,7 +50,6 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int myStartX;
|
|
||||||
private int myStartY;
|
private int myStartY;
|
||||||
private boolean myIsBrightnessAdjustmentInProgress;
|
private boolean myIsBrightnessAdjustmentInProgress;
|
||||||
private int myStartBrightness;
|
private int myStartBrightness;
|
||||||
|
@ -155,8 +154,6 @@ public final class FBView extends ZLTextView {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
myStartX = x;
|
|
||||||
myStartY = y;
|
|
||||||
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
||||||
final Direction direction = horizontal ? Direction.rightToLeft : Direction.up;
|
final Direction direction = horizontal ? Direction.rightToLeft : Direction.up;
|
||||||
myReader.getViewWidget().startManualScrolling(x, y, direction);
|
myReader.getViewWidget().startManualScrolling(x, y, direction);
|
||||||
|
@ -186,19 +183,6 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void runAutoScrolling(int x, int y) {
|
|
||||||
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
|
||||||
final Direction direction = horizontal ? Direction.rightToLeft : Direction.up;
|
|
||||||
final int animationSpeed = ScrollingPreferences.Instance().AnimationSpeedOption.getValue();
|
|
||||||
final int diff = horizontal ? x - myStartX : y - myStartY;
|
|
||||||
final int h = myContext.getHeight();
|
|
||||||
final int w = myContext.getWidth();
|
|
||||||
final int minDiff = horizontal ?
|
|
||||||
(w > h ? w / 4 : w / 3) :
|
|
||||||
(h > w ? h / 4 : h / 3);
|
|
||||||
myReader.getViewWidget().startAutoScrolling(x, y, Math.abs(diff) > minDiff, animationSpeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onFingerRelease(int x, int y) {
|
public boolean onFingerRelease(int x, int y) {
|
||||||
if (myIsBrightnessAdjustmentInProgress) {
|
if (myIsBrightnessAdjustmentInProgress) {
|
||||||
myIsBrightnessAdjustmentInProgress = false;
|
myIsBrightnessAdjustmentInProgress = false;
|
||||||
|
@ -210,7 +194,9 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFlickScrollingEnabled()) {
|
if (isFlickScrollingEnabled()) {
|
||||||
runAutoScrolling(x, y);
|
myReader.getViewWidget().startAutoScrolling(
|
||||||
|
x, y, ScrollingPreferences.Instance().AnimationSpeedOption.getValue()
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,5 +27,5 @@ public interface ZLViewWidget {
|
||||||
void scrollManuallyTo(int x, int y);
|
void scrollManuallyTo(int x, int y);
|
||||||
void startAutoScrolling(ZLView.PageIndex pageIndex, int x, int y, ZLView.Direction direction, int speed);
|
void startAutoScrolling(ZLView.PageIndex pageIndex, int x, int y, ZLView.Direction direction, int speed);
|
||||||
void startAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int speed);
|
void startAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, int speed);
|
||||||
void startAutoScrolling(int x, int y, boolean forward, int speed);
|
void startAutoScrolling(int x, int y, int speed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ abstract class AnimationProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startAutoScrolling(int x, int y, boolean forward, int speed) {
|
void startAutoScrolling(int x, int y, int speed) {
|
||||||
if (myMode != Mode.ManualScrolling) {
|
if (myMode != Mode.ManualScrolling) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,12 @@ abstract class AnimationProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int diff = myDirection.IsHorizontal ? x - myStartX : y - myStartY;
|
||||||
|
final int minDiff = myDirection.IsHorizontal ?
|
||||||
|
(myWidth > myHeight ? myWidth / 4 : myWidth / 3) :
|
||||||
|
(myHeight > myWidth ? myHeight / 4 : myHeight / 3);
|
||||||
|
boolean forward = Math.abs(diff) > minDiff;
|
||||||
|
|
||||||
myMode = forward ? Mode.AutoScrollingForward : Mode.AutoScrollingBackward;
|
myMode = forward ? Mode.AutoScrollingForward : Mode.AutoScrollingBackward;
|
||||||
|
|
||||||
float velocity = 15;
|
float velocity = 15;
|
||||||
|
|
|
@ -198,55 +198,19 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startAutoScrolling(int x, int y, boolean forward, int speed) {
|
public void startAutoScrolling(int x, int y, int speed) {
|
||||||
final ZLView view = ZLApplication.Instance().getCurrentView();
|
final ZLView view = ZLApplication.Instance().getCurrentView();
|
||||||
final AnimationProvider animator = getAnimationProvider();
|
final AnimationProvider animator = getAnimationProvider();
|
||||||
if (!view.canScroll(animator.getPageToScrollTo(x, y))) {
|
if (!view.canScroll(animator.getPageToScrollTo(x, y))) {
|
||||||
animator.terminate();
|
animator.terminate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
animator.startAutoScrolling(x, y, forward, speed);
|
animator.startAutoScrolling(x, y, speed);
|
||||||
if (animator.getMode().Auto) {
|
if (animator.getMode().Auto) {
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public void startAutoScrolling(ZLView.PageIndex pageIndex, ZLView.Direction direction, Integer x, Integer y, int speed) {
|
|
||||||
final ZLView view = ZLApplication.Instance().getCurrentView();
|
|
||||||
final AnimationProvider animator = getAnimationProvider();
|
|
||||||
final int w = getWidth();
|
|
||||||
final int h = getMainAreaHeight();
|
|
||||||
|
|
||||||
if (animator.getMode().Auto || !view.canScroll(pageIndex)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (pageIndex) {
|
|
||||||
case current:
|
|
||||||
switch (animator.getPageToScrollTo()) {
|
|
||||||
case current:
|
|
||||||
animator.terminate();
|
|
||||||
break;
|
|
||||||
case previous:
|
|
||||||
animator.startAutoScrolling(false, -3, direction, w, h, x, y, speed);
|
|
||||||
break;
|
|
||||||
case next:
|
|
||||||
animator.startAutoScrolling(false, 3, direction, w, h, x, y, speed);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case previous:
|
|
||||||
animator.startAutoScrolling(true, 3, direction, w, h, x, y, speed);
|
|
||||||
break;
|
|
||||||
case next:
|
|
||||||
animator.startAutoScrolling(true, -3, direction, w, h, x, y, speed);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
postInvalidate();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void drawOnBitmap(Bitmap bitmap, ZLView.PageIndex index) {
|
void drawOnBitmap(Bitmap bitmap, ZLView.PageIndex index) {
|
||||||
final ZLView view = ZLApplication.Instance().getCurrentView();
|
final ZLView view = ZLApplication.Instance().getCurrentView();
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue