mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
more configurable animation providers
This commit is contained in:
parent
e1ec594d9d
commit
101148db9e
7 changed files with 41 additions and 23 deletions
|
@ -62,12 +62,23 @@ abstract class AnimationProvider {
|
||||||
mySpeed = 0;
|
mySpeed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void startManualScrolling(int startX, int startY, int endX, int endY, ZLView.Direction direction, int w, int h) {
|
void startManualScrolling(int x, int y, ZLView.Direction direction, int w, int h) {
|
||||||
myMode = Mode.ManualScrolling;
|
myMode = Mode.ManualScrolling;
|
||||||
setup(startX, startY, endX, endY, direction, w, h);
|
setup(x, y, direction, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startAutoScrolling(boolean forward, float startSpeed, ZLView.Direction direction, int w, int h, Integer x, Integer y, int speed) {
|
void scrollTo(int x, int y) {
|
||||||
|
if (myMode == Mode.ManualScrolling) {
|
||||||
|
myEndX = x;
|
||||||
|
myEndY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final void startAutoScrolling(boolean forward, float startSpeed, ZLView.Direction direction, int w, int h, Integer x, Integer y, int speed) {
|
||||||
|
startAutoScrollingInternal(forward, startSpeed, direction, w, h, x, y, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startAutoScrollingInternal(boolean forward, float startSpeed, ZLView.Direction direction, int w, int h, Integer x, Integer y, int speed) {
|
||||||
if (!inProgress()) {
|
if (!inProgress()) {
|
||||||
if (x == null || y == null) {
|
if (x == null || y == null) {
|
||||||
if (direction.IsHorizontal) {
|
if (direction.IsHorizontal) {
|
||||||
|
@ -78,7 +89,7 @@ abstract class AnimationProvider {
|
||||||
y = speed < 0 ? h : 0;
|
y = speed < 0 ? h : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setup(x, y, x, y, direction, w, h);
|
setup(x, y, direction, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
myMode = forward
|
myMode = forward
|
||||||
|
@ -95,11 +106,11 @@ abstract class AnimationProvider {
|
||||||
return myDirection.IsHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
return myDirection.IsHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup(int startX, int startY, int endX, int endY, ZLView.Direction direction, int width, int height) {
|
private void setup(int x, int y, ZLView.Direction direction, int width, int height) {
|
||||||
myStartX = startX;
|
myStartX = x;
|
||||||
myStartY = startY;
|
myStartY = y;
|
||||||
myEndX = endX;
|
myEndX = x;
|
||||||
myEndY = endY;
|
myEndY = y;
|
||||||
myDirection = direction;
|
myDirection = direction;
|
||||||
myWidth = width;
|
myWidth = width;
|
||||||
myHeight = height;
|
myHeight = height;
|
||||||
|
@ -113,7 +124,11 @@ abstract class AnimationProvider {
|
||||||
return 100 * shift / full;
|
return 100 * shift / full;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
final void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
|
drawInternal(canvas, bgBitmap, fgBitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void drawInternal(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
||||||
|
|
||||||
abstract ZLView.PageIndex getPageToScrollTo();
|
abstract ZLView.PageIndex getPageToScrollTo();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class CurlAnimationProvider extends AnimationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
protected void drawInternal(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
||||||
|
|
||||||
final int cornerX = myStartX > myWidth / 2 ? myWidth : 0;
|
final int cornerX = myStartX > myWidth / 2 ? myWidth : 0;
|
||||||
|
@ -199,7 +199,7 @@ class CurlAnimationProvider extends AnimationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void startAutoScrolling(boolean forward, float startSpeed, ZLView.Direction direction, int w, int h, Integer x, Integer y, int speed) {
|
protected void startAutoScrollingInternal(boolean forward, float startSpeed, ZLView.Direction direction, int w, int h, Integer x, Integer y, int speed) {
|
||||||
if (x == null || y == null) {
|
if (x == null || y == null) {
|
||||||
if (direction.IsHorizontal) {
|
if (direction.IsHorizontal) {
|
||||||
x = startSpeed < 0 ? w - 3 : 3;
|
x = startSpeed < 0 ? w - 3 : 3;
|
||||||
|
@ -221,7 +221,7 @@ class CurlAnimationProvider extends AnimationProvider {
|
||||||
x = Math.abs(cornerX - deltaX);
|
x = Math.abs(cornerX - deltaX);
|
||||||
y = Math.abs(cornerY - deltaY);
|
y = Math.abs(cornerY - deltaY);
|
||||||
}
|
}
|
||||||
super.startAutoScrolling(forward, startSpeed, direction, w, h, x, y, speed);
|
super.startAutoScrollingInternal(forward, startSpeed, direction, w, h, x, y, speed);
|
||||||
mySpeedFactor = (float)Math.pow(2.0, 0.25 * speed);
|
mySpeedFactor = (float)Math.pow(2.0, 0.25 * speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ class NoneAnimationProvider extends SimpleAnimationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
protected void drawInternal(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
canvas.drawBitmap(fgBitmap, 0, 0, myPaint);
|
canvas.drawBitmap(fgBitmap, 0, 0, myPaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class ShiftAnimationProvider extends SimpleAnimationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
protected void drawInternal(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
myPaint.setColor(Color.rgb(127, 127, 127));
|
myPaint.setColor(Color.rgb(127, 127, 127));
|
||||||
if (myDirection.IsHorizontal) {
|
if (myDirection.IsHorizontal) {
|
||||||
final int dX = myEndX - myStartX;
|
final int dX = myEndX - myStartX;
|
||||||
|
|
|
@ -46,7 +46,7 @@ abstract class SimpleAnimationProvider extends AnimationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void startAutoScrolling(boolean forward, float startSpeed, ZLView.Direction direction, int w, int h, Integer x, Integer y, int speed) {
|
protected void startAutoScrollingInternal(boolean forward, float startSpeed, ZLView.Direction direction, int w, int h, Integer x, Integer y, int speed) {
|
||||||
super.startAutoScrolling(forward, startSpeed, direction, w, h, x, y, speed);
|
super.startAutoScrolling(forward, startSpeed, direction, w, h, x, y, speed);
|
||||||
mySpeedFactor = (float)Math.pow(1.5, 0.25 * speed);
|
mySpeedFactor = (float)Math.pow(1.5, 0.25 * speed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class SlideAnimationProvider extends SimpleAnimationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
protected void drawInternal(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
||||||
myPaint.setColor(Color.rgb(127, 127, 127));
|
myPaint.setColor(Color.rgb(127, 127, 127));
|
||||||
if (myDirection.IsHorizontal) {
|
if (myDirection.IsHorizontal) {
|
||||||
|
|
|
@ -181,12 +181,15 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAnimationProvider().startManualScrolling(
|
final AnimationProvider animator = getAnimationProvider();
|
||||||
startX, startY,
|
if (!animator.inProgress()) {
|
||||||
endX, endY,
|
getAnimationProvider().startManualScrolling(
|
||||||
direction,
|
startX, startY,
|
||||||
getWidth(), getMainAreaHeight()
|
direction,
|
||||||
);
|
getWidth(), getMainAreaHeight()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
getAnimationProvider().scrollTo(endX, endY);
|
||||||
setPageToScrollTo(getAnimationProvider().getPageToScrollTo());
|
setPageToScrollTo(getAnimationProvider().getPageToScrollTo());
|
||||||
drawOnBitmap(mySecondaryBitmap);
|
drawOnBitmap(mySecondaryBitmap);
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue