Search in sources :

Example 1 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 2 with RadialGradient

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

the class SVGHandlerGradientTransformTest method testGradientTransform.

private void testGradientTransform(String val, Matrix matrix) throws Exception {
    //given
    when(picture.beginRecording(anyInt(), anyInt())).thenReturn(canvas);
    SVGParser.SVGHandler parserHandler = spy(this.parserHandler);
    PowerMockito.whenNew(Matrix.class).withArguments(matrix).thenReturn(matrix);
    RadialGradient radialGradient = mock(RadialGradient.class);
    PowerMockito.whenNew(RadialGradient.class).withArguments(eq(10.0f), eq(10.0f), eq(5.0f), any(int[].class), any(float[].class), eq(Shader.TileMode.CLAMP)).thenReturn(radialGradient);
    //when
    startSVG(parserHandler);
    startElement(parserHandler, attributes(attr("id", "gr1"), attr("cx", "10.0"), attr("cy", "10.0"), attr("r", "5.0"), attr("gradientTransform", val)), "radialGradient");
    endElement(parserHandler, "radialGradient");
    endSVG(parserHandler);
}
Also used : RadialGradient(android.graphics.RadialGradient)

Example 3 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 4 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 5 with RadialGradient

use of android.graphics.RadialGradient in project material by rey5137.

the class RevealDrawable method getShader.

private RadialGradient getShader(ColorChangeTask task) {
    if (mShader == null) {
        if (task.isOut) {
            int color_middle = ColorUtil.getColor(mCurColor, 0f);
            mShader = new RadialGradient(task.x, task.y, GRADIENT_RADIUS, new int[] { 0, color_middle, mCurColor }, GRADIENT_STOPS, Shader.TileMode.CLAMP);
        } else {
            int color_middle = ColorUtil.getColor(task.color, 0f);
            mShader = new RadialGradient(task.x, task.y, GRADIENT_RADIUS, new int[] { 0, color_middle, task.color }, GRADIENT_STOPS, Shader.TileMode.CLAMP);
        }
    }
    return mShader;
}
Also used : RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint)

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