use of android.graphics.RadialGradient in project android_frameworks_base by AOSPA.
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));
}
use of android.graphics.RadialGradient in project wire-android by wireapp.
the class BackgroundDrawable method createVignetteShader.
private void createVignetteShader() {
vignetteShader = new RadialGradient(0.5f, 0.5f, vignetteRadiusFactor, VIGNETTE_COLOR_CENTER, VIGNETTE_COLOR_EDGE, Shader.TileMode.CLAMP);
Matrix matrix = new Matrix();
matrix.setScale(width, height);
vignetteShader.setLocalMatrix(matrix);
}
use of android.graphics.RadialGradient in project wire-android by wireapp.
the class BitmapUtils method getVignetteBitmap.
/**
* Helper function to create a bitmap that serves as a vignette overlay.
*
* @return
*/
public static Bitmap getVignetteBitmap(Resources resources) {
double radiusFactor = ResourceUtils.getResourceFloat(resources, R.dimen.background__vignette_radius_factor);
int radius = (int) (VIGNETTE_WIDTH * radiusFactor);
int baseColor = resources.getColor(R.color.black_80);
int colorCenter = resources.getColor(R.color.black);
int colorEdge = resources.getColor(R.color.transparent);
Bitmap dest = Bitmap.createBitmap(VIGNETTE_WIDTH, VIGNETTE_HEIGHT, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(dest);
Bitmap tempBitmap = Bitmap.createBitmap(dest.getWidth(), dest.getHeight(), Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(tempBitmap);
tempCanvas.drawColor(baseColor);
RadialGradient gradient = new RadialGradient(VIGNETTE_WIDTH / 2, VIGNETTE_HEIGHT / 2, radius, colorCenter, colorEdge, android.graphics.Shader.TileMode.CLAMP);
Paint p = new Paint();
p.setShader(gradient);
p.setColor(0xFF000000);
p.setAntiAlias(true);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
tempCanvas.drawCircle(VIGNETTE_WIDTH / 2, VIGNETTE_HEIGHT / 2, radius, p);
canvas.drawBitmap(tempBitmap, 0, 0, null);
return dest;
}
use of android.graphics.RadialGradient in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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);
}
}
Aggregations