mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +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) {
|
private synchronized void runAutoScrolling(int x, int y) {
|
||||||
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
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 diff = horizontal ? x - myStartX : y - myStartY;
|
||||||
final int h = myContext.getHeight();
|
final int h = myContext.getHeight();
|
||||||
final int w = myContext.getWidth();
|
final int w = myContext.getWidth();
|
||||||
|
@ -194,7 +195,7 @@ public final class FBView extends ZLTextView {
|
||||||
Math.abs(diff) < minDiff
|
Math.abs(diff) < minDiff
|
||||||
? PageIndex.current
|
? PageIndex.current
|
||||||
: (diff < 0 ? PageIndex.next : PageIndex.previous);
|
: (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) {
|
public boolean onFingerRelease(int x, int y) {
|
||||||
|
|
|
@ -121,6 +121,5 @@ abstract public class ZLView {
|
||||||
public abstract int getScrollbarThumbPosition(PageIndex pageIndex);
|
public abstract int getScrollbarThumbPosition(PageIndex pageIndex);
|
||||||
public abstract int getScrollbarThumbLength(PageIndex pageIndex);
|
public abstract int getScrollbarThumbLength(PageIndex pageIndex);
|
||||||
|
|
||||||
public abstract boolean canScrollForward();
|
public abstract boolean canScroll(PageIndex index);
|
||||||
public abstract boolean canScrollBackward();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1436,16 +1436,20 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canScrollForward() {
|
public boolean canScroll(PageIndex index) {
|
||||||
|
switch (index) {
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
case next:
|
||||||
|
{
|
||||||
final ZLTextWordCursor cursor = getEndCursor();
|
final ZLTextWordCursor cursor = getEndCursor();
|
||||||
return
|
return
|
||||||
cursor != null &&
|
cursor != null &&
|
||||||
!cursor.isNull() &&
|
!cursor.isNull() &&
|
||||||
(!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast());
|
(!cursor.isEndOfParagraph() || !cursor.getParagraphCursor().isLast());
|
||||||
}
|
}
|
||||||
|
case previous:
|
||||||
@Override
|
{
|
||||||
public boolean canScrollBackward() {
|
|
||||||
final ZLTextWordCursor cursor = getStartCursor();
|
final ZLTextWordCursor cursor = getStartCursor();
|
||||||
return
|
return
|
||||||
cursor != null &&
|
cursor != null &&
|
||||||
|
@ -1453,3 +1457,5 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
(!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst());
|
(!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) {
|
public void scrollManually(int startX, int startY, int endX, int endY, ZLView.Direction direction) {
|
||||||
final ZLView view = ZLApplication.Instance().getCurrentView();
|
final ZLView view = ZLApplication.Instance().getCurrentView();
|
||||||
final int diff = direction.IsHorizontal ? endX - startX : endY - startY;
|
final int diff = direction.IsHorizontal ? endX - startX : endY - startY;
|
||||||
if (diff >= 0) {
|
if (!view.canScroll(diff >= 0 ? ZLView.PageIndex.previous : ZLView.PageIndex.next)) {
|
||||||
if (!view.canScrollBackward()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (!view.canScrollForward()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final AnimationProvider animator = getAnimationProvider();
|
final AnimationProvider animator = getAnimationProvider();
|
||||||
if (!animator.inProgress()) {
|
if (!animator.inProgress()) {
|
||||||
|
@ -182,6 +176,11 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
final AnimationProvider animator = getAnimationProvider();
|
final AnimationProvider animator = getAnimationProvider();
|
||||||
final int w = getWidth();
|
final int w = getWidth();
|
||||||
final int h = getMainAreaHeight();
|
final int h = getMainAreaHeight();
|
||||||
|
|
||||||
|
if (!view.canScroll(pageIndex)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (pageIndex) {
|
switch (pageIndex) {
|
||||||
case current:
|
case current:
|
||||||
switch (animator.getPageToScrollTo()) {
|
switch (animator.getPageToScrollTo()) {
|
||||||
|
@ -197,15 +196,9 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case previous:
|
case previous:
|
||||||
if (!view.canScrollBackward()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
animator.startAutoScrolling(true, 3, direction, w, h, x, y, speed);
|
animator.startAutoScrolling(true, 3, direction, w, h, x, y, speed);
|
||||||
break;
|
break;
|
||||||
case next:
|
case next:
|
||||||
if (!view.canScrollForward()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
animator.startAutoScrolling(true, -3, direction, w, h, x, y, speed);
|
animator.startAutoScrolling(true, -3, direction, w, h, x, y, speed);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue