Java Code Examples for android.graphics.drawable.GradientDrawable#draw()

The following examples show how to use android.graphics.drawable.GradientDrawable#draw() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoundCornerIndicaor.java    From FlycoPageIndicator with MIT License 6 votes vote down vote up
private void drawUnselect(Canvas canvas, int count, int verticalOffset, int horizontalOffset) {
    for (int i = 0; i < count; i++) {
        Rect rect = unselectRects.get(i);
        rect.left = horizontalOffset + (indicatorWidth + indicatorGap) * i;
        rect.top = verticalOffset;
        rect.right = rect.left + indicatorWidth;
        rect.bottom = rect.top + indicatorHeight;

        GradientDrawable unselectDrawable = unselectDrawables.get(i);
        unselectDrawable.setCornerRadius(cornerRadius);
        unselectDrawable.setColor(unselectColor);
        unselectDrawable.setStroke(strokeWidth, strokeColor);
        unselectDrawable.setBounds(rect);
        unselectDrawable.draw(canvas);
    }
}
 
Example 2
Source File: BookPageView.java    From BookPage with MIT License 6 votes vote down vote up
/**
 * 绘制A区域水平翻页阴影
 * @param canvas
 */
private void drawPathAHorizontalShadow(Canvas canvas, Path pathA){
    canvas.restore();
    canvas.save();
    canvas.clipPath(pathA, Region.Op.INTERSECT);

    int maxShadowWidth = 30;//阴影矩形最大的宽度
    int left = (int) (a.x - Math.min(maxShadowWidth,(rPathAShadowDis/2)));
    int right = (int) (a.x);
    int top = 0;
    int bottom = viewHeight;
    GradientDrawable gradientDrawable = drawableHorizontalLowerRight;
    gradientDrawable.setBounds(left,top,right,bottom);

    float mDegrees = (float) Math.toDegrees(Math.atan2(f.x-a.x,f.y-h.y));
    canvas.rotate(mDegrees, a.x, a.y);
    gradientDrawable.draw(canvas);
}
 
Example 3
Source File: CirclePageIndicator.java    From JianshuApp with GNU General Public License v3.0 6 votes vote down vote up
private void drawUnselect(Canvas canvas, int count, int verticalOffset, int horizontalOffset) {
    for (int i = 0; i < count; i++) {
        Rect rect = unselectRects.get(i);
        rect.left = horizontalOffset + (indicatorWidth + indicatorGap) * i;
        rect.top = verticalOffset;
        rect.right = rect.left + indicatorWidth;
        rect.bottom = rect.top + indicatorHeight;

        GradientDrawable unselectDrawable = unselectDrawables.get(i);
        unselectDrawable.setCornerRadius(cornerRadius);
        unselectDrawable.setColor(unselectColor);
        unselectDrawable.setStroke(strokeWidth, strokeColor);
        unselectDrawable.setBounds(rect);
        unselectDrawable.draw(canvas);
    }
}
 
Example 4
Source File: BookPageView.java    From CrawlerForReader with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制A区域水平翻页阴影
 *
 * @param canvas
 */
private void drawPathAHorizontalShadow(Canvas canvas, Path pathA) {
    canvas.restore();
    canvas.save();
    canvas.clipPath(pathA, Region.Op.INTERSECT);

    int maxShadowWidth = 30;//阴影矩形最大的宽度
    int left = (int) (a.x - Math.min(maxShadowWidth, (rPathAShadowDis / 2)));
    int right = (int) (a.x);
    int top = 0;
    int bottom = viewHeight;
    GradientDrawable gradientDrawable = drawableHorizontalLowerRight;
    gradientDrawable.setBounds(left, top, right, bottom);

    float mDegrees = (float) Math.toDegrees(Math.atan2(f.x - a.x, f.y - h.y));
    canvas.rotate(mDegrees, a.x, a.y);
    gradientDrawable.draw(canvas);
}
 
Example 5
Source File: LLand.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(Canvas c) {
    final int w = c.getWidth();
    final int h = c.getHeight();
    final GradientDrawable g = new GradientDrawable();
    g.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);
    g.setGradientCenter(w * 0.75f, 0);
    g.setColors(new int[] { 0xFFFFFFFF, 0xFFAAAAAA });
    g.setBounds(0, 0, w, h);
    g.draw(c);
    if (!mDrawShadow) return;
    mShadow.reset();
    mShadow.moveTo(0,0);
    mShadow.lineTo(w, 0);
    mShadow.lineTo(w, PARAMS.OBSTACLE_WIDTH/2+w*1.5f);
    mShadow.lineTo(0, PARAMS.OBSTACLE_WIDTH/2);
    mShadow.close();
    c.drawPath(mShadow, mPaint);
}
 
