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);
;
}
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;
}
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);
}
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));
}
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));
}
Aggregations