Merge "Documentation & refinements around BubbleMetadata#setIcon API"
This commit is contained in:
@@ -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
|
||||
* <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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user