mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
better rendering for curl animation
This commit is contained in:
parent
4b4a99986d
commit
f26c851c5b
7 changed files with 67 additions and 49 deletions
|
@ -1,10 +1,10 @@
|
||||||
===== 1.0 (Mar ??, 2011) =====
|
===== 1.0 (Mar ??, 2011) =====
|
||||||
* Differnt (and configurable) actions for short and long Back button press (original code by Steffen Siebert)
|
* Different (and configurable) actions for short and long Back button press (original code by Steffen Siebert)
|
||||||
* SlovoEd dictionaries support has been fixed
|
* SlovoEd dictionaries support has been fixed
|
||||||
* Czech translation has been updated (by Marek Pavelka)
|
* Czech translation has been updated (by Marek Pavelka)
|
||||||
* No OutOfMemoryErrors in image loading
|
* No OutOfMemoryErrors in image loading
|
||||||
* Float series index parsing has been fixed
|
* Float series index parsing has been fixed
|
||||||
* Separate color for visited hyperlinks (original code by Steffen Siebert)
|
* Different colors for visited and non-visited hyperlinks (original code by Steffen Siebert)
|
||||||
* Removed menubar.xml: menu list is moved into the code
|
* Removed menubar.xml: menu list is moved into the code
|
||||||
* Proguard obfuscation has been added; package size decreased
|
* Proguard obfuscation has been added; package size decreased
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view;
|
||||||
|
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||||
|
|
||||||
abstract class AnimationProvider {
|
abstract class AnimationProvider {
|
||||||
protected final Paint myPaint;
|
protected final Paint myPaint;
|
||||||
protected int myStartX;
|
protected int myStartX;
|
||||||
|
@ -29,6 +31,9 @@ abstract class AnimationProvider {
|
||||||
protected int myEndY;
|
protected int myEndY;
|
||||||
protected boolean myHorizontal;
|
protected boolean myHorizontal;
|
||||||
|
|
||||||
|
protected int myWidth;
|
||||||
|
protected int myHeight;
|
||||||
|
|
||||||
protected AnimationProvider(Paint paint) {
|
protected AnimationProvider(Paint paint) {
|
||||||
myPaint = paint;
|
myPaint = paint;
|
||||||
}
|
}
|
||||||
|
@ -37,13 +42,17 @@ abstract class AnimationProvider {
|
||||||
return myHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
return myHorizontal ? myEndX - myStartX : myEndY - myStartY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(int startX, int startY, int endX, int endY, boolean horizontal) {
|
void setup(int startX, int startY, int endX, int endY, boolean horizontal, int width, int height) {
|
||||||
myStartX = startX;
|
myStartX = startX;
|
||||||
myStartY = startY;
|
myStartY = startY;
|
||||||
myEndX = endX;
|
myEndX = endX;
|
||||||
myEndY = endY;
|
myEndY = endY;
|
||||||
myHorizontal = horizontal;
|
myHorizontal = horizontal;
|
||||||
|
myWidth = width;
|
||||||
|
myHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
|
||||||
|
|
||||||
|
abstract ZLView.PageIndex getPageToScrollTo();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view;
|
||||||
|
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||||
|
|
||||||
class CurlAnimationProvider extends AnimationProvider {
|
class CurlAnimationProvider extends AnimationProvider {
|
||||||
private final Paint myEdgePaint = new Paint();
|
private final Paint myEdgePaint = new Paint();
|
||||||
|
|
||||||
|
@ -32,27 +34,24 @@ class CurlAnimationProvider extends AnimationProvider {
|
||||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
||||||
|
|
||||||
final int w = fgBitmap.getWidth();
|
final int cornerX = myStartX > myWidth / 2 ? myWidth : 0;
|
||||||
final int h = fgBitmap.getHeight();
|
final int cornerY = myStartY > myHeight / 2 ? myHeight : 0;
|
||||||
|
final int oppositeX = Math.abs(myWidth - cornerX);
|
||||||
final int cornerX = myStartX > w / 2 ? w : 0;
|
final int oppositeY = Math.abs(myHeight - cornerY);
|
||||||
final int cornerY = myStartY > h / 2 ? h : 0;
|
|
||||||
final int oppositeX = Math.abs(w - cornerX);
|
|
||||||
final int oppositeY = Math.abs(h - cornerY);
|
|
||||||
final int x, y;
|
final int x, y;
|
||||||
if (myHorizontal) {
|
if (myHorizontal) {
|
||||||
x = Math.max(1, Math.min(w - 1, myEndX));
|
x = Math.max(1, Math.min(myWidth - 1, myEndX));
|
||||||
if (cornerY == 0) {
|
if (cornerY == 0) {
|
||||||
y = Math.max(1, Math.min(h / 2, myEndY));
|
y = Math.max(1, Math.min(myHeight / 2, myEndY));
|
||||||
} else {
|
} else {
|
||||||
y = Math.max(h / 2, Math.min(h - 1, myEndY));
|
y = Math.max(myHeight / 2, Math.min(myHeight - 1, myEndY));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
y = Math.max(1, Math.min(h - 1, myEndY));
|
y = Math.max(1, Math.min(myHeight - 1, myEndY));
|
||||||
if (cornerX == 0) {
|
if (cornerX == 0) {
|
||||||
x = Math.max(1, Math.min(w / 2, myEndX));
|
x = Math.max(1, Math.min(myWidth / 2, myEndX));
|
||||||
} else {
|
} else {
|
||||||
x = Math.max(w / 2, Math.min(w - 1, myEndX));
|
x = Math.max(myWidth / 2, Math.min(myWidth - 1, myEndX));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final int dX = Math.abs(x - cornerX);
|
final int dX = Math.abs(x - cornerX);
|
||||||
|
@ -87,4 +86,10 @@ class CurlAnimationProvider extends AnimationProvider {
|
||||||
path.lineTo(cornerX, y1);
|
path.lineTo(cornerX, y1);
|
||||||
canvas.drawPath(path, myEdgePaint);
|
canvas.drawPath(path, myEdgePaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZLView.PageIndex getPageToScrollTo() {
|
||||||
|
return myHorizontal
|
||||||
|
? (myStartX < myWidth / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next)
|
||||||
|
: (myStartY < myHeight / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,26 +28,24 @@ class ShiftAnimationProvider extends SimpleAnimationProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
final int w = fgBitmap.getWidth();
|
|
||||||
final int h = fgBitmap.getHeight();
|
|
||||||
myPaint.setColor(Color.rgb(127, 127, 127));
|
myPaint.setColor(Color.rgb(127, 127, 127));
|
||||||
if (myHorizontal) {
|
if (myHorizontal) {
|
||||||
final int dX = myEndX - myStartX;
|
final int dX = myEndX - myStartX;
|
||||||
canvas.drawBitmap(bgBitmap, dX > 0 ? dX - w : dX + w, 0, myPaint);
|
canvas.drawBitmap(bgBitmap, dX > 0 ? dX - myWidth : dX + myWidth, 0, myPaint);
|
||||||
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
|
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
|
||||||
if (dX > 0 && dX < w) {
|
if (dX > 0 && dX < myWidth) {
|
||||||
canvas.drawLine(dX, 0, dX, h + 1, myPaint);
|
canvas.drawLine(dX, 0, dX, myHeight + 1, myPaint);
|
||||||
} else if (dX < 0 && dX > -w) {
|
} else if (dX < 0 && dX > -myWidth) {
|
||||||
canvas.drawLine(dX + w, 0, dX + w, h + 1, myPaint);
|
canvas.drawLine(dX + myWidth, 0, dX + myWidth, myHeight + 1, myPaint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final int dY = myEndY - myStartY;
|
final int dY = myEndY - myStartY;
|
||||||
canvas.drawBitmap(bgBitmap, 0, dY > 0 ? dY - h : dY + h, myPaint);
|
canvas.drawBitmap(bgBitmap, 0, dY > 0 ? dY - myHeight : dY + myHeight, myPaint);
|
||||||
canvas.drawBitmap(fgBitmap, 0, dY, myPaint);
|
canvas.drawBitmap(fgBitmap, 0, dY, myPaint);
|
||||||
if (dY > 0 && dY < h) {
|
if (dY > 0 && dY < myHeight) {
|
||||||
canvas.drawLine(0, dY, w + 1, dY, myPaint);
|
canvas.drawLine(0, dY, myWidth + 1, dY, myPaint);
|
||||||
} else if (dY < 0 && dY > -h) {
|
} else if (dY < 0 && dY > -myHeight) {
|
||||||
canvas.drawLine(0, dY + h, w + 1, dY + h, myPaint);
|
canvas.drawLine(0, dY + myHeight, myWidth + 1, dY + myHeight, myPaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,16 @@ package org.geometerplus.zlibrary.ui.android.view;
|
||||||
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||||
|
|
||||||
abstract class SimpleAnimationProvider extends AnimationProvider {
|
abstract class SimpleAnimationProvider extends AnimationProvider {
|
||||||
SimpleAnimationProvider(Paint paint) {
|
SimpleAnimationProvider(Paint paint) {
|
||||||
super(paint);
|
super(paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZLView.PageIndex getPageToScrollTo() {
|
||||||
|
return myHorizontal
|
||||||
|
? (myStartX < myEndX ? ZLView.PageIndex.previous : ZLView.PageIndex.next)
|
||||||
|
: (myStartY < myEndY ? ZLView.PageIndex.previous : ZLView.PageIndex.next);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,24 +29,22 @@ class SlideAnimationProvider extends SimpleAnimationProvider {
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
|
||||||
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
|
||||||
final int w = fgBitmap.getWidth();
|
|
||||||
final int h = fgBitmap.getHeight();
|
|
||||||
myPaint.setColor(Color.rgb(127, 127, 127));
|
myPaint.setColor(Color.rgb(127, 127, 127));
|
||||||
if (myHorizontal) {
|
if (myHorizontal) {
|
||||||
final int dX = myEndX - myStartX;
|
final int dX = myEndX - myStartX;
|
||||||
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
|
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
|
||||||
if (dX > 0 && dX < w) {
|
if (dX > 0 && dX < myWidth) {
|
||||||
canvas.drawLine(dX, 0, dX, h + 1, myPaint);
|
canvas.drawLine(dX, 0, dX, myHeight + 1, myPaint);
|
||||||
} else if (dX < 0 && dX > -w) {
|
} else if (dX < 0 && dX > -myWidth) {
|
||||||
canvas.drawLine(dX + w, 0, dX + w, h + 1, myPaint);
|
canvas.drawLine(dX + myWidth, 0, dX + myWidth, myHeight + 1, myPaint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final int dY = myEndY - myStartY;
|
final int dY = myEndY - myStartY;
|
||||||
canvas.drawBitmap(fgBitmap, 0, dY, myPaint);
|
canvas.drawBitmap(fgBitmap, 0, dY, myPaint);
|
||||||
if (dY > 0 && dY < h) {
|
if (dY > 0 && dY < myHeight) {
|
||||||
canvas.drawLine(0, dY, w + 1, dY, myPaint);
|
canvas.drawLine(0, dY, myWidth + 1, dY, myPaint);
|
||||||
} else if (dY < 0 && dY > -h) {
|
} else if (dY < 0 && dY > -myHeight) {
|
||||||
canvas.drawLine(0, dY + h, w + 1, dY + h, myPaint);
|
canvas.drawLine(0, dY + myHeight, myWidth + 1, dY + myHeight, myPaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,8 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
getAnimationProvider().setup(
|
getAnimationProvider().setup(
|
||||||
myStartX, myStartY,
|
myStartX, myStartY,
|
||||||
myEndX, myEndY,
|
myEndX, myEndY,
|
||||||
myScrollHorizontally
|
myScrollHorizontally,
|
||||||
|
getWidth(), getMainAreaHeight()
|
||||||
);
|
);
|
||||||
getAnimationProvider().draw(
|
getAnimationProvider().draw(
|
||||||
canvas,
|
canvas,
|
||||||
|
@ -230,25 +231,24 @@ 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;
|
|
||||||
final int shift = horizontally ? endX - startX : endY - startY;
|
|
||||||
|
|
||||||
if (myMainBitmap == null) {
|
if (myMainBitmap == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((shift > 0 && getAnimationProvider().getScrollingShift() <= 0) ||
|
|
||||||
(shift < 0 && getAnimationProvider().getScrollingShift() >= 0)) {
|
|
||||||
mySecondaryBitmapIsUpToDate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
myScrollingState = ScrollingState.ManualScrolling;
|
||||||
|
myScrollHorizontally = horizontally;
|
||||||
myStartX = startX;
|
myStartX = startX;
|
||||||
myStartY = startY;
|
myStartY = startY;
|
||||||
myEndX = endX;
|
myEndX = endX;
|
||||||
myEndY = endY;
|
myEndY = endY;
|
||||||
|
|
||||||
setPageToScrollTo(shift < 0 ? ZLView.PageIndex.next : ZLView.PageIndex.previous);
|
getAnimationProvider().setup(
|
||||||
|
startX, startY,
|
||||||
|
endX, endY,
|
||||||
|
horizontally,
|
||||||
|
getHeight(), getMainAreaHeight()
|
||||||
|
);
|
||||||
|
setPageToScrollTo(getAnimationProvider().getPageToScrollTo());
|
||||||
drawOnBitmap(mySecondaryBitmap);
|
drawOnBitmap(mySecondaryBitmap);
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue