From 247fa0193196c9d190770b641cfc28e862525012 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Thu, 18 Feb 2016 09:50:48 -0800 Subject: [PATCH] Cleaned up the logic for the picture end margin This allows decorated custom remote views to be properly showing with a large image. Bug: 24866646 Change-Id: Ie355e503437f19ace2503d42f44bee4bd22f03c8 --- core/java/android/app/Notification.java | 71 +++++++++++-------- core/res/res/values/dimens.xml | 3 - core/res/res/values/symbols.xml | 1 - .../systemui/statusbar/NotificationData.java | 9 ++- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 01a9ff9864f32..e290d3e9475bf 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -895,6 +895,11 @@ public class Notification implements Parcelable */ public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; + /** + * @hide + */ + public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; + private Icon mSmallIcon; private Icon mLargeIcon; @@ -3534,6 +3539,10 @@ public class Notification implements Parcelable mN.extras.putStringArray(EXTRA_PEOPLE, mPersonList.toArray(new String[mPersonList.size()])); } + if (mN.bigContentView != null || mN.contentView != null + || mN.headsUpContentView != null) { + mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); + } return mN; } @@ -4203,6 +4212,7 @@ public class Notification implements Parcelable final float density = mBuilder.mContext.getResources().getDisplayMetrics().density; int topPadding = (int) (5 * density); int bottomPadding = (int) (13 * density); + boolean first = true; while (i < mTexts.size() && i < rowIds.length) { CharSequence str = mTexts.get(i); if (str != null && !str.equals("")) { @@ -4214,23 +4224,26 @@ public class Notification implements Parcelable } contentView.setViewPadding(rowIds[i], 0, topPadding, 0, i == rowIds.length - 1 || i == mTexts.size() - 1 ? bottomPadding : 0); + handleInboxImageMargin(contentView, rowIds[i], first); + first = false; } i++; } - handleInboxImageMargin(contentView, rowIds[0]); return contentView; } - private void handleInboxImageMargin(RemoteViews contentView, int id) { - final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); - final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); - boolean hasProgress = max != 0 || ind; + private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { int endMargin = 0; - if (mTexts.size() > 0 && mBuilder.mN.mLargeIcon != null && !hasProgress) { - endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( - R.dimen.notification_content_picture_margin); + if (first) { + final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); + final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); + boolean hasProgress = max != 0 || ind; + if (mBuilder.mN.mLargeIcon != null && !hasProgress) { + endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( + R.dimen.notification_content_picture_margin); + } } contentView.setViewLayoutMarginEnd(id, endMargin); } @@ -4413,13 +4426,11 @@ public class Notification implements Parcelable } handleImage(view); // handle the content margin - int endMargin; + int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( + R.dimen.notification_content_margin_end);; if (mBuilder.mN.mLargeIcon != null) { - endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( - R.dimen.notification_content_picture_margin_media); - } else { - endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( - R.dimen.notification_content_margin_end); + endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( + R.dimen.notification_content_picture_margin); } view.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); return view; @@ -4529,9 +4540,6 @@ public class Notification implements Parcelable return makeDecoratedHeadsUpContentView(); } - /** - * @hide - */ private RemoteViews makeDecoratedHeadsUpContentView() { RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null ? mBuilder.mN.contentView @@ -4541,25 +4549,17 @@ public class Notification implements Parcelable } RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( mBuilder.getBigBaseLayoutResource()); - remoteViews.removeAllViews(R.id.notification_main_column); - remoteViews.addView(R.id.notification_main_column, headsUpContentView); + buildIntoRemoteViewContent(remoteViews, headsUpContentView); return remoteViews; } - /** - * @hide - */ private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { RemoteViews remoteViews = mBuilder.applyStandardTemplate( mBuilder.getBaseLayoutResource()); - remoteViews.removeAllViews(R.id.notification_main_column); - remoteViews.addView(R.id.notification_main_column, customContent); + buildIntoRemoteViewContent(remoteViews, customContent); return remoteViews; } - /** - * @hide - */ private RemoteViews makeDecoratedBigContentView() { RemoteViews bigContentView = mBuilder.mN.bigContentView == null ? mBuilder.mN.contentView @@ -4569,10 +4569,23 @@ public class Notification implements Parcelable } RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( mBuilder.getBigBaseLayoutResource()); - remoteViews.removeAllViews(R.id.notification_main_column); - remoteViews.addView(R.id.notification_main_column, bigContentView); + buildIntoRemoteViewContent(remoteViews, bigContentView); return remoteViews; } + + private void buildIntoRemoteViewContent(RemoteViews remoteViews, + RemoteViews customContent) { + remoteViews.removeAllViews(R.id.notification_main_column); + remoteViews.addView(R.id.notification_main_column, customContent); + // also update the end margin if there is an image + int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( + R.dimen.notification_content_margin_end); + if (mBuilder.mN.mLargeIcon != null) { + endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( + R.dimen.notification_content_picture_margin); + } + remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); + } } // When adding a new Style subclass here, don't forget to update diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml index 8e86f78e02fd9..c9a64f3caf2a3 100644 --- a/core/res/res/values/dimens.xml +++ b/core/res/res/values/dimens.xml @@ -146,9 +146,6 @@ 56dp - - 72dp - 30dp diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index f75f023b8c313..9113514dbb046 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2511,7 +2511,6 @@ - diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java index 2cacb8aedd654..ccd0ad857bbed 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java @@ -34,6 +34,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Objects; /** * The list of currently displaying notifications. @@ -118,10 +119,16 @@ public class NotificationData { final RemoteViews newPublicNotification = updatedNotificationBuilder.makePublicContentView(); + boolean sameCustomView = Objects.equals( + notification.getNotification().extras.getBoolean( + Notification.EXTRA_CONTAINS_CUSTOM_VIEW), + updatedNotification.extras.getBoolean( + Notification.EXTRA_CONTAINS_CUSTOM_VIEW)); applyInPlace = compareRemoteViews(cachedContentView, newContentView) && compareRemoteViews(cachedBigContentView, newBigContentView) && compareRemoteViews(cachedHeadsUpContentView, newHeadsUpContentView) - && compareRemoteViews(cachedPublicContentView, newPublicNotification); + && compareRemoteViews(cachedPublicContentView, newPublicNotification) + && sameCustomView; cachedPublicContentView = newPublicNotification; cachedHeadsUpContentView = newHeadsUpContentView; cachedBigContentView = newBigContentView;