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