mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
code simplification
This commit is contained in:
parent
faf3a1a8d5
commit
3495a3a7da
4 changed files with 31 additions and 32 deletions
|
@ -184,6 +184,7 @@ public final class FBView extends ZLTextView {
|
|||
|
||||
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 diff = horizontal ? x - myStartX : y - myStartY;
|
||||
final int h = myContext.getHeight();
|
||||
final int w = myContext.getWidth();
|
||||
|
@ -194,7 +195,7 @@ public final class FBView extends ZLTextView {
|
|||
Math.abs(diff) < minDiff
|
||||
? PageIndex.current
|
||||
: (diff < 0 ? PageIndex.next : PageIndex.previous);
|
||||
myReader.startViewAutoScrolling(pageIndex, horizontal ? Direction.rightToLeft : Direction.up, ScrollingPreferences.Instance().AnimationSpeedOption.getValue());
|
||||
myReader.startViewAutoScrolling(pageIndex, direction, x, y, ScrollingPreferences.Instance().AnimationSpeedOption.getValue());
|
||||
}
|
||||
|
||||
public boolean onFingerRelease(int x, int y) {
|
||||
|
|
|
@ -121,6 +121,5 @@ abstract public class ZLView {
|
|||
public abstract int getScrollbarThumbPosition(PageIndex pageIndex);
|
||||
public abstract int getScrollbarThumbLength(PageIndex pageIndex);
|
||||
|
||||
public abstract boolean canScrollForward();
|
||||
public abstract boolean canScrollBackward();
|
||||
public abstract boolean canScroll(PageIndex index);
|
||||
}
|
||||
|
|
|
@ -1436,20 +1436,26 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollForward() {
|
||||
public boolean canScroll(PageIndex index) {
|
||||
switch (index) {
|
||||
default:
|
||||
return true;
|
||||
case next:
|
||||
{
|
||||
final ZLTextWordCursor cursor = getEndCursor();
|
||||
return
|
||||
cursor != null &&
|
||||
!cursor.isNull() &&
|
||||
(!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canScrollBackward() {
|
||||
case previous:
|
||||
{
|
||||
final ZLTextWordCursor cursor = getStartCursor();
|
||||
return
|
||||
cursor != null &&
|
||||
!cursor.isNull() &&
|
||||
(!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,15 +155,9 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
public void scrollManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||
final ZLView view = ZLApplication.Instance().getCurrentView();
|
||||
final int diff = direction.IsHorizontal ? endX - startX : endY - startY;
|
||||
if (diff >= 0) {
|
||||
if (!view.canScrollBackward()) {
|
||||
if (!view.canScroll(diff >= 0 ? ZLView.PageIndex.previous : ZLView.PageIndex.next)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!view.canScrollForward()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final AnimationProvider animator = getAnimationProvider();
|
||||
if (!animator.inProgress()) {
|
||||
|
@ -182,6 +176,11 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
final AnimationProvider animator = getAnimationProvider();
|
||||
final int w = getWidth();
|
||||
final int h = getMainAreaHeight();
|
||||
|
||||
if (!view.canScroll(pageIndex)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pageIndex) {
|
||||
case current:
|
||||
switch (animator.getPageToScrollTo()) {
|
||||
|
@ -197,15 +196,9 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
|||
}
|
||||
break;
|
||||
case previous:
|
||||
if (!view.canScrollBackward()) {
|
||||
return;
|
||||
}
|
||||
animator.startAutoScrolling(true, 3, direction, w, h, x, y, speed);
|
||||
break;
|
||||
case next:
|
||||
if (!view.canScrollForward()) {
|
||||
return;
|
||||
}
|
||||
animator.startAutoScrolling(true, -3, direction, w, h, x, y, speed);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue