Loading core/java/android/app/Notification.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -8707,12 +8709,25 @@ public class Notification implements Parcelable * <p>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. * </p> * * <p>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. * </p> */ @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; } Loading packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java +11 −3 Original line number Diff line number Diff line Loading @@ -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); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); } Loading Loading
core/java/android/app/Notification.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -8707,12 +8709,25 @@ public class Notification implements Parcelable * <p>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. * </p> * * <p>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. * </p> */ @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; } Loading
packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java +11 −3 Original line number Diff line number Diff line Loading @@ -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); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); } Loading