mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
animation refactoring (in progress)
This commit is contained in:
parent
d2f11d1977
commit
ce6c8c741b
2 changed files with 17 additions and 15 deletions
|
@ -90,7 +90,7 @@ abstract class AnimationProvider {
|
||||||
return myMode != ScrollingMode.NoScrolling;
|
return myMode != ScrollingMode.NoScrolling;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getScrollingShift() {
|
private int getScrollingShift() {
|
||||||
return myDirection.IsHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
return myDirection.IsHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,12 @@ abstract class AnimationProvider {
|
||||||
mySpeed *= 1.5;
|
mySpeed *= 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getScrolledPercent() {
|
||||||
|
final int full = myDirection.IsHorizontal ? myWidth : myHeight;
|
||||||
|
final int shift = Math.abs(getScrollingShift());
|
||||||
|
return 100 * shift / full;
|
||||||
|
}
|
||||||
|
|
||||||
abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
||||||
|
|
||||||
abstract ZLView.PageIndex getPageToScrollTo();
|
abstract ZLView.PageIndex getPageToScrollTo();
|
||||||
|
|
|
@ -38,7 +38,6 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
private Bitmap myFooterBitmap;
|
private Bitmap myFooterBitmap;
|
||||||
|
|
||||||
private ZLView.PageIndex myPageToScrollTo = ZLView.PageIndex.current;
|
private ZLView.PageIndex myPageToScrollTo = ZLView.PageIndex.current;
|
||||||
private ZLView.Direction myScrollingDirection;
|
|
||||||
|
|
||||||
public ZLAndroidWidget(Context context, AttributeSet attrs, int defStyle) {
|
public ZLAndroidWidget(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
@ -183,7 +182,6 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAnimationProvider().setScrollingMode(AnimationProvider.ScrollingMode.ManualScrolling);
|
getAnimationProvider().setScrollingMode(AnimationProvider.ScrollingMode.ManualScrolling);
|
||||||
myScrollingDirection = direction;
|
|
||||||
|
|
||||||
getAnimationProvider().setup(
|
getAnimationProvider().setup(
|
||||||
startX, startY,
|
startX, startY,
|
||||||
|
@ -210,9 +208,9 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
if (myMainBitmap == null) {
|
if (myMainBitmap == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
myScrollingDirection = direction;
|
|
||||||
final AnimationProvider animator = getAnimationProvider();
|
final AnimationProvider animator = getAnimationProvider();
|
||||||
final boolean doSetup = !animator.inProgress();
|
final int w = getWidth();
|
||||||
|
final int h = getHeight();
|
||||||
switch (pageIndex) {
|
switch (pageIndex) {
|
||||||
case current:
|
case current:
|
||||||
switch (myPageToScrollTo) {
|
switch (myPageToScrollTo) {
|
||||||
|
@ -220,19 +218,19 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
animator.terminate();
|
animator.terminate();
|
||||||
break;
|
break;
|
||||||
case previous:
|
case previous:
|
||||||
animator.startAutoScrolling(false, -3, direction, getWidth(), getMainAreaHeight());
|
animator.startAutoScrolling(false, -3, direction, w, h);
|
||||||
break;
|
break;
|
||||||
case next:
|
case next:
|
||||||
animator.startAutoScrolling(false, 3, direction, getWidth(), getMainAreaHeight());
|
animator.startAutoScrolling(false, 3, direction, w, h);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case previous:
|
case previous:
|
||||||
animator.startAutoScrolling(true, 3, direction, getWidth(), getMainAreaHeight());
|
animator.startAutoScrolling(true, 3, direction, w, h);
|
||||||
setPageToScrollTo(pageIndex);
|
setPageToScrollTo(pageIndex);
|
||||||
break;
|
break;
|
||||||
case next:
|
case next:
|
||||||
animator.startAutoScrolling(true, -3, direction, getWidth(), getMainAreaHeight());
|
animator.startAutoScrolling(true, -3, direction, w, h);
|
||||||
setPageToScrollTo(pageIndex);
|
setPageToScrollTo(pageIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -505,9 +503,8 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
if (animator.inProgress()) {
|
if (animator.inProgress()) {
|
||||||
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 = myScrollingDirection.IsHorizontal ? getWidth() : getMainAreaHeight();
|
final int percent = animator.getScrolledPercent();
|
||||||
final int shift = Math.abs(animator.getScrollingShift());
|
return (from * (100 - percent) + to * percent) / 100;
|
||||||
return (from * (size - shift) + to * shift) / size;
|
|
||||||
} else {
|
} else {
|
||||||
return view.getScrollbarThumbLength(ZLView.PageIndex.current);
|
return view.getScrollbarThumbLength(ZLView.PageIndex.current);
|
||||||
}
|
}
|
||||||
|
@ -522,9 +519,8 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
if (animator.inProgress()) {
|
if (animator.inProgress()) {
|
||||||
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 = myScrollingDirection.IsHorizontal ? getWidth() : getMainAreaHeight();
|
final int percent = animator.getScrolledPercent();
|
||||||
final int shift = Math.abs(animator.getScrollingShift());
|
return (from * (100 - percent) + to * percent) / 100;
|
||||||
return (from * (size - shift) + to * shift) / size;
|
|
||||||
} else {
|
} else {
|
||||||
return view.getScrollbarThumbPosition(ZLView.PageIndex.current);
|
return view.getScrollbarThumbPosition(ZLView.PageIndex.current);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue