package com.docin.nil;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.os.Handler;
import android.os.Message;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
/**
* @author Moritz 'Moss' Wundke (b.thax.dcg@gmail.com)
*/
/**
* 原作者代码如下: svn checkout code.google.com/p/android-page-curl/
*
* @note 原代码内容写得太死,无法广泛用于阅读器等应用!
* @author 陆再谋 (Nil Lu)
* @date 2012.3.6
* @contact QQ:1351231599 email:synwith@gmail.com
*/
public class PageCurlView extends View
{
private final static String TAG = "PageCurlView";
private Paint mTextPaint;
private TextPaint mTextPaintShadow;
/** Px / Draw call */
private int mCurlSpeed;
/** Fixed update time used to create a smooth curl animation */
private int mUpdateRate;
/** The initial offset for x and y axis movements */
private int mInitialEdgeOffset;
/** The mode we will use */
private int mCurlMode;
/** Simple curl mode. Curl target will move only in one axis. */
public static final int CURLMODE_SIMPLE = 0;
/** Dynamic curl mode. Curl target will move on both X and Y axis. */
public static final int CURLMODE_DYNAMIC = 1;
/** Enable/Disable debug mode */
private boolean bEnableDebugMode = false;
/** The context which owns us */
private WeakReference<Context> mContext;
/** Handler used to auto flip time based */
private FlipAnimationHandler mAnimationHandler;
/** Maximum radius a page can be flipped, by default it's the width of the view */
private float mFlipRadius;
/** Point used to move */
private Vector2D mMovement;
/** The finger position */
private Vector2D mFinger;
/** Movement point form the last frame */
private Vector2D mOldMovement;
/** Page curl edge */
private Paint mCurlEdgePaint;
/** Our points used to define the current clipping paths in our draw call */
private Vector2D mA, mB, mC, mD, mE, mF, mOldF, mOrigin;
/** If false no draw call has been done */
private boolean bViewDrawn;
/** Defines the flip direction that is currently considered */
private boolean bFlipRight;
/** If TRUE we are currently auto-flipping */
private boolean bFlipping;
/** Used to control touch input blocking */
private boolean bBlockTouchInput = false;
/** Enable input after the next draw event */
private boolean bEnableInputAfterDraw = false;
/**
* 加入一个表示正在做翻页操作,但是没放下手指
*/
private static int RIGHT_TAG = -1;
private static int LEFT_TAG = -1;
private boolean bFirstPage = false;
/** LAGACY List of pages, this is just temporal */
private ArrayList<Bitmap> mPages;
private String mPageCurrString = "";
private Bitmap mBackGroudBitmap = null;
private ArrayList<String> mContentList = new ArrayList<String>();
/** LAGACY Current selected page */
private int mIndex = 0;
/**
* Inner class used to represent a 2D point.
*/
private class Vector2D
{
public float x, y;
public Vector2D(float x, float y)
{
this.x = x;
this.y = y;
}
@Override
public String toString()
{
// TODO Auto-generated method stub
return "(" + this.x + "," + this.y + ")";
}
public float length()
{
return (float) Math.sqrt(x * x + y * y);
}
public float lengthSquared()
{
return (x * x) + (y * y);
}
public boolean equals(Object o)
{
if (o instanceof Vector2D)
{
Vector2D p = (Vector2D) o;
return p.x == x && p.y == y;
}
return false;
}
public Vector2D reverse()
{
return new Vector2D(-x, -y);
}
public Vector2D sum(Vector2D b)
{
return new Vector2D(x + b.x, y + b.y);
}
public Vector2D sub(Vector2D b)
{
return new Vector2D(x - b.x, y - b.y);
}
public float dot(Vector2D vec)
{
return (x * vec.x) + (y * vec.y);
}
public float cross(Vector2D a, Vector2D b)
{
return a.cross(b);
}
public float cross(Vector2D vec)
{
return x * vec.y - y * vec.x;
}
public float distanceSquared(Vector2D other)
{
float dx = other.x - x;
float dy = other.y - y;
return (dx * dx) + (dy * dy);
}
public float distance(Vector2D other)
{
return (float) Math.sqrt(distanceSquared(other));
}
public float dotProduct(Vector2D other)
{
return other.x * x + other.y * y;
}
public Vector2D normalize()
{
float magnitude = (float) Math.sqrt(dotProduct(this));
return new Vector2D(x / magnitude, y / magnitude);
}
public Vector2D mult(float scalar)
{
return new Vector2D(x * scalar, y * scalar);
}
}
/**
* Inner class used to make a fixed timed animation of the curl effect.
*/
class FlipAnimationHandler extends Handler
{
@Override
public void handleMessage(Message msg)
{
PageCurlView.this.FlipAnimationStep();
}
public void sleep(long millis)
{
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), millis);
}
}
/**
* Base
*
* @param context
*/
public PageCurlView(Context context)
{
super(context);
init(context);
ResetClipEdge();
}
/**
* Construct the object from an XML file. Valid Attributes:
*
* @see android.view.View#View(android.content.Context, android.util.AttributeSet)
*/
public PageCurlView(Context context, AttributeSet attrs)
{
super(context, attrs);
init(context);
// Get the data from the XML AttributeSet
{
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.PageCurlView);
// Get data
bEnableDebugMode = a.getBoolean(
R.styleable.PageCurlView_enableDebugMode, bEnableDebugMode);
bEnableDebugMode = false;
mCurlSpeed = a.getInt(R.styleable.PageCurlView_curlSpeed,
mCurlSpeed);
mUpdateRate = a.getInt(R.styleable.PageCurlView_updateRate,
mUpdateRate);
mInitialEdgeOffset = a.getInt(
R.styleable.PageCurlView_initialEdgeOffset,
mInitialEdgeOffset);
mCurlMode = a.getInt(R.styleable.PageCurlView_curlMode, mCurlMode);
Log.i(TAG, "mCurlSpeed: " + mCurlSpeed);
Log.i(TAG, "mUpdateRate: " + mUpdateRate);
Log.i(TAG, "mInitialEdgeOffset: " + mInitialEdgeOffset);
Log.i(TAG, "mCurlMode: " + mCurlMode);
// recycle object (so it can be used by others)
a.recycle();
}
ResetClipEdge();
}
/**
* Initialize the view
*/
private final void init(Context context)
{
// Foreground text paint
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(16);
mTextPaint.setColor(0xFF000000);
// The shadow
mTextPaintShadow = new TextPaint();
mTextPaintShadow.setAntiAlias(true);
mTextPaintShadow.setTextSize(16);
mTextPaintShadow.setColor(0x00000000);
// Cache the context
mContext = new WeakReference<Context>(context);
// Base padding
setPadding(3, 3, 3, 3);
// The focus flags are needed
setFocusable(true);
setFocusableInTouchMode(true);
mMovement = new Vector2D(0, 0);
mFinger = new Vector2D(0, 0);
mOldMovement = new Vector2D(0, 0);
// Create our curl animation handler
mAnimationHandler = new FlipAnimationHandler();
// Create our edge paint
mCurlEdgePaint = new Paint();
mCurlEdgePaint.setColor(Color.WHITE);
mCurlEdgePaint.setAntiAlias(true);
mCurlEdgePaint.setStyle
没有合适的资源?快使用搜索试试~ 我知道了~
完美解决android 翻页效果
共33个文件
class:12个
java:4个
xml:4个
5星 · 超过95%的资源 需积分: 10 84 下载量 85 浏览量
2012-03-06
15:57:35
上传
评论
收藏 613KB RAR 举报
温馨提示
翻页效果,原代码是国外人写的,但是写得有点死,经过我修改后,完美实现了相关操作。 作者原代码在如下: svn checkout code.google.com/p/android-page-curl/
资源推荐
资源详情
资源评论
收起资源包目录
完美解决翻页curlPage.rar (33个子文件)
完美解决翻页curlPage
CurlPageDemo
AndroidManifest.xml 738B
res
layout
main.xml 507B
drawable-ldpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 3KB
drawable-hdpi
readback.jpg 41KB
page2.jpg 40KB
page1.jpg 110KB
ic_launcher.png 4KB
values
strings.xml 190B
attrs.xml 676B
proguard.cfg 1KB
src
com
docin
nil
PageCurlView.java 32KB
L.java 574B
CurlPageDemoActivity.java 2KB
bin
classes
com
docin
nil
R$styleable.class 772B
CurlPageDemoActivity.class 1KB
R.class 547B
PageCurlView$FlipAnimationHandler.class 958B
PageCurlView.class 17KB
R$layout.class 379B
R$attr.class 524B
R$id.class 448B
R$string.class 412B
PageCurlView$Vector2D.class 3KB
R$drawable.class 482B
L.class 1KB
res
CurlPageDemo.apk 216KB
classes.dex 21KB
resources.ap_ 203KB
.classpath 364B
assets
project.properties 360B
.project 848B
gen
com
docin
nil
R.java 7KB
共 33 条
- 1
mokey87654
- 粉丝: 39
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页