diff options
| -rw-r--r-- | core/java/android/app/Notification.java | 100 |
1 files changed, 96 insertions, 4 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index f6a06f3ed5ef..5380f1c15dfd 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -1198,6 +1198,15 @@ public class Notification implements Parcelable "android.pictureContentDescription"; /** + * {@link #extras} key: this is a boolean to indicate that the + * {@link BigPictureStyle#bigPicture(Bitmap) big picture} is to be shown in the collapsed state + * of a {@link BigPictureStyle} notification. This will replace a + * {@link Builder#setLargeIcon(Icon) large icon} in that state if one was provided. + * @hide + */ + public static final String EXTRA_PROMOTE_PICTURE = "android.promotePicture"; + + /** * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. */ @@ -5149,6 +5158,7 @@ public class Notification implements Parcelable // changes are entirely visual, and should otherwise be undetectable by apps. @SuppressWarnings("AndroidFrameworkCompatChange") private void calculateLargeIconDimens(boolean largeIconShown, + @NonNull StandardTemplateParams p, @NonNull TemplateBindResult result) { final Resources resources = mContext.getResources(); final float density = resources.getDisplayMetrics().density; @@ -5159,9 +5169,9 @@ public class Notification implements Parcelable final float viewHeightDp = resources.getDimension( R.dimen.notification_right_icon_size) / density; float viewWidthDp = viewHeightDp; // icons are 1:1 by default - if (largeIconShown && ( - mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S - || DevFlags.shouldBackportSNotifRules(mContext.getContentResolver()))) { + if (largeIconShown && (p.mPromotePicture + || mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S + || DevFlags.shouldBackportSNotifRules(mContext.getContentResolver()))) { Drawable drawable = mN.mLargeIcon.loadDrawable(mContext); if (drawable != null) { int iconWidth = drawable.getIntrinsicWidth(); @@ -5187,7 +5197,7 @@ public class Notification implements Parcelable mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); } boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon; - calculateLargeIconDimens(showLargeIcon, result); + calculateLargeIconDimens(showLargeIcon, p, result); if (showLargeIcon) { contentView.setViewLayoutWidth(R.id.right_icon, result.mRightIconWidthDp, TypedValue.COMPLEX_UNIT_DIP); @@ -6995,6 +7005,7 @@ public class Notification implements Parcelable private Icon mBigLargeIcon; private boolean mBigLargeIconSet = false; private CharSequence mPictureContentDescription; + private boolean mPromotePicture; public BigPictureStyle() { } @@ -7050,6 +7061,18 @@ public class Notification implements Parcelable } /** + * When set, the {@link #bigPicture(Bitmap) big picture} of this style will be promoted and + * shown in place of the {@link Builder#setLargeIcon(Icon) large icon} in the collapsed + * state of this notification. + * @hide + */ + @NonNull + public BigPictureStyle showBigPictureWhenCollapsed(boolean show) { + mPromotePicture = show; + return this; + } + + /** * Override the large icon when the big notification is shown. */ public BigPictureStyle bigLargeIcon(Bitmap b) { @@ -7112,6 +7135,66 @@ public class Notification implements Parcelable /** * @hide */ + @Override + public RemoteViews makeContentView(boolean increasedHeight) { + if (mPicture == null || !mPromotePicture) { + return super.makeContentView(increasedHeight); + } + + Icon oldLargeIcon = mBuilder.mN.mLargeIcon; + mBuilder.mN.mLargeIcon = Icon.createWithBitmap(mPicture); + // The legacy largeIcon might not allow us to clear the image, as it's taken in + // replacement if the other one is null. Because we're restoring these legacy icons + // for old listeners, this is in general non-null. + Bitmap largeIconLegacy = mBuilder.mN.largeIcon; + mBuilder.mN.largeIcon = null; + + StandardTemplateParams p = mBuilder.mParams.reset() + .viewType(StandardTemplateParams.VIEW_TYPE_NORMAL) + .fillTextsFrom(mBuilder) + .promotePicture(true); + RemoteViews contentView = getStandardView(mBuilder.getBaseLayoutResource(), + p, null /* result */); + + mBuilder.mN.mLargeIcon = oldLargeIcon; + mBuilder.mN.largeIcon = largeIconLegacy; + + return contentView; + } + + /** + * @hide + */ + @Override + public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { + if (mPicture == null || !mPromotePicture) { + return super.makeHeadsUpContentView(increasedHeight); + } + + Icon oldLargeIcon = mBuilder.mN.mLargeIcon; + mBuilder.mN.mLargeIcon = Icon.createWithBitmap(mPicture); + // The legacy largeIcon might not allow us to clear the image, as it's taken in + // replacement if the other one is null. Because we're restoring these legacy icons + // for old listeners, this is in general non-null. + Bitmap largeIconLegacy = mBuilder.mN.largeIcon; + mBuilder.mN.largeIcon = null; + + StandardTemplateParams p = mBuilder.mParams.reset() + .viewType(StandardTemplateParams.VIEW_TYPE_HEADS_UP) + .fillTextsFrom(mBuilder) + .promotePicture(true); + RemoteViews contentView = getStandardView(mBuilder.getHeadsUpBaseLayoutResource(), + p, null /* result */); + + mBuilder.mN.mLargeIcon = oldLargeIcon; + mBuilder.mN.largeIcon = largeIconLegacy; + + return contentView; + } + + /** + * @hide + */ public RemoteViews makeBigContentView() { // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet // This covers the following cases: @@ -7168,6 +7251,7 @@ public class Notification implements Parcelable extras.putCharSequence(EXTRA_PICTURE_CONTENT_DESCRIPTION, mPictureContentDescription); } + extras.putBoolean(EXTRA_PROMOTE_PICTURE, mPromotePicture); extras.putParcelable(EXTRA_PICTURE, mPicture); } @@ -7188,6 +7272,7 @@ public class Notification implements Parcelable extras.getCharSequence(EXTRA_PICTURE_CONTENT_DESCRIPTION); } + mPromotePicture = extras.getBoolean(EXTRA_PROMOTE_PICTURE); mPicture = extras.getParcelable(EXTRA_PICTURE); } @@ -11306,6 +11391,7 @@ public class Notification implements Parcelable boolean mHideTitle; boolean mHideActions; boolean mHideProgress; + boolean mPromotePicture; CharSequence title; CharSequence text; CharSequence headerTextSecondary; @@ -11321,6 +11407,7 @@ public class Notification implements Parcelable mHideTitle = false; mHideActions = false; mHideProgress = false; + mPromotePicture = false; title = null; text = null; summaryText = null; @@ -11360,6 +11447,11 @@ public class Notification implements Parcelable return this; } + final StandardTemplateParams promotePicture(boolean promotePicture) { + this.mPromotePicture = promotePicture; + return this; + } + final StandardTemplateParams title(CharSequence title) { this.title = title; return this; |