Search in sources :

Example 56 with LinearGradient

use of android.graphics.LinearGradient in project JustAndroid by chinaltz.

the class AbHorizontalProgressBar method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (reset) {
        canvas.drawColor(Color.TRANSPARENT);
        reset = false;
    }
    this.width = getMeasuredWidth();
    this.height = getMeasuredHeight();
    // 设置画笔颜色
    pathPaint.setColor(pathColor);
    // 设置画笔宽度
    pathPaint.setStrokeWidth(pathWidth);
    //添加浮雕效果
    pathPaint.setMaskFilter(emboss);
    canvas.drawRect(0, 0, this.width, this.height, pathPaint);
    pathPaint.setColor(pathBorderColor);
    canvas.drawRect(0, 0, this.width, this.height, pathPaint);
    LinearGradient linearGradient = new LinearGradient(0, 0, this.width, this.height, fillColors[0], fillColors[1], TileMode.CLAMP);
    fillPaint.setShader(linearGradient);
    //模糊效果
    fillPaint.setMaskFilter(mBlur);
    //设置线的类型,边是圆的
    fillPaint.setStrokeCap(Paint.Cap.ROUND);
    fillPaint.setStrokeWidth(pathWidth);
    canvas.drawRect(0, 0, ((float) progress / max) * this.width, this.height, fillPaint);
}
Also used : LinearGradient(android.graphics.LinearGradient)

Example 57 with LinearGradient

use of android.graphics.LinearGradient in project android_frameworks_base by crdroidandroid.

the class FakeShadowDrawable method buildShadowCorners.

private void buildShadowCorners() {
    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);
    if (mCornerShadowPath == null) {
        mCornerShadowPath = new Path();
    } else {
        mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();
    float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
    mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP));
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) RadialGradient(android.graphics.RadialGradient)

Example 58 with LinearGradient

use of android.graphics.LinearGradient in project android_frameworks_base by crdroidandroid.

the class RectShadowPainter method paintShadow.

