mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
animation refactoring (in progress)
This commit is contained in:
parent
8a3ad0b934
commit
89decaf5f9
2 changed files with 16 additions and 21 deletions
|
@ -33,7 +33,11 @@ abstract class AnimationProvider {
|
||||||
myPaint = paint;
|
myPaint = paint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup(int startX, int startY, int endX, int endY, boolean horizontal) {
|
int getScrollingShift() {
|
||||||
|
return myHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(int startX, int startY, int endX, int endY, boolean horizontal) {
|
||||||
myStartX = startX;
|
myStartX = startX;
|
||||||
myStartY = startY;
|
myStartY = startY;
|
||||||
myEndX = endX;
|
myEndX = endX;
|
||||||
|
@ -41,5 +45,5 @@ abstract class AnimationProvider {
|
||||||
myHorizontal = horizontal;
|
myHorizontal = horizontal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,15 +54,6 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
private ZLView.PageIndex myPageToScrollTo = ZLView.PageIndex.current;
|
private ZLView.PageIndex myPageToScrollTo = ZLView.PageIndex.current;
|
||||||
private boolean myScrollHorizontally;
|
private boolean myScrollHorizontally;
|
||||||
|
|
||||||
private int getScrollingShift() {
|
|
||||||
return myScrollHorizontally ? myEndX - myStartX : myEndY - myStartY;
|
|
||||||
}
|
|
||||||
private void stopScrolling() {
|
|
||||||
myScrollingState = ScrollingState.NoScrolling;
|
|
||||||
myEndX = myStartX;
|
|
||||||
myEndY = myStartY;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float myScrollingSpeed;
|
private float myScrollingSpeed;
|
||||||
private int myScrollingBound;
|
private int myScrollingBound;
|
||||||
|
|
||||||
|
@ -94,7 +85,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();
|
||||||
stopScrolling();
|
myScrollingState = ScrollingState.NoScrolling;
|
||||||
myScreenIsTouched = false;
|
myScreenIsTouched = false;
|
||||||
view.onScrollingFinished(ZLView.PageIndex.current);
|
view.onScrollingFinished(ZLView.PageIndex.current);
|
||||||
setPageToScrollTo(ZLView.PageIndex.current);
|
setPageToScrollTo(ZLView.PageIndex.current);
|
||||||
|
@ -187,7 +178,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
myEndY += (int)myScrollingSpeed;
|
myEndY += (int)myScrollingSpeed;
|
||||||
}
|
}
|
||||||
if (myScrollingSpeed > 0) {
|
if (myScrollingSpeed > 0) {
|
||||||
if (getScrollingShift() >= myScrollingBound) {
|
if (getAnimationProvider().getScrollingShift() >= myScrollingBound) {
|
||||||
if (myScrollHorizontally) {
|
if (myScrollHorizontally) {
|
||||||
myEndX = myStartX + myScrollingBound;
|
myEndX = myStartX + myScrollingBound;
|
||||||
} else {
|
} else {
|
||||||
|
@ -196,7 +187,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
doStopScrolling = true;
|
doStopScrolling = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (getScrollingShift() <= myScrollingBound) {
|
if (getAnimationProvider().getScrollingShift() <= myScrollingBound) {
|
||||||
if (myScrollHorizontally) {
|
if (myScrollHorizontally) {
|
||||||
myEndX = myStartX + myScrollingBound;
|
myEndX = myStartX + myScrollingBound;
|
||||||
} else {
|
} else {
|
||||||
|
@ -270,7 +261,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
final int size = myScrollHorizontally ? w : h;
|
final int size = myScrollHorizontally ? w : h;
|
||||||
int shift = getScrollingShift() < 0 ? getScrollingShift() + size : getScrollingShift() - size;
|
int shift = getAnimationProvider().getScrollingShift() < 0 ? getAnimationProvider().getScrollingShift() + size : getAnimationProvider().getScrollingShift() - size;
|
||||||
//if (shift > 0 && shift < size) {
|
//if (shift > 0 && shift < size) {
|
||||||
myEdgePaint.setColor(ZLAndroidPaintContext.getFillColor());
|
myEdgePaint.setColor(ZLAndroidPaintContext.getFillColor());
|
||||||
myEdgePaint.setAntiAlias(true);
|
myEdgePaint.setAntiAlias(true);
|
||||||
|
@ -300,7 +291,7 @@ 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);
|
||||||
stopScrolling();
|
myScrollingState = ScrollingState.NoScrolling;
|
||||||
} else {
|
} else {
|
||||||
if (myScrollingState == ScrollingState.AutoScrollingForward ||
|
if (myScrollingState == ScrollingState.AutoScrollingForward ||
|
||||||
myScrollingState == ScrollingState.AutoScrollingBackward) {
|
myScrollingState == ScrollingState.AutoScrollingBackward) {
|
||||||
|
@ -327,8 +318,8 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
if (myMainBitmap == null) {
|
if (myMainBitmap == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((shift > 0 && getScrollingShift() <= 0) ||
|
if ((shift > 0 && getAnimationProvider().getScrollingShift() <= 0) ||
|
||||||
(shift < 0 && getScrollingShift() >= 0)) {
|
(shift < 0 && getAnimationProvider().getScrollingShift() >= 0)) {
|
||||||
mySecondaryBitmapIsUpToDate = false;
|
mySecondaryBitmapIsUpToDate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +334,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollToCenter() {
|
public void scrollToCenter() {
|
||||||
stopScrolling();
|
myScrollingState = ScrollingState.NoScrolling;
|
||||||
if (myMainBitmap == null) {
|
if (myMainBitmap == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -659,7 +650,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
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(getScrollingShift());
|
final int shift = Math.abs(getAnimationProvider().getScrollingShift());
|
||||||
return (from * (size - shift) + to * shift) / size;
|
return (from * (size - shift) + to * shift) / size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -675,7 +666,7 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
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(getScrollingShift());
|
final int shift = Math.abs(getAnimationProvider().getScrollingShift());
|
||||||
return (from * (size - shift) + to * shift) / size;
|
return (from * (size - shift) + to * shift) / size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue