1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

refactoring: ScrollingInProgress -> ScrollingState

This commit is contained in:
Nikolay Pultsin 2011-03-30 00:22:30 +01:00
parent 09f173b034
commit 4bf6dd2274
2 changed files with 34 additions and 18 deletions

View file

@ -33,13 +33,13 @@ abstract public class ZLView {
abstract public FooterArea getFooterArea(); abstract public FooterArea getFooterArea();
public enum PageIndex { public static enum PageIndex {
current, previous, next current, previous, next
}; };
public enum Direction { public static enum Direction {
leftToRight, rightToLeft, up, down leftToRight, rightToLeft, up, down
}; };
public enum Animation { public static enum Animation {
none, curl, slide, shift none, curl, slide, shift
} }

View file

@ -38,7 +38,14 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
private boolean mySecondaryBitmapIsUpToDate; private boolean mySecondaryBitmapIsUpToDate;
private Bitmap myFooterBitmap; private Bitmap myFooterBitmap;
private boolean myScrollingInProgress; private static enum ScrollingState {
NoScrolling,
ManualScrolling,
AutoScrollingForward,
AutoScrollingBackward
}
private ScrollingState myScrollingState = ScrollingState.NoScrolling;
private int myScrollingShift; private int myScrollingShift;
private float myScrollingSpeed; private float myScrollingSpeed;
private int myScrollingBound; private int myScrollingBound;
@ -71,7 +78,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
if (myScreenIsTouched) { if (myScreenIsTouched) {
final ZLView view = ZLApplication.Instance().getCurrentView(); final ZLView view = ZLApplication.Instance().getCurrentView();
myScrollingInProgress = false; myScrollingState = ScrollingState.NoScrolling;
myScrollingShift = 0; myScrollingShift = 0;
myScreenIsTouched = false; myScreenIsTouched = false;
view.onScrollingFinished(ZLView.PageIndex.current); view.onScrollingFinished(ZLView.PageIndex.current);
@ -107,11 +114,11 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
drawOnBitmap(myMainBitmap); drawOnBitmap(myMainBitmap);
} }
if (myScrollingInProgress || myScrollingShift != 0) { if (myScrollingState == ScrollingState.NoScrolling) {
onDrawInScrolling(canvas);
} else {
onDrawStatic(canvas); onDrawStatic(canvas);
ZLApplication.Instance().onRepaintFinished(); ZLApplication.Instance().onRepaintFinished();
} else {
onDrawInScrolling(canvas);
} }
} }
@ -196,7 +203,8 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
final int h = getMainAreaHeight(); final int h = getMainAreaHeight();
boolean stopScrolling = false; boolean stopScrolling = false;
if (myScrollingInProgress) { if (myScrollingState == ScrollingState.AutoScrollingForward ||
myScrollingState == ScrollingState.AutoScrollingBackward) {
myScrollingShift += (int)myScrollingSpeed; myScrollingShift += (int)myScrollingSpeed;
if (myScrollingSpeed > 0) { if (myScrollingSpeed > 0) {
if (myScrollingShift >= myScrollingBound) { if (myScrollingShift >= myScrollingBound) {
@ -322,10 +330,11 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
view.onScrollingFinished(ZLView.PageIndex.current); view.onScrollingFinished(ZLView.PageIndex.current);
} }
setPageToScrollTo(ZLView.PageIndex.current); setPageToScrollTo(ZLView.PageIndex.current);
myScrollingInProgress = false; myScrollingState = ScrollingState.NoScrolling;
myScrollingShift = 0; myScrollingShift = 0;
} else { } else {
if (myScrollingInProgress) { if (myScrollingState == ScrollingState.AutoScrollingForward ||
myScrollingState == ScrollingState.AutoScrollingBackward) {
postInvalidate(); postInvalidate();
} }
} }
@ -343,6 +352,8 @@ 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, boolean horizontally) {
myScrollingState = ScrollingState.ManualScrolling;
myScrollHorizontally = horizontally; myScrollHorizontally = horizontally;
final int shift = horizontally ? endX - startX : endY - startY; final int shift = horizontally ? endX - startX : endY - startY;
@ -360,6 +371,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
} }
public void scrollToCenter() { public void scrollToCenter() {
myScrollingState = ScrollingState.NoScrolling;
if (myMainBitmap == null) { if (myMainBitmap == null) {
return; return;
} }
@ -373,29 +385,33 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
if (myMainBitmap == null) { if (myMainBitmap == null) {
return; return;
} }
myScrollingInProgress = true;
myScrollHorizontally = horizontally; myScrollHorizontally = horizontally;
switch (pageIndex) { switch (pageIndex) {
case current: case current:
switch (myPageToScrollTo) { switch (myPageToScrollTo) {
case current: case current:
myScrollingState = ScrollingState.NoScrolling;
myScrollingSpeed = 0; myScrollingSpeed = 0;
break; break;
case previous: case previous:
myScrollingState = ScrollingState.AutoScrollingBackward;
myScrollingSpeed = -3; myScrollingSpeed = -3;
break; break;
case next: case next:
myScrollingState = ScrollingState.AutoScrollingBackward;
myScrollingSpeed = 3; myScrollingSpeed = 3;
break; break;
} }
myScrollingBound = 0; myScrollingBound = 0;
break; break;
case previous: case previous:
myScrollingState = ScrollingState.AutoScrollingForward;
myScrollingSpeed = 3; myScrollingSpeed = 3;
myScrollingBound = horizontally ? getWidth() : getMainAreaHeight(); myScrollingBound = horizontally ? getWidth() : getMainAreaHeight();
setPageToScrollTo(pageIndex); setPageToScrollTo(pageIndex);
break; break;
case next: case next:
myScrollingState = ScrollingState.AutoScrollingForward;
myScrollingSpeed = -3; myScrollingSpeed = -3;
myScrollingBound = horizontally ? -getWidth() : -getMainAreaHeight(); myScrollingBound = horizontally ? -getWidth() : -getMainAreaHeight();
setPageToScrollTo(pageIndex); setPageToScrollTo(pageIndex);
@ -666,14 +682,14 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
if (!view.isScrollbarShown()) { if (!view.isScrollbarShown()) {
return 0; return 0;
} }
if (myScrollingInProgress || (myScrollingShift != 0)) { if (myScrollingState == ScrollingState.NoScrolling) {
return view.getScrollbarThumbLength(ZLView.PageIndex.current);
} else {
final int from = view.getScrollbarThumbLength(ZLView.PageIndex.current); final int from = view.getScrollbarThumbLength(ZLView.PageIndex.current);
final int to = view.getScrollbarThumbLength(myPageToScrollTo); final int to = view.getScrollbarThumbLength(myPageToScrollTo);
final int size = myScrollHorizontally ? getWidth() : getMainAreaHeight(); final int size = myScrollHorizontally ? getWidth() : getMainAreaHeight();
final int shift = Math.abs(myScrollingShift); final int shift = Math.abs(myScrollingShift);
return (from * (size - shift) + to * shift) / size; return (from * (size - shift) + to * shift) / size;
} else {
return view.getScrollbarThumbLength(ZLView.PageIndex.current);
} }
} }
@ -682,14 +698,14 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
if (!view.isScrollbarShown()) { if (!view.isScrollbarShown()) {
return 0; return 0;
} }
if (myScrollingInProgress || (myScrollingShift != 0)) { if (myScrollingState == ScrollingState.NoScrolling) {
return view.getScrollbarThumbPosition(ZLView.PageIndex.current);
} else {
final int from = view.getScrollbarThumbPosition(ZLView.PageIndex.current); final int from = view.getScrollbarThumbPosition(ZLView.PageIndex.current);
final int to = view.getScrollbarThumbPosition(myPageToScrollTo); final int to = view.getScrollbarThumbPosition(myPageToScrollTo);
final int size = myScrollHorizontally ? getWidth() : getMainAreaHeight(); final int size = myScrollHorizontally ? getWidth() : getMainAreaHeight();
final int shift = Math.abs(myScrollingShift); final int shift = Math.abs(myScrollingShift);
return (from * (size - shift) + to * shift) / size; return (from * (size - shift) + to * shift) / size;
} else {
return view.getScrollbarThumbPosition(ZLView.PageIndex.current);
} }
} }