mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-03 17:36:49 +00:00
Add shadow to badges
- Add static method to ShadowGenerator to generate a circle Bitmap with a shadow. - Move setColorScale() from DragView to Themes, and use it to apply color to the shadowed Bitmap. Bug: 35744066 Change-Id: I8d1da528bbf94dc83851f0b4016361ed9f8d5349
This commit is contained in:
@@ -83,6 +83,38 @@ public class ShadowGenerator {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Bitmap createCircleWithShadow(int circleColor, int diameter) {
|
||||
|
||||
float shadowRadius = diameter * 1f / 32;
|
||||
float shadowYOffset = diameter * 1f / 16;
|
||||
|
||||
int radius = diameter / 2;
|
||||
|
||||
Canvas canvas = new Canvas();
|
||||
Paint blurPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
||||
blurPaint.setMaskFilter(new BlurMaskFilter(shadowRadius, Blur.NORMAL));
|
||||
|
||||
int center = Math.round(radius + shadowRadius + shadowYOffset);
|
||||
int size = center * 2;
|
||||
Bitmap result = Bitmap.createBitmap(size, size, Config.ARGB_8888);
|
||||
canvas.setBitmap(result);
|
||||
|
||||
// Draw ambient shadow, center aligned within size
|
||||
blurPaint.setAlpha(AMBIENT_SHADOW_ALPHA);
|
||||
canvas.drawCircle(center, center, radius, blurPaint);
|
||||
|
||||
// Draw key shadow, bottom aligned within size
|
||||
blurPaint.setAlpha(KEY_SHADOW_ALPHA);
|
||||
canvas.drawCircle(center, center + shadowYOffset, radius, blurPaint);
|
||||
|
||||
// Draw the circle
|
||||
Paint drawPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
||||
drawPaint.setColor(circleColor);
|
||||
canvas.drawCircle(center, center, radius, drawPaint);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ShadowGenerator getInstance(Context context) {
|
||||
Preconditions.assertNonUiThread();
|
||||
synchronized (LOCK) {
|
||||
|
||||
Reference in New Issue
Block a user