public static void paintShadow(Outline viewOutline, float elevation, Canvas canvas) {
    Rect outline = new Rect();
    if (!viewOutline.getRect(outline)) {
        throw new IllegalArgumentException("Outline is not a rect shadow");
    }
    float shadowSize = elevationToShadow(elevation);
    int saved = modifyCanvas(canvas, shadowSize);
    if (saved == -1) {
        return;
    }
    try {
        Paint cornerPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        cornerPaint.setStyle(Style.FILL);
        Paint edgePaint = new Paint(cornerPaint);
        edgePaint.setAntiAlias(false);
        float radius = viewOutline.getRadius();
        float outerArcRadius = radius + shadowSize;
        int[] colors = { START_COLOR, START_COLOR, END_COLOR };
        cornerPaint.setShader(new RadialGradient(0, 0, outerArcRadius, colors, new float[] { 0f, radius / outerArcRadius, 1f }, TileMode.CLAMP));
        edgePaint.setShader(new LinearGradient(0, 0, -shadowSize, 0, START_COLOR, END_COLOR, TileMode.CLAMP));
        Path path = new Path();
        path.setFillType(FillType.EVEN_ODD);
        // A rectangle bounding the complete shadow.
        RectF shadowRect = new RectF(outline);
        shadowRect.inset(-shadowSize, -shadowSize);
        // A rectangle with edges corresponding to the straight edges of the outline.
        RectF inset = new RectF(outline);
        inset.inset(radius, radius);
        // A rectangle used to represent the edge shadow.
        RectF edgeShadowRect = new RectF();
        // left and right sides.
        edgeShadowRect.set(-shadowSize, 0f, 0f, inset.height());
        // Left shadow
        sideShadow(canvas, edgePaint, edgeShadowRect, outline.left, inset.top, 0);
        // Right shadow
        sideShadow(canvas, edgePaint, edgeShadowRect, outline.right, inset.bottom, 2);
        // Top shadow
        edgeShadowRect.set(-shadowSize, 0, 0, inset.width());
        sideShadow(canvas, edgePaint, edgeShadowRect, inset.right, outline.top, 1);
        // bottom shadow. This needs an inset so that blank doesn't appear when the content is
        // moved up.
        edgeShadowRect.set(-shadowSize, 0, shadowSize / 2f, inset.width());
        edgePaint.setShader(new LinearGradient(edgeShadowRect.right, 0, edgeShadowRect.left, 0, colors, new float[] { 0f, 1 / 3f, 1f }, TileMode.CLAMP));
        sideShadow(canvas, edgePaint, edgeShadowRect, inset.left, outline.bottom, 3);
        // Draw corners.
        drawCorner(canvas, cornerPaint, path, inset.right, inset.bottom, outerArcRadius, 0);
        drawCorner(canvas, cornerPaint, path, inset.left, inset.bottom, outerArcRadius, 1);
        drawCorner(canvas, cornerPaint, path, inset.left, inset.top, outerArcRadius, 2);
        drawCorner(canvas, cornerPaint, path, inset.right, inset.top, outerArcRadius, 3);
    } finally {
        canvas.restoreToCount(saved);
    }
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Rect(android.graphics.Rect) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 59 with LinearGradient

use of android.graphics.LinearGradient in project android_frameworks_base by crdroidandroid.

the class MinimizedDockShadow method updatePaint.

private void updatePaint(int left, int top, int right, int bottom) {
    int startColor = mContext.getResources().getColor(R.color.minimize_dock_shadow_start, null);
    int endColor = mContext.getResources().getColor(R.color.minimize_dock_shadow_end, null);
    final int middleColor = Color.argb((Color.alpha(startColor) + Color.alpha(endColor)) / 2, 0, 0, 0);
    final int quarter = Color.argb((int) (Color.alpha(startColor) * 0.25f + Color.alpha(endColor) * 0.75f), 0, 0, 0);
    if (mDockSide == WindowManager.DOCKED_TOP) {
        mShadowPaint.setShader(new LinearGradient(0, 0, 0, bottom - top, new int[] { startColor, middleColor, quarter, endColor }, new float[] { 0f, 0.35f, 0.6f, 1f }, Shader.TileMode.CLAMP));
    } else if (mDockSide == WindowManager.DOCKED_LEFT) {
        mShadowPaint.setShader(new LinearGradient(0, 0, right - left, 0, new int[] { startColor, middleColor, quarter, endColor }, new float[] { 0f, 0.35f, 0.6f, 1f }, Shader.TileMode.CLAMP));
    } else if (mDockSide == WindowManager.DOCKED_RIGHT) {
        mShadowPaint.setShader(new LinearGradient(right - left, 0, 0, 0, new int[] { startColor, middleColor, quarter, endColor }, new float[] { 0f, 0.35f, 0.6f, 1f }, Shader.TileMode.CLAMP));
    }
}
Also used : LinearGradient(android.graphics.LinearGradient) Paint(android.graphics.Paint)

Example 60 with LinearGradient

use of android.graphics.LinearGradient in project book-animation by briangriffey.

the class PageTurnLayout method draw.

@Override
public void draw(Canvas canvas) {
    if (mLastTouchPoint != null && mIsTurning && mDirection != null) {
        View topView;
        View bottomView;
        if (mDirection == PageTurnDirection.LEFT) {
            topView = getChildAt(mCurrentPage);
            bottomView = getChildAt(mCurrentPage + 1);
        } else {
            topView = getChildAt(mCurrentPage - 1);
            bottomView = getChildAt(mCurrentPage);
        }
        int height = getMeasuredHeight();
        int width = getMeasuredWidth();
        int halfWidth = (int) (width * .5);
        int distanceToEnd = width - mLastTouchPoint.x;
        int backOfPageWidth = Math.min(halfWidth, distanceToEnd / 2);
        int shadowLength = Math.max(5, backOfPageWidth / 20);
        // The rect that represents the backofthepage
        Rect backOfPageRect = new Rect(mLastTouchPoint.x, 0, mLastTouchPoint.x + backOfPageWidth, height);
        // The along the crease of the turning page
        Rect shadowRect = new Rect(mLastTouchPoint.x - shadowLength, 0, mLastTouchPoint.x, height);
        // The shadow cast onto the next page by teh turning page
        Rect backShadowRect = new Rect(backOfPageRect.right, 0, backOfPageRect.right + (backOfPageWidth / 2), height);
        // set the top view to be the current page to the crease of the
        // turning page
        mTopViewRect.set(0, 0, mLastTouchPoint.x, getMeasuredHeight());
        mBottomViewRect.set(backOfPageRect.right, 0, width, height);
        canvas.save();
        // clip and draw the top page to your touch
        canvas.clipRect(mTopViewRect);
        topView.draw(canvas);
        canvas.restore();
        // clip and draw the first shadow
        canvas.save();
        canvas.clipRect(shadowRect);
        mPaint.setShader(new LinearGradient(shadowRect.left, shadowRect.top, shadowRect.right, shadowRect.top, 0x00000000, 0x44000000, Shader.TileMode.REPEAT));
        canvas.drawPaint(mPaint);
        canvas.restore();
        mPaint.setShader(null);
        // clip and draw the gradient that makes the page look bent
        canvas.save();
        canvas.clipRect(backOfPageRect);
        mPaint.setShadowLayer(0, 0, 0, 0x00000000);
        mPaint.setShader(new LinearGradient(backOfPageRect.left, backOfPageRect.top, backOfPageRect.right, backOfPageRect.top, new int[] { 0xFFEEEEEE, 0xFFDDDDDD, 0xFFEEEEEE, 0xFFD6D6D6 }, new float[] { .35f, .73f, 9f, 1.0f }, Shader.TileMode.REPEAT));
        canvas.drawPaint(mPaint);
        canvas.restore();
        // draw the second page in the remaining space
        canvas.save();
        canvas.clipRect(mBottomViewRect);
        bottomView.draw(canvas);
        canvas.restore();
        // now draw a shadow
        if (backShadowRect.left > 0) {
            canvas.save();
            canvas.clipRect(backShadowRect);
            mPaint.setShader(new LinearGradient(backShadowRect.left, backShadowRect.top, backShadowRect.right, backShadowRect.top, 0x44000000, 0x00000000, Shader.TileMode.REPEAT));
            canvas.drawPaint(mPaint);
            // canvas.drawColor(0xFF000000);
            canvas.restore();
        }
    } else {
        getChildAt(mCurrentPage).draw(canvas);
    }
}
Also used : LinearGradient(android.graphics.LinearGradient) Rect(android.graphics.Rect) View(android.view.View) Paint(android.graphics.Paint) Point(android.graphics.Point)

Aggregations

LinearGradient (android.graphics.LinearGradient)123 Paint (android.graphics.Paint)70 RectF (android.graphics.RectF)38 RadialGradient (android.graphics.RadialGradient)27 Canvas (android.graphics.Canvas)22 Rect (android.graphics.Rect)21 Path (android.graphics.Path)18 Shader (android.graphics.Shader)18 Bitmap (android.graphics.Bitmap)15 Matrix (android.graphics.Matrix)15 Point (android.graphics.Point)13 SweepGradient (android.graphics.SweepGradient)12 PorterDuffXfermode (android.graphics.PorterDuffXfermode)9 ShapeDrawable (android.graphics.drawable.ShapeDrawable)9 SuppressLint (android.annotation.SuppressLint)6 ComposeShader (android.graphics.ComposeShader)6 PaintDrawable (android.graphics.drawable.PaintDrawable)5 RectShape (android.graphics.drawable.shapes.RectShape)5 ColorMatrix (android.graphics.ColorMatrix)3 PointF (android.graphics.PointF)3