mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 09:56:49 +00:00
Show notification icon in place of "1" in badge.
- When notifications update, add the NotificationInfo to the BadgeInfo if there is only one for an app. BadgeRenderer will use the NotificationInfo to get the icon to draw. - When retrieving the icon from the NotificationInfo, we draw it into a shader (similar to MaskableIconDrawable), which is rendered by BadgeRenderer. - For now, we only use the notification icon if it is large. Bug: 34839959 Bug: 32410600 Bug: 33553066 Change-Id: I31851804008dd15bab75d2759441187830c3265e
This commit is contained in:
@@ -38,6 +38,11 @@ import com.android.launcher3.util.PackageUserKey;
|
||||
*/
|
||||
public class NotificationInfo implements View.OnClickListener {
|
||||
|
||||
// TODO: use Notification constants directly.
|
||||
public static final int BADGE_ICON_NONE = 0;
|
||||
public static final int BADGE_ICON_SMALL = 1;
|
||||
public static final int BADGE_ICON_LARGE = 2;
|
||||
|
||||
public final PackageUserKey packageUserKey;
|
||||
public final String notificationKey;
|
||||
public final CharSequence title;
|
||||
@@ -46,9 +51,10 @@ public class NotificationInfo implements View.OnClickListener {
|
||||
public final boolean autoCancel;
|
||||
public final boolean dismissable;
|
||||
|
||||
private final int mBadgeIcon;
|
||||
private final Drawable mIconDrawable;
|
||||
private boolean mShouldTintIcon;
|
||||
private int mIconColor;
|
||||
private boolean mIsIconLarge;
|
||||
|
||||
/**
|
||||
* Extracts the data that we need from the StatusBarNotification.
|
||||
@@ -59,17 +65,20 @@ public class NotificationInfo implements View.OnClickListener {
|
||||
Notification notification = statusBarNotification.getNotification();
|
||||
title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
|
||||
text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
|
||||
mBadgeIcon = BADGE_ICON_LARGE; // TODO: get from the Notification
|
||||
// Load the icon. Since it is backed by ashmem, we won't copy the entire bitmap
|
||||
// into our process as long as we don't touch it and it exists in systemui.
|
||||
Icon icon = notification.getLargeIcon();
|
||||
Icon icon = mBadgeIcon == BADGE_ICON_SMALL ? null : notification.getLargeIcon();
|
||||
if (icon == null) {
|
||||
// Use the small icon.
|
||||
icon = notification.getSmallIcon();
|
||||
mIconDrawable = icon.loadDrawable(context);
|
||||
mIconColor = statusBarNotification.getNotification().color;
|
||||
mShouldTintIcon = true;
|
||||
mIsIconLarge = false;
|
||||
} else {
|
||||
// Use the large icon.
|
||||
mIconDrawable = icon.loadDrawable(context);
|
||||
mShouldTintIcon = false;
|
||||
mIsIconLarge = true;
|
||||
}
|
||||
intent = notification.contentIntent;
|
||||
autoCancel = (notification.flags & Notification.FLAG_AUTO_CANCEL) != 0;
|
||||
@@ -91,7 +100,8 @@ public class NotificationInfo implements View.OnClickListener {
|
||||
}
|
||||
|
||||
public Drawable getIconForBackground(Context context, int background) {
|
||||
if (!mShouldTintIcon) {
|
||||
if (mIsIconLarge) {
|
||||
// Only small icons should be tinted.
|
||||
return mIconDrawable;
|
||||
}
|
||||
mIconColor = IconPalette.resolveContrastColor(context, mIconColor, background);
|
||||
@@ -100,7 +110,17 @@ public class NotificationInfo implements View.OnClickListener {
|
||||
// get it set and invalidated properly.
|
||||
icon.setTintList(null);
|
||||
icon.setTint(mIconColor);
|
||||
mShouldTintIcon = false;
|
||||
return icon;
|
||||
}
|
||||
|
||||
public boolean isIconLarge() {
|
||||
return mIsIconLarge;
|
||||
}
|
||||
|
||||
public boolean shouldShowIconInBadge() {
|
||||
// If the icon we're using for this notification matches what the Notification
|
||||
// specified should show in the badge, then return true.
|
||||
return mIsIconLarge && mBadgeIcon == BADGE_ICON_LARGE
|
||||
|| !mIsIconLarge && mBadgeIcon == BADGE_ICON_SMALL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user