From 17ee3ec0b85f1ca29920bc3bf26e613b82a0ecf8 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Fri, 29 Aug 2014 03:47:31 +0200 Subject: [PATCH] Media notification updates - Make text white. - Adjust padding & metrics to redlines. - Use different narrow layout when 3 or less notifications with big picture. - Update action ripples. - Fix progress bar size & fix color for indeterminate progress bar. - Apply default background in SystemUI when no color is set, so we don't end up with white text on white background. Bug: 15437369 Bug: 16625746 Bug: 15147533 Change-Id: Ie8bd5ad0bbca972685adb50034fff88ea97456bd --- core/java/android/app/Notification.java | 110 ++++++++++-- core/java/android/widget/RemoteViews.java | 6 +- ...otification_material_action_background.xml | 23 +++ ...ation_material_media_action_background.xml | 19 +++ .../notification_material_media_progress.xml | 28 --- .../layout/notification_material_action.xml | 1 + .../notification_material_media_action.xml | 7 +- ...tification_template_material_big_media.xml | 160 ++++-------------- ...ion_template_material_big_media_narrow.xml | 62 +++++++ .../notification_template_material_media.xml | 93 +--------- core/res/res/values/colors.xml | 5 +- core/res/res/values/styles_material.xml | 4 - core/res/res/values/symbols.xml | 8 +- packages/SystemUI/res/values/colors.xml | 4 + .../systemui/statusbar/BaseStatusBar.java | 7 +- 15 files changed, 259 insertions(+), 278 deletions(-) create mode 100644 core/res/res/drawable/notification_material_action_background.xml create mode 100644 core/res/res/drawable/notification_material_media_action_background.xml delete mode 100644 core/res/res/drawable/notification_material_media_progress.xml create mode 100644 core/res/res/layout/notification_template_material_big_media_narrow.xml diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 966d2ce2f725a..abd706b6b2643 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -22,7 +22,6 @@ import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager.NameNotFoundException; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.PorterDuff; @@ -2624,6 +2623,13 @@ public class Notification implements Parcelable } private RemoteViews applyStandardTemplate(int resId) { + return applyStandardTemplate(resId, true /* hasProgress */); + } + + /** + * @param hasProgress whether the progress bar should be shown and set + */ + private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(), mOriginatingUserId, resId); @@ -2683,7 +2689,7 @@ public class Notification implements Parcelable } } else { contentView.setViewVisibility(R.id.text2, View.GONE); - if (mProgressMax != 0 || mProgressIndeterminate) { + if (hasProgress && (mProgressMax != 0 || mProgressIndeterminate)) { contentView.setProgressBar( R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); contentView.setViewVisibility(R.id.progress, View.VISIBLE); @@ -2698,7 +2704,7 @@ public class Notification implements Parcelable shrinkLine3Text(contentView); } - if (mWhen != 0 && mShowWhen) { + if (showsTimeOrChronometer()) { if (mUseChronometer) { contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); contentView.setLong(R.id.chronometer, "setBase", @@ -2731,6 +2737,14 @@ public class Notification implements Parcelable return contentView; } + /** + * @return true if the built notification will show the time or the chronometer; false + * otherwise + */ + private boolean showsTimeOrChronometer() { + return mWhen != 0 && mShowWhen; + } + /** * Logic to find out whether the notification is going to have three lines in the contracted * layout. This is used to adjust the top padding. @@ -2740,13 +2754,14 @@ public class Notification implements Parcelable */ private boolean hasThreeLines() { boolean contentTextInLine2 = mSubText != null && mContentText != null; - + boolean hasProgress = mStyle == null || mStyle.hasProgress(); // If we have content text in line 2, badge goes into line 2, or line 3 otherwise boolean badgeInLine3 = getProfileBadgeDrawable() != null && !contentTextInLine2; boolean hasLine3 = mContentText != null || mContentInfo != null || mNumber > 0 || badgeInLine3; boolean hasLine2 = (mSubText != null && mContentText != null) || - (mSubText == null && (mProgressMax != 0 || mProgressIndeterminate)); + (hasProgress && mSubText == null + && (mProgressMax != 0 || mProgressIndeterminate)); return hasLine2 && hasLine3; } @@ -3488,6 +3503,15 @@ public class Notification implements Parcelable checkBuilder(); return mBuilder.build(); } + + /** + * @hide + * @return true if the style positions the progress bar on the second line; false if the + * style hides the progress bar + */ + protected boolean hasProgress() { + return true; + } } /** @@ -3885,7 +3909,7 @@ public class Notification implements Parcelable * @see Notification#bigContentView */ public static class MediaStyle extends Style { - static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 2; + static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; static final int MAX_MEDIA_BUTTONS = 5; private int[] mActionsToShowInCompact = null; @@ -3899,8 +3923,10 @@ public class Notification implements Parcelable } /** - * Request up to 2 actions (by index in the order of addition) to be shown in the compact + * Request up to 3 actions (by index in the order of addition) to be shown in the compact * notification view. + * + * @param actions the indices of the actions to show in the compact notification view */ public MediaStyle setShowActionsInCompactView(int...actions) { mActionsToShowInCompact = actions; @@ -3977,6 +4003,9 @@ public class Notification implements Parcelable RemoteViews button = new RemoteViews(mBuilder.mContext.getPackageName(), R.layout.notification_material_media_action); button.setImageViewResource(R.id.action0, action.icon); + button.setDrawableParameters(R.id.action0, false, -1, + 0xFFFFFFFF, + PorterDuff.Mode.SRC_ATOP, -1); if (!tombstone) { button.setOnClickPendingIntent(R.id.action0, action.actionIntent); } @@ -3986,14 +4015,14 @@ public class Notification implements Parcelable private RemoteViews makeMediaContentView() { RemoteViews view = mBuilder.applyStandardTemplate( - R.layout.notification_template_material_media); + R.layout.notification_template_material_media, false /* hasProgress */); final int numActions = mBuilder.mActions.size(); final int N = mActionsToShowInCompact == null ? 0 : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); if (N > 0) { - view.removeAllViews(R.id.actions); + view.removeAllViews(com.android.internal.R.id.media_actions); for (int i = 0; i < N; i++) { if (i >= numActions) { throw new IllegalArgumentException(String.format( @@ -4003,26 +4032,73 @@ public class Notification implements Parcelable final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); final RemoteViews button = generateMediaActionButton(action); - view.addView(R.id.actions, button); + view.addView(com.android.internal.R.id.media_actions, button); } } + styleText(view); + hideRightIcon(view); return view; } private RemoteViews makeMediaBigContentView() { - RemoteViews big = mBuilder.applyStandardTemplate( - R.layout.notification_template_material_big_media); + final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); + RemoteViews big = mBuilder.applyStandardTemplate(getBigLayoutResource(actionCount), + false /* hasProgress */); - final int N = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); - if (N > 0) { - big.removeAllViews(R.id.actions); - for (int i=0; i 0) { + big.removeAllViews(com.android.internal.R.id.media_actions); + for (int i = 0; i < actionCount; i++) { final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i)); - big.addView(R.id.actions, button); + big.addView(com.android.internal.R.id.media_actions, button); } } + styleText(big); + hideRightIcon(big); + applyTopPadding(big); + big.setViewVisibility(android.R.id.progress, View.GONE); return big; } + + private int getBigLayoutResource(int actionCount) { + if (actionCount <= 3) { + return R.layout.notification_template_material_big_media_narrow; + } else { + return R.layout.notification_template_material_big_media; + } + } + + private void hideRightIcon(RemoteViews contentView) { + contentView.setViewVisibility(R.id.right_icon, View.GONE); + } + + /** + * Applies the special text colors for media notifications to all text views. + */ + private void styleText(RemoteViews contentView) { + int primaryColor = mBuilder.mContext.getResources().getColor( + R.color.notification_media_primary_color); + int secondaryColor = mBuilder.mContext.getResources().getColor( + R.color.notification_media_secondary_color); + contentView.setTextColor(R.id.title, primaryColor); + if (mBuilder.showsTimeOrChronometer()) { + if (mBuilder.mUseChronometer) { + contentView.setTextColor(R.id.chronometer, secondaryColor); + } else { + contentView.setTextColor(R.id.time, secondaryColor); + } + } + contentView.setTextColor(R.id.text2, secondaryColor); + contentView.setTextColor(R.id.text, secondaryColor); + contentView.setTextColor(R.id.info, secondaryColor); + } + + /** + * @hide + */ + @Override + protected boolean hasProgress() { + return false; + } } // When adding a new Style subclass here, don't forget to update diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 05ff151316ef1..69d5f40802ccd 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -864,7 +864,7 @@ public class RemoteViews implements Parcelable, Filter { if (alpha != -1) { targetDrawable.setAlpha(alpha); } - if (colorFilter != -1 && filterMode != null) { + if (filterMode != null) { targetDrawable.setColorFilter(colorFilter, filterMode); } if (level != -1) { @@ -2189,8 +2189,8 @@ public class RemoteViews implements Parcelable, Filter { * @param alpha Specify an alpha value for the drawable, or -1 to leave * unchanged. * @param colorFilter Specify a color for a - * {@link android.graphics.ColorFilter} for this drawable, or -1 - * to leave unchanged. + * {@link android.graphics.ColorFilter} for this drawable. This will be ignored if + * {@code mode} is {@code null}. * @param mode Specify a PorterDuff mode for this drawable, or null to leave * unchanged. * @param level Specify the level for the drawable, or -1 to leave diff --git a/core/res/res/drawable/notification_material_action_background.xml b/core/res/res/drawable/notification_material_action_background.xml new file mode 100644 index 0000000000000..ff6f69dc7e2bc --- /dev/null +++ b/core/res/res/drawable/notification_material_action_background.xml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/core/res/res/drawable/notification_material_media_action_background.xml b/core/res/res/drawable/notification_material_media_action_background.xml new file mode 100644 index 0000000000000..8e559d571440f --- /dev/null +++ b/core/res/res/drawable/notification_material_media_action_background.xml @@ -0,0 +1,19 @@ + + + + diff --git a/core/res/res/drawable/notification_material_media_progress.xml b/core/res/res/drawable/notification_material_media_progress.xml deleted file mode 100644 index 74d871b530569..0000000000000 --- a/core/res/res/drawable/notification_material_media_progress.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - diff --git a/core/res/res/layout/notification_material_action.xml b/core/res/res/layout/notification_material_action.xml index 637d9410fc7d2..da8b2e7b4360d 100644 --- a/core/res/res/layout/notification_material_action.xml +++ b/core/res/res/layout/notification_material_action.xml @@ -29,4 +29,5 @@ android:textSize="13sp" android:singleLine="true" android:ellipsize="end" + android:background="@drawable/notification_material_action_background" /> diff --git a/core/res/res/layout/notification_material_media_action.xml b/core/res/res/layout/notification_material_media_action.xml index 331ee57254b8a..1d52e546ce94a 100644 --- a/core/res/res/layout/notification_material_media_action.xml +++ b/core/res/res/layout/notification_material_media_action.xml @@ -16,10 +16,13 @@ --> diff --git a/core/res/res/layout/notification_template_material_big_media.xml b/core/res/res/layout/notification_template_material_big_media.xml index 3c44141045720..93acdbfc6cdf0 100644 --- a/core/res/res/layout/notification_template_material_big_media.xml +++ b/core/res/res/layout/notification_template_material_big_media.xml @@ -15,143 +15,43 @@ ~ limitations under the License --> - + - - - - - - - - - - - - - - - - - - - + + + - - + + + + + diff --git a/core/res/res/layout/notification_template_material_big_media_narrow.xml b/core/res/res/layout/notification_template_material_big_media_narrow.xml new file mode 100644 index 0000000000000..21e5ff8910563 --- /dev/null +++ b/core/res/res/layout/notification_template_material_big_media_narrow.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + diff --git a/core/res/res/layout/notification_template_material_media.xml b/core/res/res/layout/notification_template_material_media.xml index db24c1f6be9df..69020a4879a1e 100644 --- a/core/res/res/layout/notification_template_material_media.xml +++ b/core/res/res/layout/notification_template_material_media.xml @@ -21,6 +21,7 @@ android:layout_width="match_parent" android:layout_height="64dp" android:orientation="horizontal" + android:background="#00000000" internal:layout_minHeight="64dp" internal:layout_maxHeight="64dp" > @@ -36,99 +37,19 @@ android:layout_gravity="fill_vertical" android:minHeight="@dimen/notification_large_icon_height" android:orientation="vertical" - android:paddingEnd="8dp" - android:paddingTop="2dp" - android:paddingBottom="2dp" - android:gravity="top" > - - - - - - - - - - - + + + diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml index 4470fc3beb08d..c42683b5bc02e 100644 --- a/core/res/res/values/colors.xml +++ b/core/res/res/values/colors.xml @@ -128,12 +128,13 @@ #3333B5E5 #0cffffff #29000000 + #29ffffff #ff9e9e9e @color/secondary_text_material_light - #00000000 - #FFFFFFFF + @color/primary_text_material_dark + @color/secondary_text_material_dark #ffffffff diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml index e783cd6d28f1e..8b3cbaf21d883 100644 --- a/core/res/res/values/styles_material.xml +++ b/core/res/res/values/styles_material.xml @@ -438,10 +438,6 @@ please see styles_device_defaults.xml. -