當前位置: 首頁>>代碼示例>>Java>>正文


Java GradientDrawable.draw方法代碼示例

本文整理匯總了Java中android.graphics.drawable.GradientDrawable.draw方法的典型用法代碼示例。如果您正苦於以下問題:Java GradientDrawable.draw方法的具體用法?Java GradientDrawable.draw怎麽用?Java GradientDrawable.draw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.drawable.GradientDrawable的用法示例。


在下文中一共展示了GradientDrawable.draw方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawCurrentPageShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
@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) {

    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:OverlappedWidget.java

示例2: addPulseRing

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void addPulseRing(LatLng latLng) {
    GradientDrawable d = new GradientDrawable();
    d.setShape(GradientDrawable.OVAL);
    d.setSize(500, 500);
    d.setColor(ContextCompat.getColor(this, R.color.pulse_color));

    Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth()
            , d.getIntrinsicHeight()
            , Bitmap.Config.ARGB_8888);

    // Convert the drawable to bitmap
    Canvas canvas = new Canvas(bitmap);
    d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    d.draw(canvas);

    // Radius of the circle
    final int radius = 100;

    // Add the circle to the map
    circle = mMap.addGroundOverlay(new GroundOverlayOptions()
            .position(latLng, 2 * radius).image(BitmapDescriptorFactory.fromBitmap(bitmap)));
}
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:23,代碼來源:Home.java

示例3: drawPathAHorizontalShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * 繪製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);
}
 
開發者ID:AnliaLee,項目名稱:BookPage,代碼行數:22,代碼來源:BookPageView.java

示例4: drawNextPageAreaAndShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
@Override
protected void drawNextPageAreaAndShadow(Canvas canvas) {
    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(mNextPageBitmap, 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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:39,代碼來源:PageWidget.java

示例5: drawNextPageAreaAndShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
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();
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:39,代碼來源:SimulationPageAnim.java

示例6: drawPathALeftShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * 繪製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);
}
 
開發者ID:AnliaLee,項目名稱:BookPage,代碼行數:40,代碼來源:BookPageView.java

示例7: drawPathARightShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
     * 繪製A區域右陰影
     * @param canvas
     */
    private void drawPathARightShadow(Canvas canvas, Path pathA){
        canvas.restore();
        canvas.save();

        float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//view對角線長度
        int left = (int) h.x;
        int right = (int) (h.x + viewDiagonalLength*10);//需要足夠長的長度
        int top;
        int bottom;

        GradientDrawable gradientDrawable;
        if (style.equals(STYLE_TOP_RIGHT)) {
            gradientDrawable = drawableRightTopRight;
            top = (int) (h.y- rPathAShadowDis /2);
            bottom = (int) h.y;
        } else {
            gradientDrawable = drawableRightLowerRight;
            top = (int) h.y;
            bottom = (int) (h.y+ rPathAShadowDis /2);
        }
        gradientDrawable.setBounds(left,top,right,bottom);

        Path mPath = new Path();
        mPath.moveTo(a.x- Math.max(rPathAShadowDis, lPathAShadowDis) /2,a.y);
//        mPath.lineTo(i.x,i.y);
        mPath.lineTo(h.x,h.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(a.y-h.y, a.x-h.x));
        canvas.rotate(mDegrees, h.x, h.y);
        gradientDrawable.draw(canvas);
    }
 
開發者ID:AnliaLee,項目名稱:BookPage,代碼行數:40,代碼來源:BookPageView.java

示例8: drawPathCShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * 繪製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);
}
 
開發者ID:AnliaLee,項目名稱:BookPage,代碼行數:33,代碼來源:BookPageView.java

示例9: drawNextPageAreaAndShadow

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
    mPath2.reset();
    mPath2.moveTo(mBzStart1.x, mBzStart1.y);
    mPath2.lineTo(mBzVertex1.x, mBzVertex1.y);
    mPath2.lineTo(mBzVertex2.x, mBzVertex2.y);
    mPath2.lineTo(mBzStart2.x, mBzStart2.y);
    mPath2.lineTo(mCornerX, mCornerY);
    mPath2.close();

    mDegress = (float) Math.toDegrees(Math.atan2(mBzControl1.x
            - mCornerX, mBzControl2.y - mCornerY));
    int leftx;
    int rightx;
    GradientDrawable mBackShadowDrawable;
    if (mIsRtOrLb) {
        leftx = (int) (mBzStart1.x);
        rightx = (int) (mBzStart1.x + mTouchCornerDis / 4);
        mBackShadowDrawable = mBackDrawableLR;
    } else {
        leftx = (int) (mBzStart1.x - mTouchCornerDis / 4);
        rightx = (int) mBzStart1.x;
        mBackShadowDrawable = mBackDrawableRL;
    }
    canvas.save();
    canvas.clipPath(mPath1);
    canvas.clipPath(mPath2, Region.Op.INTERSECT);
    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.rotate(mDegress, mBzStart1.x, mBzStart1.y);
    // rotate就是旋轉坐標,順時針,默認原點旋轉,可以指定旋轉點,然後按照專選後的的坐標繪製,不會對之前的繪製有影響
    // 其實可以這樣看,我們先按原來坐標繪製出來東西,在把這個東西按照點來旋轉角度,效果是一樣的,我們的陰影繪製在(start.x - touchCornerDic / 4, mHeight, start.x, maxLen)矩形中
    // 最後按照start點來旋轉就可以變成原來當前頁和下一頁的交匯線下麵的陰影 touchCornerDic / 4就是陰影的寬度
    mBackShadowDrawable.setBounds(leftx, (int) mBzStart1.y, rightx,
            (int) (mMaxLength + mBzStart1.y));
    mBackShadowDrawable.draw(canvas);
    canvas.restore();
}
 
開發者ID:1014277960,項目名稱:DailyReader,代碼行數:37,代碼來源:ReadView.java

示例10: drawCurrentBackArea

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
@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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:57,代碼來源:PageWidget.java

示例11: drawCurrentBackArea

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * 繪製翻起頁背麵
 *
 * @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();
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:64,代碼來源:SimulationPageAnim.java

示例12: drawCurrentBackArea

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * 繪製翻起頁背麵
 *
 * @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();
}
 
開發者ID:guoxiaoxing,項目名稱:android-open-source-project-analysis,代碼行數:64,代碼來源:PageView.java

示例13: drawCurrentBackArea

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * 繪製翻起頁背麵
 *
 * @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);
    //對Bitmap進行取色
    int color = bitmap.getPixel(1, 1);
    //獲取對應的三色
    int red = (color & 0xff0000) >> 16;
    int green = (color & 0x00ff00) >> 8;
    int blue = (color & 0x0000ff);
    //轉換成含有透明度的顏色
    int tempColor = Color.argb(200, red, green, blue);


    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.drawColor(tempColor);

    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();
}
 
開發者ID:newbiechen1024,項目名稱:NovelReader,代碼行數:74,代碼來源:SimulationPageAnim.java


注:本文中的android.graphics.drawable.GradientDrawable.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。