public class Page extends RelativeLayout { public static final int CORNER_BOTTOM_LEFT = 0; public static final int CORNER_BOTTOM_RIGHT = 1; public static final int CORNER_TOP_LEFT = 2; public static final int CORNER_TOP_RIGHT = 3; private Path mClipPath; private PageTurner mPageTurner; private Callback mCallback; private int mCorner; private Drawable mBackPage; private Drawable mPageBackground;
public Page(Context context) { super(context); }
public Page(Context context, AttributeSet attrs ) { super(context, attrs ); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PageTurner);
public void setCorner(int corner) { this.mCorner = corner; }
public int getCorner() { return this.mCorner; } public void setBackPage(Drawable backPage) { this.mBackPage = backPage; } public Drawable getBackPage() { return this.mBackPage; }
public void setPageBackground(Drawable background) { this.mPageBackground = background; }
public Drawable getPageBackground() { return this.mPageBackground; } public static abstract class Callback { public void onDrawBackPage(Canvas canvas) {} public void onDrawBackground(Canvas canvas) {} public void onPageTurnFinished(Canvas canvas) {} } }
private static final int CORNER_RIGHT_MASK = 1; private static final int CORNER_TOP_MASK = 2; public static final int CORNER_BOTTOM_LEFT = 0; public static final int CORNER_BOTTOM_RIGHT = 1; public static final int CORNER_TOP_LEFT = 2; public static final int CORNER_TOP_RIGHT = 3; private static final int INVALIDATE = 1; private static final int INITIAL_TIME_DELAY = 100; private static final int TIME_DELAY = 10; private static final int TIME_STEPS = 30; private boolean mPageTurning; private boolean mStepping; private long mNextTime; private int mTimeStep; private int mDrawnTimeStep; private int mCorner; private Drawable mBackPage; private Drawable mPageBackground; private Path mForegroundPath; private Path mBackPagePath; private Path mBackgroundPath; private float mRotation; private Rect mChildRect = new Rect(); private int mOuterOffsetX; private int mOuterOffsetY; private float mPivotX; private int mPageId; private Page mPage; private PointF mPageTurnCorner = new PointF(); private PointF mOppositeCorner = new PointF(); private PointF mPageDim = new PointF(); private final Handler mHandler = new Handler() { public void handleMessage(Message msg) { if (msg.what != 1) { return; } PageTurner.this.invalidate(); if (PageTurner.this.mStepping) { return; } msg = obtainMessage(1); long current = SystemClock.uptimeMillis(); if (PageTurner.this.mNextTime < current) { //PageTurner.access$102(PageTurner.this, current + 10L); } sendMessageAtTime(msg, PageTurner.this.mNextTime); //PageTurner.access$114(PageTurner.this, 10L); } }; public PageTurner(Context context) { super(context); } public PageTurner(Context context, AttributeSet attrs) { super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PageTurner);
这个原来有的 因为不够泛所以就被android移除了
能说一下用2D的具体思路吗?thks
效果就是模拟日常中使用的日历的翻页方式,有个动画效果。
这里可以下archive 官方的那个应该也可以的 好象有问题
我帮你弄了 你看看把。。 差什么在说第一部分package android.widget;import android.R.styleable;
import android.content.Context;
import android.content.Resources.StyledAttributes;
import android.graphics.Canvas;
import android.graphics.Canvas.ClipMode;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import java.util.Map;public class PageTurner extends RelativeLayout
{
private static final int CORNER_RIGHT_MASK = 1;
private static final int CORNER_TOP_MASK = 2;
public static final int CORNER_BOTTOM_LEFT = 0;
public static final int CORNER_BOTTOM_RIGHT = 1;
public static final int CORNER_TOP_LEFT = 2;
public static final int CORNER_TOP_RIGHT = 3;
private static final int INVALIDATE = 1;
private static final int INITIAL_TIME_DELAY = 100;
private static final int TIME_DELAY = 10;
private static final int TIME_STEPS = 30;
private boolean mPageTurning;
private boolean mStepping;
private long mNextTime;
private int mTimeStep;
private int mDrawnTimeStep;
private int mCorner;
private Drawable mBackPage;
private Drawable mPageBackground;
private Path mForegroundPath;
private Path mBackPagePath;
private Path mBackgroundPath;
private float mRotation;
private Rect mChildRect = new Rect();
private int mOuterOffsetX;
private int mOuterOffsetY;
private float mPivotX;
private int mPageId;
private Page mPage;
private PointF mPageTurnCorner = new PointF();
private PointF mOppositeCorner = new PointF();
private PointF mPageDim = new PointF(); private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what != 1) {
return;
}
PageTurner.this.invalidate();
if (PageTurner.this.mStepping) {
return;
}
msg = obtainMessage(1);
long current = SystemClock.uptimeMillis();
if (PageTurner.this.mNextTime < current) {
PageTurner.access$102(PageTurner.this, current + 10L);
}
sendMessageAtTime(msg, PageTurner.this.mNextTime);
PageTurner.access$114(PageTurner.this, 10L);
}
}; public PageTurner(Context context)
{
super(context);
} public PageTurner(Context context, AttributeSet attrs, Map inflateParams) {
super(context, attrs, inflateParams);
Resources.StyledAttributes a = context.obtainStyledAttributes(attrs, R.styleable.PageTurner); this.mBackPage = a.getDrawable(1);
this.mPageBackground = a.getDrawable(0); this.mPageId = a.getResourceID(3, -1); this.mCorner = a.getInt(2, 0);
} protected void onFinishInflate()
{
super.onFinishInflate();
if (this.mPageId != -1) {
this.mPage = ((Page)findViewById(this.mPageId));
if (this.mPage != null)
this.mPage.setPageTurner(this);
}
} public void setPageId(int pageId)
{
this.mPageId = pageId;
this.mPage = ((Page)findViewById(this.mPageId));
if (this.mPage != null)
this.mPage.setPageTurner(this);
} public int getPageId()
{
return this.mPageId;
} public void setPage(Page page)
{
this.mPage = page;
} public Page getPage()
{
return this.mPage;
} public void setCorner(int corner)
{
this.mCorner = corner;
} public int getCorner()
{
return this.mCorner;
} protected void dispatchDraw(Canvas canvas)
{
if ((this.mPageTurning) && (this.mPage != null) && (computePageTurn()))
{
this.mPage.setClipPath(this.mForegroundPath);
} super.dispatchDraw(canvas); if (this.mPageTurning) {
drawBackground(canvas);
drawBackPage(canvas); if (!updateTimeStep())
{
this.mHandler.removeMessages(1);
if (this.mPage != null) {
this.mPage.onPageTurnFinished(canvas);
}
this.mPageTurning = false;
this.mStepping = false;
invalidate();
}
}
} public void startPageTurn()
{
if ((this.mPage == null) && (this.mPageId != -1)) {
this.mPage = ((Page)findViewById(this.mPageId));
}
if (this.mPage == null) {
return;
}
this.mPage.setPageTurner(this); Drawable d = this.mPage.getPageBackground();
if (d != null) {
this.mPageBackground = d;
}
d = this.mPage.getBackPage();
if (d != null) {
this.mBackPage = d;
} int corner = this.mPage.getCorner();
if (corner != -1) {
this.mCorner = corner;
} this.mPageTurning = true;
this.mTimeStep = 0;
this.mDrawnTimeStep = -1;
Message msg = this.mHandler.obtainMessage(1);
this.mNextTime = (SystemClock.uptimeMillis() + 100L);
this.mHandler.sendMessageAtTime(msg, this.mNextTime);
} public void stepPageTurn()
{
if (!this.mStepping)
{
this.mStepping = true;
startPageTurn();
}
else {
Message msg = this.mHandler.obtainMessage(1);
this.mNextTime = (SystemClock.uptimeMillis() + 10L);
this.mHandler.sendMessageAtTime(msg, this.mNextTime);
}
} private boolean updateTimeStep()
{
if (this.mTimeStep >= 30) {
return false;
}
this.mTimeStep += 1;
return true;
} private boolean computePageTurn()
{
if ((this.mDrawnTimeStep == this.mTimeStep) || (this.mTimeStep >= 30)) {
return false;
}
if (this.mPage == null) {
return false;
}
this.mDrawnTimeStep = this.mTimeStep;
View child = this.mPage.getChildAt(0);
child.getDrawingRect(this.mChildRect);
this.mOuterOffsetX = (child.getWindowLeft() - getWindowLeft());
this.mOuterOffsetY = (child.getWindowTop() - getWindowTop()); float width = this.mChildRect.right;
float height = this.mChildRect.bottom;
this.mPivotX = (this.mTimeStep / 30.0F * width);
this.mForegroundPath = new Path();
this.mBackPagePath = new Path();
this.mBackgroundPath = new Path();
float slope = width / (this.mPivotX - width);
float y = this.mPivotX * slope; this.mPageTurnCorner.x = 0.0F;
this.mPageTurnCorner.y = height;
this.mOppositeCorner.x = width;
this.mOppositeCorner.y = 0.0F;
float x0 = this.mPivotX;
float cornerIntersect = height * width / (height + width);
if ((this.mCorner & 0x1) != 0) {
this.mPageTurnCorner.x = width;
this.mOppositeCorner.x = 0.0F;
x0 = width - x0;
}
if ((this.mCorner & 0x2) != 0) {
this.mPageTurnCorner.y = 0.0F;
this.mOppositeCorner.y = height;
} this.mPageDim.x = width;
this.mPageDim.y = height;
float page_slope;
float page_slope;
if (this.mPivotX <= cornerIntersect)
{
page_slope = firstHalfPageTurn(this.mPageDim, this.mPageTurnCorner, this.mOppositeCorner, x0, slope, y);
}
else
{
page_slope = secondHalfPageTurn(this.mPageDim, this.mPageTurnCorner, this.mOppositeCorner, x0, slope, y);
} this.mRotation = (float)Math.atan(page_slope); this.mRotation = (float)(-this.mRotation * 180.0D / 3.141592653589793D); return true;
}
{
float width = pageDim.x;
float height = pageDim.y;
View child = this.mPage.getChildAt(0);
int innerOffsetX = child.getWindowLeft() - this.mPage.getWindowLeft();
int innerOffsetY = child.getWindowTop() - this.mPage.getWindowTop(); float y1 = height + y; float x2 = (float)(2.0D * y / (slope + 1.0D / slope));
float y2 = height + x2 / slope;
float page_slope = (height - y2) / (x2 - this.mPivotX);
if ((this.mCorner & 0x1) != 0) {
x2 = width - x2;
page_slope = -page_slope;
}
if ((this.mCorner & 0x2) != 0) {
y1 = height - y1;
y2 = height - y2;
page_slope = -page_slope;
} float x0 = xPivot;
float x1 = pageTurnCorner.x; this.mForegroundPath.moveTo(innerOffsetX + x1, innerOffsetY + y1);
this.mForegroundPath.lineTo(innerOffsetX + pageTurnCorner.x, innerOffsetY + oppositeCorner.y); this.mForegroundPath.lineTo(innerOffsetX + oppositeCorner.x, innerOffsetY + oppositeCorner.y); this.mForegroundPath.lineTo(innerOffsetX + oppositeCorner.x, innerOffsetY + pageTurnCorner.y); this.mForegroundPath.lineTo(innerOffsetX + x0, innerOffsetY + pageTurnCorner.y); this.mForegroundPath.lineTo(innerOffsetX + x2, innerOffsetY + y2);
this.mForegroundPath.lineTo(innerOffsetX + x1, innerOffsetY + y1); this.mBackPagePath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x2, this.mOuterOffsetY + y2);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackPagePath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); this.mBackgroundPath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackgroundPath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + pageTurnCorner.x, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); return page_slope;
} private float secondHalfPageTurn(PointF pageDim, PointF pageTurnCorner, PointF oppositeCorner, float xPivot, float slope, float y)
{
float width = pageDim.x;
float height = pageDim.y;
View child = this.mPage.getChildAt(0);
int xOffset = child.getWindowLeft() - this.mPage.getWindowLeft();
int yOffset = child.getWindowTop() - this.mPage.getWindowTop(); float y1 = 0.0F;
float x1 = width - (height + width) * (width - this.mPivotX) / width; float x3 = (float)(2.0D * y / (slope + 1.0D / slope));
float y3 = height + x3 / slope;
float page_slope = (height - y3) / (x3 - this.mPivotX);
float b = height - x1 * page_slope;
float x2 = (float)((-y - b) / (page_slope + 1.0D / page_slope));
float y2 = (x1 - x2) * page_slope; if ((this.mCorner & 0x1) != 0) {
x1 = width - x1;
x2 = width - x2;
x3 = width - x3;
page_slope = -page_slope;
}
if ((this.mCorner & 0x2) != 0) {
y1 = height - y1;
y2 = height - y2;
y3 = height - y3;
page_slope = -page_slope;
} float x0 = xPivot; this.mForegroundPath.moveTo(xOffset + x1, yOffset + y1);
this.mForegroundPath.lineTo(xOffset + oppositeCorner.x, yOffset + oppositeCorner.y); this.mForegroundPath.lineTo(xOffset + oppositeCorner.x, yOffset + pageTurnCorner.y); this.mForegroundPath.lineTo(xOffset + x0, yOffset + pageTurnCorner.y);
this.mForegroundPath.lineTo(xOffset + x1, yOffset + y1); this.mBackPagePath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x2, this.mOuterOffsetY + y2);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x3, this.mOuterOffsetY + y3);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackPagePath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); this.mBackgroundPath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackgroundPath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + pageTurnCorner.x, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + pageTurnCorner.x, this.mOuterOffsetY + oppositeCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); return page_slope;
} private void drawBackground(Canvas canvas)
{
canvas.save();
canvas.clipPath(this.mBackgroundPath, Canvas.ClipMode.INTERSECT);
canvas.translate(this.mOuterOffsetX, this.mOuterOffsetY);
if (this.mPageBackground != null) {
this.mPageBackground.setBounds(0, 0, this.mChildRect.right, this.mChildRect.bottom); this.mPageBackground.draw(canvas);
}
if (this.mPage != null) {
this.mPage.drawBackground(canvas);
}
canvas.restore();
} private void drawBackPage(Canvas canvas)
{
float width = this.mChildRect.right;
float height = this.mChildRect.bottom; canvas.save();
canvas.clipPath(this.mBackPagePath, Canvas.ClipMode.INTERSECT);
float xShift = 2.0F * this.mPivotX - width;
float xRotate = width - this.mPivotX;
float yRotate = height;
if ((this.mCorner & 0x1) != 0) {
xShift = width - 2.0F * this.mPivotX;
xRotate = this.mPivotX;
}
if ((this.mCorner & 0x2) != 0) {
yRotate = 0.0F;
}
canvas.translate(this.mOuterOffsetX + xShift, this.mOuterOffsetY);
canvas.rotate(this.mRotation, xRotate, yRotate);
if (this.mBackPage != null) {
this.mBackPage.setBounds(0, 0, this.mChildRect.right, this.mChildRect.bottom);
this.mBackPage.draw(canvas);
}
if (this.mPage != null) {
this.mPage.drawBackPage(canvas);
}
canvas.restore();
}
}
只能给你老版本sdk里面的pageTunner和相关的java源码 你可以直接用来试试看 应该是可以实现的
如果你要源文件我可以邮箱给你
多谢.
邮箱:[email protected]
http://download.csdn.net/source/2668990多谢了
[email protected]
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
public class Page extends RelativeLayout {
public static final int CORNER_BOTTOM_LEFT = 0;
public static final int CORNER_BOTTOM_RIGHT = 1;
public static final int CORNER_TOP_LEFT = 2;
public static final int CORNER_TOP_RIGHT = 3;
private Path mClipPath;
private PageTurner mPageTurner;
private Callback mCallback;
private int mCorner;
private Drawable mBackPage;
private Drawable mPageBackground;
public Page(Context context) {
super(context);
}
public Page(Context context, AttributeSet attrs ) {
super(context, attrs );
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PageTurner);
this.mBackPage = a.getDrawable(1);
this.mPageBackground = a.getDrawable(0);
this.mCorner = a.getInt(2, -1);
}
void setPageTurner(PageTurner pageTurner) {
this.mPageTurner = pageTurner;
} void setClipPath(Path clipPath) {
this.mClipPath = clipPath;
}
public void setCallback(Callback callback) {
this.mCallback = callback;
}
void drawBackPage(Canvas canvas) {
if (this.mCallback != null)
this.mCallback.onDrawBackPage(canvas);
}
void drawBackground(Canvas canvas) {
if (this.mCallback != null)
this.mCallback.onDrawBackground(canvas);
}
public void startPageTurn() {
if (this.mPageTurner != null)
this.mPageTurner.startPageTurn();
}
void onPageTurnFinished(Canvas canvas) {
this.mCallback.onPageTurnFinished(canvas);
this.mClipPath = null;
} protected void dispatchDraw(Canvas canvas) {
if (this.mClipPath != null) {
canvas.save();
canvas.clipPath(this.mClipPath, Region.Op.INTERSECT);
}
super.dispatchDraw(canvas);
if (this.mClipPath != null)
canvas.restore();
}
public void setCorner(int corner) {
this.mCorner = corner;
}
public int getCorner() {
return this.mCorner;
} public void setBackPage(Drawable backPage) {
this.mBackPage = backPage;
} public Drawable getBackPage() {
return this.mBackPage;
}
public void setPageBackground(Drawable background) {
this.mPageBackground = background;
}
public Drawable getPageBackground() {
return this.mPageBackground;
} public static abstract class Callback {
public void onDrawBackPage(Canvas canvas) {}
public void onDrawBackground(Canvas canvas) {}
public void onPageTurnFinished(Canvas canvas) {}
}
}
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;public class PageTurner extends RelativeLayout{
private static final int CORNER_RIGHT_MASK = 1;
private static final int CORNER_TOP_MASK = 2;
public static final int CORNER_BOTTOM_LEFT = 0;
public static final int CORNER_BOTTOM_RIGHT = 1;
public static final int CORNER_TOP_LEFT = 2;
public static final int CORNER_TOP_RIGHT = 3;
private static final int INVALIDATE = 1;
private static final int INITIAL_TIME_DELAY = 100;
private static final int TIME_DELAY = 10;
private static final int TIME_STEPS = 30;
private boolean mPageTurning;
private boolean mStepping;
private long mNextTime;
private int mTimeStep;
private int mDrawnTimeStep;
private int mCorner;
private Drawable mBackPage;
private Drawable mPageBackground;
private Path mForegroundPath;
private Path mBackPagePath;
private Path mBackgroundPath;
private float mRotation;
private Rect mChildRect = new Rect();
private int mOuterOffsetX;
private int mOuterOffsetY;
private float mPivotX;
private int mPageId;
private Page mPage;
private PointF mPageTurnCorner = new PointF();
private PointF mOppositeCorner = new PointF();
private PointF mPageDim = new PointF(); private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what != 1) { return; }
PageTurner.this.invalidate();
if (PageTurner.this.mStepping) { return; }
msg = obtainMessage(1);
long current = SystemClock.uptimeMillis();
if (PageTurner.this.mNextTime < current) {
//PageTurner.access$102(PageTurner.this, current + 10L);
}
sendMessageAtTime(msg, PageTurner.this.mNextTime);
//PageTurner.access$114(PageTurner.this, 10L);
}
}; public PageTurner(Context context) {
super(context);
} public PageTurner(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PageTurner);
this.mBackPage = a.getDrawable(1);
this.mPageBackground = a.getDrawable(0);
this.mPageId = a.getResourceId(3, -1);
this.mCorner = a.getInt(2, 0);
} protected void onFinishInflate() {
super.onFinishInflate();
if (this.mPageId != -1) {
this.mPage = ((Page)findViewById(this.mPageId));
if (this.mPage != null)
this.mPage.setPageTurner(this);
}
} public void setPageId(int pageId) {
this.mPageId = pageId;
this.mPage = ((Page)findViewById(this.mPageId));
if (this.mPage != null)
this.mPage.setPageTurner(this);
} public int getPageId() {
return this.mPageId;
} public void setPage(Page page) {
this.mPage = page;
} public Page getPage() {
return this.mPage;
} public void setCorner(int corner) {
this.mCorner = corner;
} public int getCorner() {
return this.mCorner;
} protected void dispatchDraw(Canvas canvas) {
if ((this.mPageTurning) && (this.mPage != null) && (computePageTurn())) {
this.mPage.setClipPath(this.mForegroundPath);
} super.dispatchDraw(canvas); if (this.mPageTurning) {
drawBackground(canvas);
drawBackPage(canvas); if (!updateTimeStep()) {
this.mHandler.removeMessages(1);
if (this.mPage != null) {
this.mPage.onPageTurnFinished(canvas);
}
this.mPageTurning = false;
this.mStepping = false;
invalidate();
}
}
} public void startPageTurn() {
if ((this.mPage == null) && (this.mPageId != -1)) {
this.mPage = ((Page)findViewById(this.mPageId));
}
if (this.mPage == null) {
return;
}
this.mPage.setPageTurner(this);
Drawable d = this.mPage.getPageBackground();
if (d != null) {
this.mPageBackground = d;
}
d = this.mPage.getBackPage();
if (d != null) {
this.mBackPage = d;
} int corner = this.mPage.getCorner();
if (corner != -1) {
this.mCorner = corner;
} this.mPageTurning = true;
this.mTimeStep = 0;
this.mDrawnTimeStep = -1;
Message msg = this.mHandler.obtainMessage(1);
this.mNextTime = (SystemClock.uptimeMillis() + 100L);
this.mHandler.sendMessageAtTime(msg, this.mNextTime);
} public void stepPageTurn() {
if (!this.mStepping) {
this.mStepping = true;
startPageTurn();
} else {
Message msg = this.mHandler.obtainMessage(1);
this.mNextTime = (SystemClock.uptimeMillis() + 10L);
this.mHandler.sendMessageAtTime(msg, this.mNextTime);
}
} private boolean updateTimeStep() {
if (this.mTimeStep >= 30) {
return false;
}
this.mTimeStep += 1;
return true;
} private boolean computePageTurn() {
if ((this.mDrawnTimeStep == this.mTimeStep) || (this.mTimeStep >= 30)) {
return false;
}
if (this.mPage == null) {
return false;
}
this.mDrawnTimeStep = this.mTimeStep;
View child = this.mPage.getChildAt(0);
child.getDrawingRect(this.mChildRect);
this.mOuterOffsetX = (child.getLeft() - getLeft());
this.mOuterOffsetY = (child.getTop() - getTop()); float width = this.mChildRect.right;
float height = this.mChildRect.bottom;
this.mPivotX = (this.mTimeStep / 30.0F * width);
this.mForegroundPath = new Path();
this.mBackPagePath = new Path();
this.mBackgroundPath = new Path();
float slope = width / (this.mPivotX - width);
float y = this.mPivotX * slope; this.mPageTurnCorner.x = 0.0F;
this.mPageTurnCorner.y = height;
this.mOppositeCorner.x = width;
this.mOppositeCorner.y = 0.0F;
float x0 = this.mPivotX;
float cornerIntersect = height * width / (height + width);
if ((this.mCorner & 0x1) != 0) {
this.mPageTurnCorner.x = width;
this.mOppositeCorner.x = 0.0F;
x0 = width - x0;
}
if ((this.mCorner & 0x2) != 0) {
this.mPageTurnCorner.y = 0.0F;
this.mOppositeCorner.y = height;
} this.mPageDim.x = width;
this.mPageDim.y = height;
float page_slope;
if (this.mPivotX <= cornerIntersect) {
page_slope = firstHalfPageTurn(this.mPageDim, this.mPageTurnCorner, this.mOppositeCorner, x0, slope, y);
} else {
page_slope = secondHalfPageTurn(this.mPageDim, this.mPageTurnCorner, this.mOppositeCorner, x0, slope, y);
} this.mRotation = (float)Math.atan(page_slope); this.mRotation = (float)(-this.mRotation * 180.0D / 3.141592653589793D); return true;
}
float width = pageDim.x;
float height = pageDim.y;
View child = this.mPage.getChildAt(0);
int innerOffsetX = child.getLeft() - this.mPage.getLeft();
int innerOffsetY = child.getTop() - this.mPage.getTop(); float y1 = height + y; float x2 = (float)(2.0D * y / (slope + 1.0D / slope));
float y2 = height + x2 / slope;
float page_slope = (height - y2) / (x2 - this.mPivotX);
if ((this.mCorner & 0x1) != 0) {
x2 = width - x2;
page_slope = -page_slope;
}
if ((this.mCorner & 0x2) != 0) {
y1 = height - y1;
y2 = height - y2;
page_slope = -page_slope;
} float x0 = xPivot;
float x1 = pageTurnCorner.x; this.mForegroundPath.moveTo(innerOffsetX + x1, innerOffsetY + y1);
this.mForegroundPath.lineTo(innerOffsetX + pageTurnCorner.x, innerOffsetY + oppositeCorner.y); this.mForegroundPath.lineTo(innerOffsetX + oppositeCorner.x, innerOffsetY + oppositeCorner.y); this.mForegroundPath.lineTo(innerOffsetX + oppositeCorner.x, innerOffsetY + pageTurnCorner.y); this.mForegroundPath.lineTo(innerOffsetX + x0, innerOffsetY + pageTurnCorner.y); this.mForegroundPath.lineTo(innerOffsetX + x2, innerOffsetY + y2);
this.mForegroundPath.lineTo(innerOffsetX + x1, innerOffsetY + y1); this.mBackPagePath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x2, this.mOuterOffsetY + y2);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackPagePath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); this.mBackgroundPath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackgroundPath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + pageTurnCorner.x, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); return page_slope;
} private float secondHalfPageTurn(PointF pageDim, PointF pageTurnCorner, PointF oppositeCorner, float xPivot, float slope, float y) {
float width = pageDim.x;
float height = pageDim.y;
View child = this.mPage.getChildAt(0);
int xOffset = child.getLeft() - this.mPage.getLeft();
int yOffset = child.getTop() - this.mPage.getTop(); float y1 = 0.0F;
float x1 = width - (height + width) * (width - this.mPivotX) / width; float x3 = (float)(2.0D * y / (slope + 1.0D / slope));
float y3 = height + x3 / slope;
float page_slope = (height - y3) / (x3 - this.mPivotX);
float b = height - x1 * page_slope;
float x2 = (float)((-y - b) / (page_slope + 1.0D / page_slope));
float y2 = (x1 - x2) * page_slope; if ((this.mCorner & 0x1) != 0) {
x1 = width - x1;
x2 = width - x2;
x3 = width - x3;
page_slope = -page_slope;
}
if ((this.mCorner & 0x2) != 0) {
y1 = height - y1;
y2 = height - y2;
y3 = height - y3;
page_slope = -page_slope;
} float x0 = xPivot; this.mForegroundPath.moveTo(xOffset + x1, yOffset + y1);
this.mForegroundPath.lineTo(xOffset + oppositeCorner.x, yOffset + oppositeCorner.y); this.mForegroundPath.lineTo(xOffset + oppositeCorner.x, yOffset + pageTurnCorner.y); this.mForegroundPath.lineTo(xOffset + x0, yOffset + pageTurnCorner.y);
this.mForegroundPath.lineTo(xOffset + x1, yOffset + y1); this.mBackPagePath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x2, this.mOuterOffsetY + y2);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x3, this.mOuterOffsetY + y3);
this.mBackPagePath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackPagePath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); this.mBackgroundPath.moveTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1);
this.mBackgroundPath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + pageTurnCorner.x, this.mOuterOffsetY + pageTurnCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + pageTurnCorner.x, this.mOuterOffsetY + oppositeCorner.y); this.mBackgroundPath.lineTo(this.mOuterOffsetX + x1, this.mOuterOffsetY + y1); return page_slope;
} private void drawBackground(Canvas canvas) {
canvas.save();
canvas.clipPath(this.mBackgroundPath, Region.Op.INTERSECT);
canvas.translate(this.mOuterOffsetX, this.mOuterOffsetY);
if (this.mPageBackground != null) {
this.mPageBackground.setBounds(0, 0, this.mChildRect.right, this.mChildRect.bottom); this.mPageBackground.draw(canvas);
}
if (this.mPage != null) {
this.mPage.drawBackground(canvas);
}
canvas.restore();
} private void drawBackPage(Canvas canvas) {
float width = this.mChildRect.right;
float height = this.mChildRect.bottom; canvas.save();
canvas.clipPath(this.mBackPagePath, Region.Op.INTERSECT);
float xShift = 2.0F * this.mPivotX - width;
float xRotate = width - this.mPivotX;
float yRotate = height;
if ((this.mCorner & 0x1) != 0) {
xShift = width - 2.0F * this.mPivotX;
xRotate = this.mPivotX;
}
if ((this.mCorner & 0x2) != 0) {
yRotate = 0.0F;
}
canvas.translate(this.mOuterOffsetX + xShift, this.mOuterOffsetY);
canvas.rotate(this.mRotation, xRotate, yRotate);
if (this.mBackPage != null) {
this.mBackPage.setBounds(0, 0, this.mChildRect.right, this.mChildRect.bottom);
this.mBackPage.draw(canvas);
}
if (this.mPage != null) {
this.mPage.drawBackPage(canvas);
}
canvas.restore();
}
}
但是在PageTurner中有个问题,if (PageTurner.this.mNextTime < current) {
//PageTurner.access$102(PageTurner.this, current + 10L);
}
sendMessageAtTime(msg, PageTurner.this.mNextTime);
//PageTurner.access$114(PageTurner.this, 10L);
注释这段的acess$102和access$114是何意??
找到一个android手势翻页效果的文章,有源代码的详细说明,并有下载。
http://wxmijl.blog.163.com/blog/static/13245928201062744245658/
这个是滑动翻页,非PageTurner的模拟真实效果翻页
http://download.csdn.net/source/2681832
http://download.csdn.net/source/2691661
thanks
if (PageTurner.this.mNextTime < current) {
PageTurner.this.mNextTime= current + 10L;
}
sendMessageAtTime(msg, PageTurner.this.mNextTime);
PageTurner.this.mNextTime+= 10L;