Example 6
Source File: OverlappedWidget.java    From fangzhuishushenqi with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawCurrentPageShadow(Canvas canvas) {
    canvas.save();
    GradientDrawable shadow;
    if (actiondownX > mScreenWidth >> 1) {
        shadow = mBackShadowDrawableLR;
        shadow.setBounds((int) (mScreenWidth + touch_down - 5), 0, (int) (mScreenWidth + touch_down + 5), mScreenHeight);

    } else {
        shadow = mBackShadowDrawableRL;
        shadow.setBounds((int) (touch_down - 5), 0, (int) (touch_down + 5), mScreenHeight);
    }
    shadow.draw(canvas);
    try {
        canvas.restore();
    } catch (Exception e) {

    }
}
 
Example 7
Source File: BookPageView.java    From BookPage with MIT License 5 votes vote down vote up
/**
 * 绘制B区域阴影,阴影左深右浅
 * @param canvas
 */
private void drawPathBShadow(Canvas canvas){
    int deepOffset = 0;//深色端的偏移值
    int lightOffset = 0;//浅色端的偏移值
    float aTof =(float) Math.hypot((a.x - f.x),(a.y - f.y));//a到f的距离
    float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//对角线长度

    int left;
    int right;
    int top = (int) c.y;
    int bottom = (int) (viewDiagonalLength + c.y);
    GradientDrawable gradientDrawable;
    if(style.equals(STYLE_TOP_RIGHT)){//f点在右上角
        //从左向右线性渐变
        gradientDrawable = drawableBTopRight;

        left = (int) (c.x - deepOffset);//c点位于左上角
        right = (int) (c.x + aTof/4 + lightOffset);
    }else {
        //从右向左线性渐变
        gradientDrawable = drawableBLowerRight;

        left = (int) (c.x - aTof/4 - lightOffset);//c点位于左下角
        right = (int) (c.x + deepOffset);
    }
    gradientDrawable.setBounds(left,top,right,bottom);//设置阴影矩形

    float rotateDegrees = (float) Math.toDegrees(Math.atan2(e.x- f.x, h.y - f.y));//旋转角度
    canvas.rotate(rotateDegrees, c.x, c.y);//以c为中心点旋转
    gradientDrawable.draw(canvas);
}
 
Example 8
Source File: BookPageView.java    From BookPage with MIT License 5 votes vote down vote up
/**
 * 绘制A区域左阴影
 * @param canvas
 */
private void drawPathALeftShadow(Canvas canvas, Path pathA){
    canvas.restore();
    canvas.save();

    int left;
    int right;
    int top = (int) e.y;
    int bottom = (int) (e.y+viewHeight);

    GradientDrawable gradientDrawable;
    if (style.equals(STYLE_TOP_RIGHT)) {
        gradientDrawable = drawableLeftTopRight;
        left = (int) (e.x - lPathAShadowDis /2);
        right = (int) (e.x);
    } else {
        gradientDrawable = drawableLeftLowerRight;
        left = (int) (e.x);
        right = (int) (e.x + lPathAShadowDis /2);
    }

    Path mPath = new Path();
    mPath.moveTo(a.x- Math.max(rPathAShadowDis, lPathAShadowDis) /2,a.y);
    mPath.lineTo(d.x,d.y);
    mPath.lineTo(e.x,e.y);
    mPath.lineTo(a.x,a.y);
    mPath.close();
    canvas.clipPath(pathA);
    canvas.clipPath(mPath, Region.Op.INTERSECT);

    float mDegrees = (float) Math.toDegrees(Math.atan2(e.x-a.x, a.y-e.y));
    canvas.rotate(mDegrees, e.x, e.y);

    gradientDrawable.setBounds(left,top,right,bottom);
    gradientDrawable.draw(canvas);
}
 
