diff options
| author | 2021-01-20 15:15:02 +0000 | |
|---|---|---|
| committer | 2021-01-20 15:15:02 +0000 | |
| commit | 98668dc59c109d800ab58b20c9c26e3783670b81 (patch) | |
| tree | e0740131b63c74bcaa0ce1078a9c6283bf2f352f | |
| parent | 5be018438d5569809e6528b3f7261f5fbb83a343 (diff) | |
| parent | 16a62a9ac5f980383357c014a85b765d6877f9e1 (diff) | |
Merge changes from topic "promote_big_picture"
* changes:
Unhide the API to promote the picture
Add (still hidden) API to promote the big picture to the collapsed state
| -rw-r--r-- | core/api/current.txt | 12 | ||||
| -rw-r--r-- | core/java/android/app/Notification.java | 113 |
2 files changed, 111 insertions, 14 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 1d9fa8695a37..06c37d21ed37 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -5573,6 +5573,7 @@ package android.app { field public static final String EXTRA_PROGRESS = "android.progress"; field public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; field public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; + field public static final String EXTRA_PROMOTE_PICTURE = "android.promotePicture"; field public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; field public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; field @Deprecated public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; @@ -5712,12 +5713,13 @@ package android.app { public static class Notification.BigPictureStyle extends android.app.Notification.Style { ctor public Notification.BigPictureStyle(); ctor @Deprecated public Notification.BigPictureStyle(android.app.Notification.Builder); - method public android.app.Notification.BigPictureStyle bigLargeIcon(android.graphics.Bitmap); - method public android.app.Notification.BigPictureStyle bigLargeIcon(android.graphics.drawable.Icon); - method public android.app.Notification.BigPictureStyle bigPicture(android.graphics.Bitmap); + method @NonNull public android.app.Notification.BigPictureStyle bigLargeIcon(@Nullable android.graphics.Bitmap); + method @NonNull public android.app.Notification.BigPictureStyle bigLargeIcon(@Nullable android.graphics.drawable.Icon); + method @NonNull public android.app.Notification.BigPictureStyle bigPicture(@Nullable android.graphics.Bitmap); method @NonNull public android.app.Notification.BigPictureStyle bigPictureContentDescription(@Nullable CharSequence); - method public android.app.Notification.BigPictureStyle setBigContentTitle(CharSequence); - method public android.app.Notification.BigPictureStyle setSummaryText(CharSequence); + method @NonNull public android.app.Notification.BigPictureStyle setBigContentTitle(@Nullable CharSequence); + method @NonNull public android.app.Notification.BigPictureStyle setSummaryText(@Nullable CharSequence); + method @NonNull public android.app.Notification.BigPictureStyle showBigPictureWhenCollapsed(boolean); } public static class Notification.BigTextStyle extends android.app.Notification.Style { diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index f6a06f3ed5ef..b166d31ce5df 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -1198,6 +1198,14 @@ 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. + */ + 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 +5157,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 +5168,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 +5196,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 +7004,7 @@ public class Notification implements Parcelable private Icon mBigLargeIcon; private boolean mBigLargeIconSet = false; private CharSequence mPictureContentDescription; + private boolean mPromotePicture; public BigPictureStyle() { } @@ -7011,7 +7021,8 @@ public class Notification implements Parcelable * Overrides ContentTitle in the big form of the template. * This defaults to the value passed to setContentTitle(). */ - public BigPictureStyle setBigContentTitle(CharSequence title) { + @NonNull + public BigPictureStyle setBigContentTitle(@Nullable CharSequence title) { internalSetBigContentTitle(safeCharSequence(title)); return this; } @@ -7019,7 +7030,8 @@ public class Notification implements Parcelable /** * Set the first line of text after the detail section in the big form of the template. */ - public BigPictureStyle setSummaryText(CharSequence cs) { + @NonNull + public BigPictureStyle setSummaryText(@Nullable CharSequence cs) { internalSetSummaryText(safeCharSequence(cs)); return this; } @@ -7044,22 +7056,36 @@ public class Notification implements Parcelable /** * Provide the bitmap to be used as the payload for the BigPicture notification. */ - public BigPictureStyle bigPicture(Bitmap b) { + @NonNull + public BigPictureStyle bigPicture(@Nullable Bitmap b) { mPicture = b; return this; } /** + * 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. + */ + @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) { + @NonNull + public BigPictureStyle bigLargeIcon(@Nullable Bitmap b) { return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); } /** * Override the large icon when the big notification is shown. */ - public BigPictureStyle bigLargeIcon(Icon icon) { + @NonNull + public BigPictureStyle bigLargeIcon(@Nullable Icon icon) { mBigLargeIconSet = true; mBigLargeIcon = icon; return this; @@ -7112,6 +7138,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 +7254,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 +7275,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 +11394,7 @@ public class Notification implements Parcelable boolean mHideTitle; boolean mHideActions; boolean mHideProgress; + boolean mPromotePicture; CharSequence title; CharSequence text; CharSequence headerTextSecondary; @@ -11321,6 +11410,7 @@ public class Notification implements Parcelable mHideTitle = false; mHideActions = false; mHideProgress = false; + mPromotePicture = false; title = null; text = null; summaryText = null; @@ -11360,6 +11450,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; |