`
jackeysion
  • 浏览: 129558 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

电子书翻页效果(转)

阅读更多
两个UI的view类和一个使用方法的demo。
第一个pageTurnerView.java:
public class PageTurnerViewP1 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;    
      public 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;    
      public float mPivotX;    
      private int mPageId;    
      private PageViewP1 mPage;    
      private PointF mPageTurnCorner = new PointF();    
      private PointF mOppositeCorner = new PointF();    
      private PointF mPageDim = new PointF();    
      private int mStepLen = 1;    
      public static final int KEEP = 0;    
      public static final int NEXT = 1;    
      public static final int LAST = 2;    
      public int mWhere = KEEP;    
      public boolean isBgInit = true;    
      public boolean isBackInit = true;    
      private  float ax,ay,bx,by,cx,cy,dx,dy,ex,ey,c0x,c0y;    
      private int mMaxStep=30;    
      public final Handler mHandler = new Handler() {    
          public void handleMessage(Message msg) {    
              if (msg.what != 1) { return; }    
//            PageTurnerViewP1.this.invalidate();    
              refreshUI();    
//            PageTurnerViewP1.this.invalidate((int)bx, (int)ay, (int)dx, (int)dy);    
              if (PageTurnerViewP1.this.mStepping) { return; }    
              msg = obtainMessage(1);    
              long current = SystemClock.uptimeMillis();    
              if (PageTurnerViewP1.this.mNextTime < current) {    
                  //PageTurnerViewP1.access$102(PageTurnerViewP1.this, current + 10L);    
                 PageTurnerViewP1.this.mNextTime= current + 5L;    
              }    
              sendMessageAtTime(msg, PageTurnerViewP1.this.mNextTime);    
              //PageTurnerViewP1.access$114(PageTurnerViewP1.this, 10L);    
                PageTurnerViewP1.this.mNextTime+= 5L;    
          }    
      };    
        
   
      public PageTurnerViewP1(Context context) {    
          super(context);    
          Log.i("==================== PageTurnerViewP1(Context context) =================", "" + this);    
      }    
   
      public PageTurnerViewP1(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);    
//          this.mBackPage = this.getResources().getDrawable(com.tom.clip.R.drawable.a5);    
//          this.mPageBackground =this.getResources().getDrawable(com.tom.clip.R.drawable.a6);    
                
          this.mPageId = -1;    
            this.mCorner = -1;    
      }    
   
      protected void onFinishInflate() {    
          super.onFinishInflate();    
          if (this.mPageId != -1) {    
              this.mPage = ((PageViewP1)findViewById(this.mPageId));    
              if (this.mPage != null)    
                  this.mPage.setPageTurner(this);    
          }    
      }    
   
      public void setPageId(int pageId) {    
          this.mPageId = pageId;    
          this.mPage = ((PageViewP1)findViewById(this.mPageId));    
          if (this.mPage != null)    
              this.mPage.setPageTurner(this);    
      }    
   
      public int getPageId() {    
          return this.mPageId;    
      }    
   
      public void setPage(PageViewP1 pageViewP1) {    
          this.mPage = pageViewP1;    
      }    
   
      public PageViewP1 getPage() {    
          return this.mPage;    
      }    
   
      public void setCorner(int corner) {    
          this.mCorner = corner;    
      }    
   
      public int getCorner() {    
          return this.mCorner;    
      }    
   
      protected void dispatchDraw(Canvas canvas) {    
              
            Log.v("log dispatchDraw:", "drawing back page"+mPageTurning);    
//        if ((this.mPageTurning) && (this.mPage != null) && (computePageTurn())) {    
          if ((computePageTurn())&& (this.mPageTurning) && (this.mPage != null) ) {    
              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(int mTimeStep) {    
          if ((this.mPage == null) && (this.mPageId != -1)) {    
              this.mPage = ((PageViewP1)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.mStepping=false;    
          this.mPageTurning = true;    
          this.mTimeStep = mTimeStep;    
          this.mDrawnTimeStep = -1;    
          Message msg = this.mHandler.obtainMessage(1);    
          this.mNextTime = (SystemClock.uptimeMillis() + 5L);    
          this.mHandler.sendMessageAtTime(msg, this.mNextTime);    
      }    
   
      public void stepPageTurn() {    
          if (!this.mStepping) {    
              this.mStepping = true;    
              startPageTurn(this.mTimeStep);    
          } else {    
//          te((int)bx, 0, (int)mPageTurnCorner.x, (int)mPageTurnCorner.y);    
//            sendUIhandler();    
              refreshUI();    
          }    
      }    
      public void refreshUI(){    
          computePageTurn();    
//      
          this.invalidate();    
      }    
      private void sendUIhandler(){    
          Message msg = this.mHandler.obtainMessage(1);    
          this.mNextTime = (SystemClock.uptimeMillis() + 30L);    
          this.mHandler.sendMessageAtTime(msg, this.mNextTime);    
      }    
      private boolean updateTimeStep() {    
          if (this.mTimeStep >mMaxStep || this.mTimeStep<0) {    
              return false;    
          }    
          this.mTimeStep +=mStepLen;    
          return true;    
      }    
          
      private boolean computePageTurn() {    
//        if ((this.mDrawnTimeStep == this.mTimeStep) ||(this.mTimeStep <0)||(this.mTimeStep >this.mMaxStep)) {    
          if ( (this.mTimeStep <0)||(this.mTimeStep >this.mMaxStep)) {    
              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());    
          this.mOuterOffsetX = 0;    
          this.mOuterOffsetY = 0;    
   
          float width = this.mChildRect.right;    
          float height = this.mChildRect.bottom;    
          if(!mStepping){    
              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;    
      }    
   
      private float firstHalfPageTurn(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 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;    
   
              
          //a点是右上角,b点位左下角,c点为右下角,d点为固定的右下角    
          ax=this.mOuterOffsetX + x1;    
          ay=this.mOuterOffsetY + y1;    
              
          bx=this.mOuterOffsetX + x2;    
          by=this.mOuterOffsetY + y2;    
              
          cx=this.mOuterOffsetX + x0;    
          cy=this.mOuterOffsetY + pageTurnCorner.y;    
              
          dx=this.mOuterOffsetX + pageTurnCorner.x;    
          dy=this.mOuterOffsetY + pageTurnCorner.y;    
              
          ex=(dx+bx)/2;    
          ey=(dy+by)/2;    
              
          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.quadTo(ex, ey, bx, by);    
          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);    
          //b到c的那条线,可以考虑画个弧线    
          this.mBackPagePath.lineTo(this.mOuterOffsetX + x0, this.mOuterOffsetY + pageTurnCorner.y);    
//        this.mBackPagePath.arcTo(new RectF(bx,by,cx,cy), 220, 180,false);    
//        this.mBackPagePath.quadTo(ex, ey, cx, cy);    
//        this.mBackPagePath.cubicTo(100, -50, 200, 50, cx, cy);//贝赛尔曲线    
          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);    
   
        //a点是右上角,c0点位左上角,b点为左下角,d点为固定的右下角    
          ax=this.mOuterOffsetX + x1;    
          ay=this.mOuterOffsetY + y1;    
              
          c0x=this.mOuterOffsetX + x2;    
          c0y=this.mOuterOffsetY + y2;    
              
          bx=this.mOuterOffsetX + x3;    
          by=this.mOuterOffsetY + y3;    
          cx=this.mOuterOffsetX + x0;    
          cy=this.mOuterOffsetY + pageTurnCorner.y;    
              
          dx=this.mOuterOffsetX + pageTurnCorner.x;    
          dy=this.mOuterOffsetY + pageTurnCorner.y;    
              
          ex=(dx+bx)/2;    
          ey=(dy+by)/2;    
              
          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.quadTo(ex, ey, cx, cy);    
          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.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));    
          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);    
          }    
              
        // add drop shadow start test    
            if(mTimeStep<=29&&ex>2){    
            LinearGradient grad = new LinearGradient(    
                    ex,ey,ex+(dx-ex)/4,ey+(dy-ey)/4,R.color.gray3,Color.TRANSPARENT,Shader.TileMode.CLAMP);    
            Paint p=new Paint();    
            p.setShader(grad);    
//          p.setAlpha(120);    
            canvas.drawPath(this.mBackgroundPath,p);    
            //end test    
            }    
          canvas.restore();    
              
            
      }    
   
      private void drawBackPage(Canvas canvas) {    
          float width = this.mChildRect.right;    
          float height = this.mChildRect.bottom;    
          canvas.save();    
//        canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));    
          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) {    
                Log.v("log2 drawBackPage2:", "drawing back page");    
              this.mPage.drawBackPage(canvas);    
          }    
              
          canvas.restore();    
          canvas.save();    
//        canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));    
//        int[] colors={Color.BLACK,Color.GRAY,Color.BLACK};    
//          LinearGradient grad = new LinearGradient(    
//                  ex,ey,bx,by,colors,null,Shader.TileMode.CLAMP);    
//          Paint p=new Paint();    
//          p.setShader(grad);    
//          p.setAlpha(120);    
//          canvas.drawPath(this.mBackPagePath,p);    
            LinearGradient grad = new LinearGradient(    
                    ex,ey,ex-(ex-bx)/4,ey-(ey-by)/4,R.color.gray3,0xC9C9C9,Shader.TileMode.CLAMP);    
            Paint p=new Paint();    
            p.setShader(grad);    
//          p.setAlpha(120);    
            canvas.drawPath(this.mBackPagePath,p);    
            canvas.restore();    
            //中间阴影问题,起点蓝色-》 白色-》 蓝色终点,这样起点前和终点后的区域也为蓝色了。    
            canvas.save();    
//          canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));    
            LinearGradient grad1 = new LinearGradient(    
                    ex-(ex-bx)/4,ey-(ey-by)/4,bx,by,0xC9C9C9,R.color.gray3,Shader.TileMode.CLAMP);    
            Paint p1=new Paint();    
            p1.setShader(grad1);    
//          p1.setAlpha(120);    
            canvas.drawPath(this.mBackPagePath,p1);    
            canvas.restore();    
//    
                
      }    
          
      public int getmTimeStep(){    
              
          return mTimeStep;    
      }    
      public void setmTimeStep(int mTimeStep ){    
              
          this.mTimeStep= mTimeStep;    
      }    
      public boolean getmStepping(){    
              
          return mStepping;    
      }    
      public void setmStepping(boolean mStepping ){    
              
          this.mStepping= mStepping;    
      }    
          
      public void setmStepLen(int mStepLen){    
          this.mStepLen=mStepLen;    
      }    
      public int getmStepLen(){    
          return this.mStepLen;    
      }    
          
      public void setmMaxStep(int mMaxStep){    
          this.mMaxStep=mMaxStep;    
      }    
      public int getmMaxStep(){    
          return this.mMaxStep;    
      }    
   
    public void setPreStart(int where)    
    {    
        switch (where)     
        {    
            case NEXT:    
            case LAST:    
                mWhere = where;    
                break;    
                    
            default:    
                mWhere = KEEP;    
                break;    
        }    
            
        isBgInit = true;    
        isBackInit = true;    
            
    }    
        
        
}   

第二个view类pageView.java:

Java代码 
public class PageViewP1 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 PageTurnerViewP1 mPageTurner; 
    private Callback mCallback; 
    private int mCorner; 
    private Drawable mBackPage; 
    private Drawable mPageBackground; 
  
    public PageViewP1(Context context) { 
        super(context); 
    } 
  
    public PageViewP1(Context context, AttributeSet attrs ) { 
        super(context, attrs ); 
  
        this.mBackPage =this.getBackground(); 
        this.mCorner = -1; 
    } 
  
    void setPageTurner(PageTurnerViewP1 pageTurnerViewP1) { 
        this.mPageTurner = pageTurnerViewP1; 
    } 
  
    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(0); 
    } 
  
    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) { 
            Log.v("Callback", "drawing back page"); 
        } 
        public void onDrawBackground(Canvas canvas) { 
            Log.v("Callback2", "drawing back page"); 
        } 
        public void onPageTurnFinished(Canvas canvas) { 
            Log.v("Callback3", "drawing back page"); 
        } 
    } 
} 

分享到:
评论

相关推荐

    android电子书翻页效果

    在Android平台上,为电子书实现逼真的翻页效果...总的来说,Android电子书翻页效果的实现是一个结合了图形学、动画和用户体验设计的综合任务。通过不断学习和实践,开发者可以创造出更出色、更个性化的电子书阅读体验。

    HTML5网页电子书翻页效果

    HTML5网页电子书翻页效果是一种现代化的网页设计技术,旨在提供类似真实书籍的阅读体验。... ... CSS3则为网页设计提供了更多的样式和动画...通过不断优化和创新,这样的电子书翻页效果将继续提升网页阅读的质量和乐趣。

    android 电子书翻页效果

    "android 电子书翻页效果"这个话题涉及到的是如何在Android应用中实现类似纸质书翻页的动画效果,让电子阅读更加生动有趣。下面我们将深入探讨这个主题。 首先,Android中的翻页特效通常是通过自定义View或者使用第...

    Android 3D特效相册+电子书翻页效果

    在Android开发中,3D特效相册和电子书翻页效果是提高用户体验的重要技术手段,尤其是在多媒体应用和阅读类应用中。本项目聚焦于这两项技术的实现,为用户提供更加生动且互动性强的视觉体验。 首先,让我们深入探讨...

    html5基于插件实现的3D电子书翻页效果源码.zip

    这个"html5基于插件实现的3D电子书翻页效果源码"是一个利用HTML5特性和插件创建的互动3D电子书翻页效果示例。这种效果能够模拟真实书籍翻页的感觉,为读者带来更沉浸式的阅读体验。 在HTML5中,实现3D翻页效果通常...

    电子书翻页效果 源文件 FLA

    《电子书翻页效果源文件FLA解析及应用》 电子书作为一种新型的阅读方式,以其便捷性、互动性和丰富的多媒体展示,深受广大用户的喜爱。其中,翻页效果是电子书设计中的一个重要环节,它直接影响到用户的阅读体验。...

    电子书翻页3D效果

    电子书翻页3D效果是一种模拟传统纸质书阅读体验的技术,它通过动态视觉效果使得在屏幕上阅读电子书时,仿佛真的在翻动纸张。这种技术不仅提升了阅读的趣味性,也增强了用户的沉浸感,使得数字化阅读更加贴近实体书籍...

    CSS3简洁版左右翻页电子书效果

    在实践中,创建CSS3电子书翻页效果需要综合运用这些知识点,并不断调整以达到最佳的视觉和交互体验。同时,为了解决浏览器兼容性问题,可以考虑使用成熟的库或框架,如turn.js、bookblock等,它们已经封装好了这些...

    Android 电子书翻页效果(增强了翻页效果,算法可以参考)

    在Android电子书翻页效果中,我们通常会用到二次或三次贝塞尔曲线来模拟书页的边缘形态。 要实现这个功能,我们需要创建一个自定义的View或者 ViewGroup,这个组件负责绘制书页。在绘制过程中,关键在于计算每个帧...

    电子书翻页效果的Flash代码.rar

    在IT行业中,电子书翻页效果的实现是数字出版领域的一个重要组成部分,它为用户提供了一种模拟传统纸质书籍阅读体验的交互方式。本资源提供的"电子书翻页效果的Flash代码"就是一个这样的解决方案,它利用Adobe Flash...

    ios 电子书翻页效果

    在iOS开发中,实现电子书翻页效果是一项挑战性但极具吸引力的任务,它能为用户带来更为真实的阅读体验。本文将深入探讨如何在iOS应用中创建逼真的电子书翻页效果,结合“记得带XIB”这一标签,我们将讨论使用XIB...

    手动拖拽翻页电子书 翻页效果

    拖拽翻页。手动拖拽翻页电子书 翻页效果手动拖拽翻页电子书 翻页效果手动拖拽翻页电子书 翻页效果手动拖拽翻页电子书 翻页效果

    HTML5电子书翻页动画效果.zip

    在电子书翻页效果中,CSS3可能被用来控制书页的弯曲、阴影和旋转效果,使其看起来更加自然。 此外,HTML5的离线存储功能(如localStorage和indexDB)也可能被用于缓存电子书内容,使得用户在没有网络连接的情况下也...

    Android仿照iReader电子书翻页效果实现

    本例子详细讲解怎么在Android中使用java实现翻页效果,就像电子阅读器那样。翻页效果在Android日常开发中已经非常普遍,机密不再是机密,现在来展示两年前写的Demo程序,希望对大家理解这篇文章有一定帮助

    HTML5 book 电子书翻页效果

    "HTML5 book 电子书翻页效果"是利用HTML5技术来模拟传统纸质书籍的翻页体验,使得数字阅读更加生动且具有沉浸感。 这种翻页效果通常基于HTML5的Canvas或SVG元素,以及JavaScript库如jQuery或更专业的图书展示框架,...

    turn.js电子书翻页特效实例

    总的来说,turn.js是一个强大且灵活的工具,可以帮助开发者轻松创建具有专业级翻页效果的电子书和杂志。通过深入理解其工作原理和API,你可以定制出满足各种需求的互动阅读体验。在实践中,不断试验和优化,将turn....

    flash 电子书 翻页效果

    标题中的“Flash电子书翻页效果”指的是使用Adobe Flash技术创建的一种模拟真实书籍翻页体验的数字出版形式。这种技术让电子书不仅具有文本和图像的显示功能,还能通过动态的翻页动画增加互动性和沉浸感,使得阅读...

Global site tag (gtag.js) - Google Analytics