Search in sources :

Example 26 with RadialGradient

use of android.graphics.RadialGradient in project XCL-Charts by xcltapestry.

the class PieChart method renderRadialGradient.

/**
 * 给画笔设置渲染颜色和效果
 * @param paintArc	画笔
 * @param cirX		中心点X坐标
 * @param cirY		中心点Y坐标
 * @param radius	半径
 * @return	返回渲染效果类
 */
private RadialGradient renderRadialGradient(Paint paintArc, float cirX, float cirY, float radius) {
    float radialRadius = radius * 0.8f;
    int color = paintArc.getColor();
    int darkerColor = DrawHelper.getInstance().getDarkerColor(color);
    RadialGradient radialGradient = new RadialGradient(cirX, cirY, radialRadius, darkerColor, color, Shader.TileMode.MIRROR);
    // 返回环形渐变
    return radialGradient;
}
Also used : RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint)

Example 27 with RadialGradient

use of android.graphics.RadialGradient in project platform_frameworks_base by android.

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 28 with RadialGradient

use of android.graphics.RadialGradient in project VirtualApp by asLody.

the class RippleButton method setRadius.

public void setRadius(final float radius) {
    mRadius = radius;
    if (mRadius > 0) {
        mRadialGradient = new RadialGradient(mDownX, mDownY, mRadius, adjustAlpha(mRippleColor, mAlphaFactor), mRippleColor, Shader.TileMode.MIRROR);
        mPaint.setShader(mRadialGradient);
    }
    invalidate();
}
Also used : RadialGradient(android.graphics.RadialGradient)

Example 29 with RadialGradient

use of android.graphics.RadialGradient in project UltimateAndroid by cymcsg.

the class ShimmerFrameLayout method getMaskBitmap.

// Return the mask bitmap, creating it if necessary.
private Bitmap getMaskBitmap() {
    if (mMaskBitmap != null) {
        return mMaskBitmap;
    }
    int width = mMask.maskWidth(getWidth());
    int height = mMask.maskHeight(getHeight());
    mMaskBitmap = createBitmapAndGcIfNecessary(width, height);
    Canvas canvas = new Canvas(mMaskBitmap);
    Shader gradient;
    switch(mMask.shape) {
        default:
        case LINEAR:
            {
                int x1, y1;
                int x2, y2;
                switch(mMask.angle) {
                    default:
                    case CW_0:
                        x1 = 0;
                        y1 = 0;
                        x2 = width;
                        y2 = 0;
                        break;
                    case CW_90:
                        x1 = 0;
                        y1 = 0;
                        x2 = 0;
                        y2 = height;
                        break;
                    case CW_180:
                        x1 = width;
                        y1 = 0;
                        x2 = 0;
                        y2 = 0;
                        break;
                    case CW_270:
                        x1 = 0;
                        y1 = height;
                        x2 = 0;
                        y2 = 0;
                        break;
                }
                gradient = new LinearGradient(x1, y1, x2, y2, mMask.getGradientColors(), mMask.getGradientPositions(), Shader.TileMode.REPEAT);
                break;
            }
        case RADIAL:
            {
                int x = width / 2;
                int y = height / 2;
                gradient = new RadialGradient(x, y, (float) (Math.max(width, height) / Math.sqrt(2)), mMask.getGradientColors(), mMask.getGradientPositions(), Shader.TileMode.REPEAT);
                break;
            }
    }
    canvas.rotate(mMask.tilt, width / 2, height / 2);
    Paint paint = new Paint();
    paint.setShader(gradient);
    // We need to increase the rect size to account for the tilt
    int padding = (int) (Math.sqrt(2) * Math.max(width, height)) / 2;
    canvas.drawRect(-padding, -padding, width + padding, height + padding, paint);
    return mMaskBitmap;
}
Also used : LinearGradient(android.graphics.LinearGradient) Canvas(android.graphics.Canvas) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint) Shader(android.graphics.Shader) Paint(android.graphics.Paint)

Example 30 with RadialGradient

use of android.graphics.RadialGradient in project CustomShapeImageView by MostafaGazar.

the class SVGHandlerTest method testParseRadialGradient_xlink.

@Test
public void testParseRadialGradient_xlink() throws Exception {
    //given
    when(picture.beginRecording(anyInt(), anyInt())).thenReturn(canvas);
    SVGParser.SVGHandler parserHandler = spy(this.parserHandler);
    RadialGradient gr1 = mock(RadialGradient.class);
    PowerMockito.whenNew(RadialGradient.class).withArguments(eq(10.1f), eq(4.1f), eq(5.0f), eq(new int[0]), eq(new float[0]), eq(Shader.TileMode.CLAMP)).thenReturn(gr1);
    RadialGradient gr2 = mock(RadialGradient.class);
    PowerMockito.whenNew(RadialGradient.class).withArguments(eq(5.0f), eq(5.0f), eq(2.0f), eq(new int[0]), eq(new float[0]), eq(Shader.TileMode.CLAMP)).thenReturn(gr2);
    Matrix subMatrix = mock(Matrix.class);
    PowerMockito.whenNew(Matrix.class).withArguments(matrix).thenReturn(subMatrix);
    //when
    startSVG(parserHandler);
    //parent gradient
    startElement(parserHandler, attributes(attr("id", "gr1"), attr("cx", "10.1"), attr("cy", "4.1"), attr("r", "5.0"), attr("gradientTransform", "matrix(0.2883 0 0 0.2865 153.3307 265.0264)")), "radialGradient");
    endElement(parserHandler, "radialGradient");
    //child gradient
    startElement(parserHandler, attributes(attr("id", "gr2"), attr("cx", "5.0"), attr("cy", "5.0"), attr("r", "2.0"), attr("href", "#gr1")), "radialGradient");
    endElement(parserHandler, "radialGradient");
    endSVG(parserHandler);
    //then
    verify(gr1, times(1)).setLocalMatrix(matrix);
    verify(gr2, times(1)).setLocalMatrix(subMatrix);
    verify(matrix).setValues(new float[] { 0.2883f, 0.0f, 153.3307f, 0.0f, 0.2865f, 265.0264f, 0.0f, 0.0f, 1.0f });
}
Also used : Matrix(android.graphics.Matrix) RadialGradient(android.graphics.RadialGradient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RadialGradient (android.graphics.RadialGradient)49 LinearGradient (android.graphics.LinearGradient)27 Paint (android.graphics.Paint)23 RectF (android.graphics.RectF)21 Path (android.graphics.Path)15 SweepGradient (android.graphics.SweepGradient)14 Rect (android.graphics.Rect)12 Canvas (android.graphics.Canvas)6 Bitmap (android.graphics.Bitmap)4 ComposeShader (android.graphics.ComposeShader)4 Matrix (android.graphics.Matrix)4 SuppressLint (android.annotation.SuppressLint)2 PorterDuffXfermode (android.graphics.PorterDuffXfermode)2 Shader (android.graphics.Shader)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ColorMatrix (android.graphics.ColorMatrix)1 ArrayList (java.util.ArrayList)1 Point (org.achartengine.model.Point)1 SimpleSeriesRenderer (org.achartengine.renderer.SimpleSeriesRenderer)1