Example 9
Source File: SimulationPageAnim.java    From NovelReader with MIT License 5 votes vote down vote up
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
    mPath1.reset();
    mPath1.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
    mPath1.lineTo(mCornerX, mCornerY);
    mPath1.close();

    mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x
            - mCornerX, mBezierControl2.y - mCornerY));
    int leftx;
    int rightx;
    GradientDrawable mBackShadowDrawable;
    if (mIsRTandLB) {  //左下及右上
        leftx = (int) (mBezierStart1.x);
        rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4);
        mBackShadowDrawable = mBackShadowDrawableLR;
    } else {
        leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4);
        rightx = (int) mBezierStart1.x;
        mBackShadowDrawable = mBackShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }


    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx,
            (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形
    mBackShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 10
Source File: SimulationPageAnim.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
    mPath1.reset();
    mPath1.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
    mPath1.lineTo(mCornerX, mCornerY);
    mPath1.close();

    mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x
            - mCornerX, mBezierControl2.y - mCornerY));
    int leftx;
    int rightx;
    GradientDrawable mBackShadowDrawable;
    if (mIsRTandLB) {  //左下及右上
        leftx = (int) (mBezierStart1.x);
        rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4);
        mBackShadowDrawable = mBackShadowDrawableLR;
    } else {
        leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4);
        rightx = (int) mBezierStart1.x;
        mBackShadowDrawable = mBackShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }


    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx,
            (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形
    mBackShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 11
Source File: BookPageView.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
/**
 * 绘制C区域阴影,阴影左浅右深
 *
 * @param canvas
 */
private void drawPathCShadow(Canvas canvas) {
    int deepOffset = 1;//深色端的偏移值
    int lightOffset = -30;//浅色端的偏移值
    float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//view对角线长度
    int midpoint_ce = (int) (c.x + e.x) / 2;//ce中点
    int midpoint_jh = (int) (j.y + h.y) / 2;//jh中点
    float minDisToControlPoint = Math.min(Math.abs(midpoint_ce - e.x), Math.abs(midpoint_jh - h.y));//中点到控制点的最小值

    int left;
    int right;
    int top = (int) c.y;
    int bottom = (int) (viewDiagonalLength + c.y);
    GradientDrawable gradientDrawable;
    if (style.equals(STYLE_TOP_RIGHT)) {
        gradientDrawable = drawableCTopRight;
        left = (int) (c.x - lightOffset);
        right = (int) (c.x + minDisToControlPoint + deepOffset);
    } else {
        gradientDrawable = drawableCLowerRight;
        left = (int) (c.x - minDisToControlPoint - deepOffset);
        right = (int) (c.x + lightOffset);
    }
    gradientDrawable.setBounds(left, top, right, bottom);

    float mDegrees = (float) Math.toDegrees(Math.atan2(e.x - f.x, h.y - f.y));
    canvas.rotate(mDegrees, c.x, c.y);
    gradientDrawable.draw(canvas);
}
 
Example 12
Source File: SimulationPageAnim.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
    mPath1.reset();
    mPath1.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath1.lineTo(mBezierVertex1.x, mBezierVertex1.y);
    mPath1.lineTo(mBezierVertex2.x, mBezierVertex2.y);
    mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
    mPath1.lineTo(mCornerX, mCornerY);
    mPath1.close();

    mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x
            - mCornerX, mBezierControl2.y - mCornerY));
    int leftx;
    int rightx;
    GradientDrawable mBackShadowDrawable;
    if (mIsRTandLB) {  //左下及右上
        leftx = (int) (mBezierStart1.x);
        rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4);
        mBackShadowDrawable = mBackShadowDrawableLR;
    } else {
        leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4);
        rightx = (int) mBezierStart1.x;
        mBackShadowDrawable = mBackShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            canvas.clipPath(mPath1);
        } else {
            canvas.clipPath(mPath1, Region.Op.INTERSECT);
        }
    } catch (Exception ignored) {
    }


    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx,
            (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形
    mBackShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 13
Source File: SimulationPageAnim.java    From FriendBook with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 绘制翻起页背面
 *
 * @param canvas
 * @param bitmap
 */
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouchX, mTouchY);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRTandLB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }


    mPaint.setColorFilter(mColorMatrixFilter);

    float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
            mBezierControl2.y - mCornerY);
    float f8 = (mCornerX - mBezierControl1.x) / dis;
    float f9 = (mBezierControl2.y - mCornerY) / dis;
    mMatrixArray[0] = 1 - 2 * f9 * f9;
    mMatrixArray[1] = 2 * f8 * f9;
    mMatrixArray[3] = mMatrixArray[1];
    mMatrixArray[4] = 1 - 2 * f8 * f8;
    mMatrix.reset();
    mMatrix.setValues(mMatrixArray);
    mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
    mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
    canvas.drawBitmap(bitmap, mMatrix, mPaint);
    // canvas.drawBitmap(bitmap, mMatrix, null);
    mPaint.setColorFilter(null);

    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
            (int) (mBezierStart1.y + mMaxLength));
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 14
Source File: SimulationPageAnim.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 绘制翻起页背面
 */
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBezierVertex2.x, mBezierVertex2.y);
    mPath1.lineTo(mBezierVertex1.x, mBezierVertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouchX, mTouchY);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRTandLB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            canvas.clipPath(mPath1);
        } else {
            canvas.clipPath(mPath1, Region.Op.INTERSECT);
        }
    } catch (Exception ignored) {
    }

    //对Bitmap进行取色
    int color = bitmap.getPixel(ScreenUtils.dpToPx(10), ScreenUtils.dpToPx(10));
    canvas.drawColor(color);

    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
            (int) (mBezierStart1.y + mMaxLength));
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 15
Source File: PageWidget.java    From coolreader with MIT License 4 votes vote down vote up
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouch.x, mTouch.y);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRTandLB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    canvas.clipPath(mPath0);
    canvas.clipPath(mPath1, Region.Op.INTERSECT);

    mPaint.setColorFilter(mColorMatrixFilter);

    float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
            mBezierControl2.y - mCornerY);
    float f8 = (mCornerX - mBezierControl1.x) / dis;
    float f9 = (mBezierControl2.y - mCornerY) / dis;
    mMatrixArray[0] = 1 - 2 * f9 * f9;
    mMatrixArray[1] = 2 * f8 * f9;
    mMatrixArray[3] = mMatrixArray[1];
    mMatrixArray[4] = 1 - 2 * f8 * f8;
    mMatrix.reset();
    mMatrix.setValues(mMatrixArray);
    mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
    mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
    canvas.drawBitmap(bitmap, mMatrix, mPaint);
    mPaint.setColorFilter(null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
            (int) (mBezierStart1.y + mDisplayMaxLength));
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 16
Source File: PageWidget.java    From BookReader with Apache License 2.0 4 votes vote down vote up
@Override
protected void drawCurrentBackArea(Canvas canvas) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouch.x, mTouch.y);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRTandLB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }

    mPaint.setColorFilter(mColorMatrixFilter);

    float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
            mBezierControl2.y - mCornerY);
    float f8 = (mCornerX - mBezierControl1.x) / dis;
    float f9 = (mBezierControl2.y - mCornerY) / dis;
    mMatrixArray[0] = 1 - 2 * f9 * f9;
    mMatrixArray[1] = 2 * f8 * f9;
    mMatrixArray[3] = mMatrixArray[1];
    mMatrixArray[4] = 1 - 2 * f8 * f8;
    mMatrix.reset();
    mMatrix.setValues(mMatrixArray);
    mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
    mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
    canvas.drawBitmap(mCurPageBitmap, mMatrix, mPaint);
    // canvas.drawBitmap(bitmap, mMatrix, null);
    mPaint.setColorFilter(null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
            (int) (mBezierStart1.y + mMaxLength));
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 17
Source File: SimulationPageAnim.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 绘制翻起页背面
 */
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBezierVertex2.x, mBezierVertex2.y);
    mPath1.lineTo(mBezierVertex1.x, mBezierVertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouchX, mTouchY);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRT_LB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            canvas.clipPath(mPath1);
        } else {
            canvas.clipPath(mPath1, Region.Op.INTERSECT);
        }
    } catch (Exception ignored) {
    }

    mPaint.setColorFilter(mColorMatrixFilter);

    float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
            mBezierControl2.y - mCornerY);
    float f8 = (mCornerX - mBezierControl1.x) / dis;
    float f9 = (mBezierControl2.y - mCornerY) / dis;
    mMatrixArray[0] = 1 - 2 * f9 * f9;
    mMatrixArray[1] = 2 * f8 * f9;
    mMatrixArray[3] = mMatrixArray[1];
    mMatrixArray[4] = 1 - 2 * f8 * f8;
    mMatrix.reset();
    mMatrix.setValues(mMatrixArray);
    mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
    mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
    canvas.drawBitmap(bitmap, mMatrix, mPaint);

    mPaint.setColorFilter(null);

    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(
            left, (int) mBezierStart1.y,
            right, (int) (mBezierStart1.y + mMaxLength)
    );
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 18
Source File: PageWidget.java    From Jreader with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 绘制翻起页背面
 *
 * @param canvas
 * @param bitmap
 */
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouch.x, mTouch.y);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRTandLB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }


    mPaint.setColorFilter(mColorMatrixFilter);

    float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
            mBezierControl2.y - mCornerY);
    float f8 = (mCornerX - mBezierControl1.x) / dis;
    float f9 = (mBezierControl2.y - mCornerY) / dis;
    mMatrixArray[0] = 1 - 2 * f9 * f9;
    mMatrixArray[1] = 2 * f8 * f9;
    mMatrixArray[3] = mMatrixArray[1];
    mMatrixArray[4] = 1 - 2 * f8 * f8;
    mMatrix.reset();
    mMatrix.setValues(mMatrixArray);
    mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
    mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
    canvas.drawBitmap(bitmap, mMatrix, mPaint);
    // canvas.drawBitmap(bitmap, mMatrix, null);
    mPaint.setColorFilter(null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
            (int) (mBezierStart1.y + mMaxLength));
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 19
Source File: pageView.java    From Jreader with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 绘制翻起页背面
 *
 * @param canvas
 * @param bitmap
 */
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouch.x, mTouch.y);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRTandLB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }


    mPaint.setColorFilter(mColorMatrixFilter);

    float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
            mBezierControl2.y - mCornerY);
    float f8 = (mCornerX - mBezierControl1.x) / dis;
    float f9 = (mBezierControl2.y - mCornerY) / dis;
    mMatrixArray[0] = 1 - 2 * f9 * f9;
    mMatrixArray[1] = 2 * f8 * f9;
    mMatrixArray[3] = mMatrixArray[1];
    mMatrixArray[4] = 1 - 2 * f8 * f8;
    mMatrix.reset();
    mMatrix.setValues(mMatrixArray);
    mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
    mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
    canvas.drawBitmap(bitmap, mMatrix, mPaint);
    // canvas.drawBitmap(bitmap, mMatrix, null);
    mPaint.setColorFilter(null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
            (int) (mBezierStart1.y + mMaxLength));
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 20
Source File: SimulationPageAnim.java    From a with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 绘制翻起页背面
 */
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
    int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
    float f1 = Math.abs(i - mBezierControl1.x);
    int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
    float f2 = Math.abs(i1 - mBezierControl2.y);
    float f3 = Math.min(f1, f2);
    mPath1.reset();
    mPath1.moveTo(mBezierVertex2.x, mBezierVertex2.y);
    mPath1.lineTo(mBezierVertex1.x, mBezierVertex1.y);
    mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
    mPath1.lineTo(mTouchX, mTouchY);
    mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath1.close();
    GradientDrawable mFolderShadowDrawable;
    int left;
    int right;
    if (mIsRTandLB) {
        left = (int) (mBezierStart1.x - 1);
        right = (int) (mBezierStart1.x + f3 + 1);
        mFolderShadowDrawable = mFolderShadowDrawableLR;
    } else {
        left = (int) (mBezierStart1.x - f3 - 1);
        right = (int) (mBezierStart1.x + 1);
        mFolderShadowDrawable = mFolderShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            canvas.clipPath(mPath1);
        } else {
            canvas.clipPath(mPath1, Region.Op.INTERSECT);
        }
    } catch (Exception ignored) { }

    mPaint.setColorFilter(mColorMatrixFilter);

    float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
            mBezierControl2.y - mCornerY);
    float f8 = (mCornerX - mBezierControl1.x) / dis;
    float f9 = (mBezierControl2.y - mCornerY) / dis;
    mMatrixArray[0] = 1 - 2 * f9 * f9;
    mMatrixArray[1] = 2 * f8 * f9;
    mMatrixArray[3] = mMatrixArray[1];
    mMatrixArray[4] = 1 - 2 * f8 * f8;
    mMatrix.reset();
    mMatrix.setValues(mMatrixArray);
    mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
    mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
    canvas.drawBitmap(bitmap, mMatrix, mPaint);

    mPaint.setColorFilter(null);

    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
            (int) (mBezierStart1.y + mMaxLength));
    mFolderShadowDrawable.draw(canvas);
    canvas.restore();
}