diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 523b2005fb720..7ba614685ad88 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -16,6 +16,8 @@ package android.app; +import static android.graphics.drawable.Icon.TYPE_BITMAP; + import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast; import android.annotation.ColorInt; @@ -8707,12 +8709,25 @@ public class Notification implements Parcelable *
An icon is required and should be representative of the content within the bubble. * If your app produces multiple bubbles, the image should be unique for each of them. *
+ * + *The shape of a bubble icon is adaptive and can match the device theme. + * + * If your icon is bitmap-based, you should create it using + * {@link Icon#createWithAdaptiveBitmap(Bitmap)}, otherwise this method will throw. + * + * If your icon is not bitmap-based, you should expect that the icon will be tinted. + *
*/ @NonNull public BubbleMetadata.Builder setIcon(@NonNull Icon icon) { if (icon == null) { throw new IllegalArgumentException("Bubbles require non-null icon"); } + if (icon.getType() == TYPE_BITMAP) { + throw new IllegalArgumentException("When using bitmap based icons, Bubbles " + + "require TYPE_ADAPTIVE_BITMAP, please use" + + " Icon#createWithAdaptiveBitmap instead"); + } mIcon = icon; return this; } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java index b409a3181e2bb..7a68be494cf9c 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java @@ -193,11 +193,19 @@ public class BubbleView extends FrameLayout { if (mEntry == null) { return; } + Notification.BubbleMetadata metadata = mEntry.getBubbleMetadata(); Notification n = mEntry.notification.getNotification(); - boolean isLarge = n.getLargeIcon() != null; - Icon ic = isLarge ? n.getLargeIcon() : n.getSmallIcon(); + Icon ic; + boolean needsTint; + if (metadata != null) { + ic = metadata.getIcon(); + needsTint = ic.getType() != Icon.TYPE_ADAPTIVE_BITMAP; + } else { + needsTint = n.getLargeIcon() == null; + ic = needsTint ? n.getSmallIcon() : n.getLargeIcon(); + } Drawable iconDrawable = ic.loadDrawable(mContext); - if (!isLarge) { + if (needsTint) { // Center icon on coloured background iconDrawable.setTint(Color.WHITE); // TODO: dark mode Drawable bg = new ColorDrawable(n.color); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java index de155055b76b1..5a1f24a44b2f5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java @@ -313,7 +313,7 @@ public class NotificationTestHelper { .setIntent(bubbleIntent) .setDeleteIntent(deleteIntent) .setTitle("bubble title") - .setIcon(Icon.createWithResource(mContext, 1)) + .setIcon(Icon.createWithResource(mContext, R.drawable.android)) .setDesiredHeight(314) .build(); }