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:
Tony Wickham
2017-02-27 13:30:20 -08:00
committed by Tony
parent cf18c3c2d1
commit 6c82867a7e
6 changed files with 74 additions and 14 deletions

View File

@@ -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) {