Search in sources :

Example 11 with RadialGradient

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

the class SVGHandlerTest method testParseRadialGradient.

@Test
public void testParseRadialGradient() throws Exception {
    //given
    when(picture.beginRecording(anyInt(), anyInt())).thenReturn(canvas);
    SVGParser.SVGHandler parserHandler = spy(this.parserHandler);
    RadialGradient gradient = mock(RadialGradient.class);
    PowerMockito.whenNew(RadialGradient.class).withArguments(eq(10.1f), eq(4.1f), eq(5.0f), eq(new int[] { -65536 }), eq(new float[] { 10.1f }), eq(Shader.TileMode.CLAMP)).thenReturn(gradient);
    //when
    startSVG(parserHandler);
    startElement(parserHandler, attributes(attr("id", "g1"), attr("cx", "10.1"), attr("cy", "4.1"), attr("r", "5.0")), "radialGradient");
    startElement(parserHandler, attributes(attr("offset", "10.1"), attr("style", "stop-color:ff0000")), "stop");
    endElement(parserHandler, "stop");
    endElement(parserHandler, "radialGradient");
    startElement(parserHandler, attributes(attr("width", "100"), attr("height", "100"), attr("fill", "url(#g1)")), "rect");
    endElement(parserHandler, "rect");
    endSVG(parserHandler);
    //then
    verify(paint).setShader(gradient);
    ;
}
Also used : RadialGradient(android.graphics.RadialGradient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with RadialGradient

use of android.graphics.RadialGradient in project SystemBarTint by jgilfelt.

the class ColorPicker method createColorWheelBitmap.

private Bitmap createColorWheelBitmap(int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    int colorCount = 12;
    int colorAngleStep = 360 / 12;
    int[] colors = new int[colorCount + 1];
    float[] hsv = new float[] { 0f, 1f, 1f };
    for (int i = 0; i < colors.length; i++) {
        hsv[0] = (i * colorAngleStep + 180) % 360;
        colors[i] = Color.HSVToColor(hsv);
    }
    colors[colorCount] = colors[0];
    SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
    RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
    ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);
    colorWheelPaint.setShader(composeShader);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) ComposeShader(android.graphics.ComposeShader) Canvas(android.graphics.Canvas) RadialGradient(android.graphics.RadialGradient) SweepGradient(android.graphics.SweepGradient) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 13 with RadialGradient

use of android.graphics.RadialGradient in project Depth-LIB-Android- by danielzeller.

the class CustomShadow 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));
    mEdgeShadowPaint.setAntiAlias(false);
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) RadialGradient(android.graphics.RadialGradient)

Example 14 with RadialGradient

use of android.graphics.RadialGradient in project android_frameworks_base by ResurrectionRemix.

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

use of android.graphics.RadialGradient in project android_frameworks_base by ResurrectionRemix.

the class KeyguardUserSwitcherScrim method updatePaint.

private void updatePaint() {
    if (mLayoutWidth == 0) {
        return;
    }
    float radius = mLayoutWidth * OUTER_EXTENT;
    boolean isLtr = getLayoutDirection() == LayoutDirection.LTR;
    mRadialGradientPaint.setShader(new RadialGradient(isLtr ? mLayoutWidth : 0, 0, radius, new int[] { Color.argb((int) (Color.alpha(mDarkColor) * mAlpha / 255f), 0, 0, 0), Color.TRANSPARENT }, new float[] { Math.max(0f, mLayoutWidth * INNER_EXTENT / radius), 1f }, Shader.TileMode.CLAMP));
}
Also used : RadialGradient(android.graphics.RadialGradient)

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