summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/badge
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-04-26 18:13:56 -0700
committerTony <twickham@google.com>2017-04-26 19:39:05 -0700
commit0530e8c60809afa92b1aa907376f0553ad94d58f (patch)
tree044b2b2ee2686d2bf1e97f3abe08fcb176a62acd /src/com/android/launcher3/badge
parentb85f5dfcba3833b2a520e14fb6526de58763444f (diff)
downloadandroid_packages_apps_Trebuchet-0530e8c60809afa92b1aa907376f0553ad94d58f.tar.gz
android_packages_apps_Trebuchet-0530e8c60809afa92b1aa907376f0553ad94d58f.tar.bz2
android_packages_apps_Trebuchet-0530e8c60809afa92b1aa907376f0553ad94d58f.zip
Support notifications with 0 count (show as dots)
- Show number if number > 0 - Show icon if number == 0 and a notification specified an icon to show - Show a dot otherwise - In cases of multiple notifications, stack a second badge behind the first (visuals will be updated in future CL, as well as support stacked dots) - Folders always show dot if any app within has a badge. Change-Id: I0a89059b0e0a0d174fe739c9da4f75fa18c0edfa
Diffstat (limited to 'src/com/android/launcher3/badge')
-rw-r--r--src/com/android/launcher3/badge/BadgeRenderer.java46
-rw-r--r--src/com/android/launcher3/badge/FolderBadgeInfo.java25
2 files changed, 52 insertions, 19 deletions
diff --git a/src/com/android/launcher3/badge/BadgeRenderer.java b/src/com/android/launcher3/badge/BadgeRenderer.java
index a1ef22f4e..2971ceb80 100644
--- a/src/com/android/launcher3/badge/BadgeRenderer.java
+++ b/src/com/android/launcher3/badge/BadgeRenderer.java
@@ -44,12 +44,17 @@ public class BadgeRenderer {
private static final float CHAR_SIZE_PERCENTAGE = 0.12f;
private static final float TEXT_SIZE_PERCENTAGE = 0.26f;
private static final float OFFSET_PERCENTAGE = 0.02f;
+ private static final float STACK_OFFSET_PERCENTAGE_X = 0.05f;
+ private static final float STACK_OFFSET_PERCENTAGE_Y = 0.06f;
+ private static final float DOT_SCALE = 0.6f;
private final Context mContext;
private final int mSize;
private final int mCharSize;
private final int mTextHeight;
private final int mOffset;
+ private final int mStackOffsetX;
+ private final int mStackOffsetY;
private final IconDrawer mLargeIconDrawer;
private final IconDrawer mSmallIconDrawer;
private final Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
@@ -63,6 +68,8 @@ public class BadgeRenderer {
mSize = (int) (SIZE_PERCENTAGE * iconSizePx);
mCharSize = (int) (CHAR_SIZE_PERCENTAGE * iconSizePx);
mOffset = (int) (OFFSET_PERCENTAGE * iconSizePx);
+ mStackOffsetX = (int) (STACK_OFFSET_PERCENTAGE_X * iconSizePx);
+ mStackOffsetY = (int) (STACK_OFFSET_PERCENTAGE_Y * iconSizePx);
mTextPaint.setTextSize(iconSizePx * TEXT_SIZE_PERCENTAGE);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mLargeIconDrawer = new IconDrawer(res.getDimensionPixelSize(R.dimen.badge_small_padding));
@@ -91,7 +98,7 @@ public class BadgeRenderer {
? mLargeIconDrawer : mSmallIconDrawer;
Shader icon = badgeInfo == null ? null : badgeInfo.getNotificationIconForBadge(
mContext, palette.backgroundColor, mSize, iconDrawer.mPadding);
- String notificationCount = icon != null || badgeInfo == null ? "0"
+ String notificationCount = badgeInfo == null ? "0"
: String.valueOf(badgeInfo.getNotificationCount());
int numChars = notificationCount.length();
int width = mSize + mCharSize * (numChars - 1);
@@ -105,21 +112,42 @@ public class BadgeRenderer {
// We draw the badge relative to its center.
int badgeCenterX = iconBounds.right - width / 2;
int badgeCenterY = iconBounds.top + mSize / 2;
+ boolean isText = badgeInfo != null && badgeInfo.getNotificationCount() != 0;
+ boolean isIcon = icon != null;
+ boolean isDot = !(isText || isIcon);
+ if (isDot) {
+ badgeScale *= DOT_SCALE;
+ }
int offsetX = Math.min(mOffset, spaceForOffset.x);
int offsetY = Math.min(mOffset, spaceForOffset.y);
canvas.translate(badgeCenterX + offsetX, badgeCenterY - offsetY);
canvas.scale(badgeScale, badgeScale);
- // Draw the background and shadow.
+ // Prepare the background and shadow and possible stacking effect.
mBackgroundPaint.setColorFilter(palette.backgroundColorMatrixFilter);
int backgroundWithShadowSize = backgroundWithShadow.getHeight(); // Same as width.
- canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
- -backgroundWithShadowSize / 2, mBackgroundPaint);
- if (icon != null) {
- // Draw the notification icon with padding.
- iconDrawer.drawIcon(icon, canvas);
- } else {
- // Draw the notification count.
+ boolean shouldStack = !isDot && badgeInfo != null
+ && badgeInfo.getNotificationKeys().size() > 1;
+ if (shouldStack) {
+ int offsetDiffX = mStackOffsetX - mOffset;
+ int offsetDiffY = mStackOffsetY - mOffset;
+ canvas.translate(offsetDiffX, offsetDiffY);
+ canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
+ -backgroundWithShadowSize / 2, mBackgroundPaint);
+ canvas.translate(-offsetDiffX, -offsetDiffY);
+ }
+
+ if (isText) {
+ canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
+ -backgroundWithShadowSize / 2, mBackgroundPaint);
canvas.drawText(notificationCount, 0, mTextHeight / 2, mTextPaint);
+ } else if (isIcon) {
+ canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
+ -backgroundWithShadowSize / 2, mBackgroundPaint);
+ iconDrawer.drawIcon(icon, canvas);
+ } else if (isDot) {
+ mBackgroundPaint.setColorFilter(palette.saturatedBackgroundColorMatrixFilter);
+ canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
+ -backgroundWithShadowSize / 2, mBackgroundPaint);
}
canvas.restore();
}
diff --git a/src/com/android/launcher3/badge/FolderBadgeInfo.java b/src/com/android/launcher3/badge/FolderBadgeInfo.java
index f7c64aa88..3a1bf60c4 100644
--- a/src/com/android/launcher3/badge/FolderBadgeInfo.java
+++ b/src/com/android/launcher3/badge/FolderBadgeInfo.java
@@ -19,14 +19,14 @@ package com.android.launcher3.badge;
import com.android.launcher3.Utilities;
/**
- * Subclass of BadgeInfo that only contains the badge count,
- * which is the sum of all the Folder's items' counts.
+ * Subclass of BadgeInfo that only contains the badge count, which is
+ * the sum of all the Folder's items' notifications (each counts as 1).
*/
public class FolderBadgeInfo extends BadgeInfo {
private static final int MIN_COUNT = 0;
- private int mTotalNotificationCount;
+ private int mNumNotifications;
public FolderBadgeInfo() {
super(null);
@@ -36,22 +36,27 @@ public class FolderBadgeInfo extends BadgeInfo {
if (badgeToAdd == null) {
return;
}
- mTotalNotificationCount += badgeToAdd.getNotificationCount();
- mTotalNotificationCount = Utilities.boundToRange(
- mTotalNotificationCount, MIN_COUNT, BadgeInfo.MAX_COUNT);
+ mNumNotifications += badgeToAdd.getNotificationKeys().size();
+ mNumNotifications = Utilities.boundToRange(
+ mNumNotifications, MIN_COUNT, BadgeInfo.MAX_COUNT);
}
public void subtractBadgeInfo(BadgeInfo badgeToSubtract) {
if (badgeToSubtract == null) {
return;
}
- mTotalNotificationCount -= badgeToSubtract.getNotificationCount();
- mTotalNotificationCount = Utilities.boundToRange(
- mTotalNotificationCount, MIN_COUNT, BadgeInfo.MAX_COUNT);
+ mNumNotifications -= badgeToSubtract.getNotificationKeys().size();
+ mNumNotifications = Utilities.boundToRange(
+ mNumNotifications, MIN_COUNT, BadgeInfo.MAX_COUNT);
}
@Override
public int getNotificationCount() {
- return mTotalNotificationCount;
+ // This forces the folder badge to always show up as a dot.
+ return 0;
+ }
+
+ public boolean hasBadge() {
+ return mNumNotifications > 0;
}
}