summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/badge
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-06-07 14:32:23 -0700
committerTony Wickham <twickham@google.com>2017-06-08 21:08:47 +0000
commit7092db02410562026da17a7b38f48025cc847de2 (patch)
treef1c0c5a50594ce890109bdb25dd0346dee9cbf6d /src/com/android/launcher3/badge
parent85b64c7da0f1134fdbae954acbc2925c1433566a (diff)
downloadandroid_packages_apps_Trebuchet-7092db02410562026da17a7b38f48025cc847de2.tar.gz
android_packages_apps_Trebuchet-7092db02410562026da17a7b38f48025cc847de2.tar.bz2
android_packages_apps_Trebuchet-7092db02410562026da17a7b38f48025cc847de2.zip
Add support for color extracted notification dots
Changing the badge_color in colors.xml to transparent will cause them to be color extracted. When an extracted color is used in the IconPalette, we desaturate the background. Otherwise we respect the exact color specified in colors.xml. Change-Id: Ie82d0c5335fa5f24d4cc47766e4c1719c4916f8b
Diffstat (limited to 'src/com/android/launcher3/badge')
-rw-r--r--src/com/android/launcher3/badge/BadgeRenderer.java14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/com/android/launcher3/badge/BadgeRenderer.java b/src/com/android/launcher3/badge/BadgeRenderer.java
index adde4a2fc..ba1977af4 100644
--- a/src/com/android/launcher3/badge/BadgeRenderer.java
+++ b/src/com/android/launcher3/badge/BadgeRenderer.java
@@ -63,7 +63,6 @@ public class BadgeRenderer {
private final Paint mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG
| Paint.FILTER_BITMAP_FLAG);
private final SparseArray<Bitmap> mBackgroundsWithShadow;
- private final IconPalette mIconPalette;
public BadgeRenderer(Context context, int iconSizePx) {
mContext = context;
@@ -83,25 +82,24 @@ public class BadgeRenderer {
mTextHeight = tempTextHeight.height();
mBackgroundsWithShadow = new SparseArray<>(3);
-
- mIconPalette = IconPalette.fromDominantColor(context.getColor(R.color.badge_color));
}
/**
* Draw a circle in the top right corner of the given bounds, and draw
* {@link BadgeInfo#getNotificationCount()} on top of the circle.
+ * @param palette The colors (based on the icon) to use for the badge.
* @param badgeInfo Contains data to draw on the badge. Could be null if we are animating out.
* @param iconBounds The bounds of the icon being badged.
* @param badgeScale The progress of the animation, from 0 to 1.
* @param spaceForOffset How much space is available to offset the badge up and to the right.
*/
- public void draw(Canvas canvas, @Nullable BadgeInfo badgeInfo,
+ public void draw(Canvas canvas, IconPalette palette, @Nullable BadgeInfo badgeInfo,
Rect iconBounds, float badgeScale, Point spaceForOffset) {
- mTextPaint.setColor(mIconPalette.textColor);
+ mTextPaint.setColor(palette.textColor);
IconDrawer iconDrawer = badgeInfo != null && badgeInfo.isIconLarge()
? mLargeIconDrawer : mSmallIconDrawer;
Shader icon = badgeInfo == null ? null : badgeInfo.getNotificationIconForBadge(
- mContext, mIconPalette.backgroundColor, mSize, iconDrawer.mPadding);
+ mContext, palette.backgroundColor, mSize, iconDrawer.mPadding);
String notificationCount = badgeInfo == null ? "0"
: String.valueOf(badgeInfo.getNotificationCount());
int numChars = notificationCount.length();
@@ -127,7 +125,7 @@ public class BadgeRenderer {
canvas.translate(badgeCenterX + offsetX, badgeCenterY - offsetY);
canvas.scale(badgeScale, badgeScale);
// Prepare the background and shadow and possible stacking effect.
- mBackgroundPaint.setColorFilter(mIconPalette.backgroundColorMatrixFilter);
+ mBackgroundPaint.setColorFilter(palette.backgroundColorMatrixFilter);
int backgroundWithShadowSize = backgroundWithShadow.getHeight(); // Same as width.
boolean shouldStack = !isDot && badgeInfo != null
&& badgeInfo.getNotificationKeys().size() > 1;
@@ -149,7 +147,7 @@ public class BadgeRenderer {
-backgroundWithShadowSize / 2, mBackgroundPaint);
iconDrawer.drawIcon(icon, canvas);
} else if (isDot) {
- mBackgroundPaint.setColorFilter(mIconPalette.saturatedBackgroundColorMatrixFilter);
+ mBackgroundPaint.setColorFilter(palette.saturatedBackgroundColorMatrixFilter);
canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
-backgroundWithShadowSize / 2, mBackgroundPaint);
}