From 445d3c0a6f471b4bb1bd37ad5da0fd90c6ce2825 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Tue, 19 Aug 2014 22:33:42 +0200 Subject: [PATCH] Update notification layouts to match redlines Also fixes a lot of paddings and other small issues with the notification layouts. Bug: 15437369 Change-Id: I40b6c69afc160c498b7e2e709814b5b847f615de --- core/java/android/app/Notification.java | 122 ++++++++++++------ .../res/drawable-hdpi/title_bar_shadow.9.png | Bin 198 -> 0 bytes .../res/drawable-mdpi/title_bar_shadow.9.png | Bin 173 -> 0 bytes .../res/drawable-xhdpi/title_bar_shadow.9.png | Bin 188 -> 0 bytes ...gacy_bg_inset.xml => title_bar_shadow.xml} | 14 +- .../layout/notification_material_action.xml | 4 +- .../notification_material_action_list.xml | 3 - .../notification_template_icon_group.xml | 19 +-- .../notification_template_material_base.xml | 19 +-- ...otification_template_material_big_base.xml | 17 ++- ...otification_template_material_big_text.xml | 74 +++++++++++ .../notification_template_material_inbox.xml | 14 +- .../notification_template_part_line1.xml | 3 +- .../notification_template_part_line2.xml | 8 +- .../notification_template_part_line3.xml | 3 +- core/res/res/values/colors.xml | 1 + core/res/res/values/dimens.xml | 19 ++- core/res/res/values/styles_material.xml | 4 +- core/res/res/values/symbols.xml | 8 +- .../drawable-xxhdpi/title_bar_shadow.9.png | Bin 1128 -> 0 bytes .../systemui/statusbar/BaseStatusBar.java | 10 +- 21 files changed, 242 insertions(+), 100 deletions(-) delete mode 100644 core/res/res/drawable-hdpi/title_bar_shadow.9.png delete mode 100644 core/res/res/drawable-mdpi/title_bar_shadow.9.png delete mode 100644 core/res/res/drawable-xhdpi/title_bar_shadow.9.png rename core/res/res/drawable/{notification_icon_legacy_bg_inset.xml => title_bar_shadow.xml} (69%) create mode 100644 core/res/res/layout/notification_template_material_big_text.xml delete mode 100644 packages/SystemUI/res/drawable-xxhdpi/title_bar_shadow.9.png diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 70ba8ea36036d..47967baaae793 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -40,6 +40,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.text.TextUtils; import android.util.Log; +import android.util.MathUtils; import android.util.TypedValue; import android.view.Gravity; import android.view.View; @@ -1755,6 +1756,7 @@ public class Notification implements Parcelable */ public static class Builder { private static final int MAX_ACTION_BUTTONS = 3; + private static final float LARGE_TEXT_SCALE = 1.3f; /** * @hide @@ -2577,28 +2579,14 @@ public class Notification implements Parcelable return bitmap; } - private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) { - final boolean largeFontScale - = mContext.getResources().getConfiguration().fontScale >= 1.25f; - + private RemoteViews applyStandardTemplate(int resId) { Bitmap profileIcon = getProfileBadge(); RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(), mOriginatingUserId, resId); - if (largeFontScale) { - // Make a little extra room for the bigger text. - final int margin = (int) mContext.getResources() - .getDimensionPixelSize(R.dimen.notification_large_font_vert_pad); - contentView.setViewPadding(R.id.line1, 0, margin, 0, 0); - contentView.setViewPadding(R.id.line3, 0, 0, 0, margin); - } - boolean showLine3 = false; boolean showLine2 = false; - if (mPriority < PRIORITY_LOW) { - // TODO: Low priority presentation - } if (profileIcon != null) { contentView.setImageViewBitmap(R.id.profile_icon, profileIcon); contentView.setViewVisibility(R.id.profile_icon, View.VISIBLE); @@ -2666,15 +2654,12 @@ public class Notification implements Parcelable } } if (showLine2) { - if (fitIn1U) { - // need to shrink all the type to make sure everything fits - final Resources res = mContext.getResources(); - final float subTextSize = res.getDimensionPixelSize( - R.dimen.notification_subtext_size); - contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); - } - // vertical centering - contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); + + // need to shrink all the type to make sure everything fits + final Resources res = mContext.getResources(); + final float subTextSize = res.getDimensionPixelSize( + R.dimen.notification_subtext_size); + contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); } if (mWhen != 0 && mShowWhen) { @@ -2691,13 +2676,51 @@ public class Notification implements Parcelable contentView.setViewVisibility(R.id.time, View.GONE); } + // Adjust padding depending on line count and font size. + contentView.setViewPadding(R.id.line1, 0, calculateTopPadding(mContext, + hasThreeLines(), mContext.getResources().getConfiguration().fontScale), + 0, 0); + contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE); return contentView; } + /** + * 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. + * + * @return true if the notification is going to have three lines; false if the notification + * is going to have one or two lines + */ + private boolean hasThreeLines() { + boolean hasLine3 = mContentText != null || mContentInfo != null || mNumber > 0; + boolean hasLine2 = (mSubText != null && mContentText != null) || + (mSubText == null && (mProgressMax != 0 || mProgressIndeterminate)); + return hasLine2 && hasLine3; + } + + /** + * @hide + */ + public static int calculateTopPadding(Context ctx, boolean hasThreeLines, + float fontScale) { + int padding = ctx.getResources().getDimensionPixelSize(hasThreeLines + ? R.dimen.notification_top_pad_narrow + : R.dimen.notification_top_pad); + int largePadding = ctx.getResources().getDimensionPixelSize(hasThreeLines + ? R.dimen.notification_top_pad_large_text_narrow + : R.dimen.notification_top_pad_large_text); + float largeFactor = (MathUtils.constrain(fontScale, 1.0f, LARGE_TEXT_SCALE) - 1f) + / (LARGE_TEXT_SCALE - 1f); + + // Linearly interpolate the padding between large and normal with the font scale ranging + // from 1f to LARGE_TEXT_SCALE + return Math.round((1 - largeFactor) * padding + largeFactor * largePadding); + } + private RemoteViews applyStandardTemplateWithActions(int layoutId) { - RemoteViews big = applyStandardTemplate(layoutId, false); + RemoteViews big = applyStandardTemplate(layoutId); int N = mActions.size(); if (N > 0) { @@ -2717,7 +2740,7 @@ public class Notification implements Parcelable if (mContentView != null) { return mContentView; } else { - return applyStandardTemplate(getBaseLayoutResource(), true); // no more special large_icon flavor + return applyStandardTemplate(getBaseLayoutResource()); } } @@ -2810,7 +2833,7 @@ public class Notification implements Parcelable */ private void applyLargeIconBackground(RemoteViews contentView) { contentView.setInt(R.id.icon, "setBackgroundResource", - R.drawable.notification_icon_legacy_bg_inset); + R.drawable.notification_icon_legacy_bg); contentView.setDrawableParameters( R.id.icon, @@ -2819,6 +2842,10 @@ public class Notification implements Parcelable resolveColor(), PorterDuff.Mode.SRC_ATOP, -1); + + int padding = mContext.getResources().getDimensionPixelSize( + R.dimen.notification_large_icon_circle_padding); + contentView.setViewPadding(R.id.icon, padding, padding, padding, padding); } private void removeLargeIconBackground(RemoteViews contentView) { @@ -3234,7 +3261,7 @@ public class Notification implements Parcelable } private int getBigTextLayoutResource() { - return getBigBaseLayoutResource(); + return R.layout.notification_template_material_big_text; } private int getInboxLayoutResource() { @@ -3327,6 +3354,19 @@ public class Notification implements Parcelable return contentView; } + /** + * Changes the padding of the first line such that the big and small content view have the + * same top padding. + * + * @hide + */ + protected void applyTopPadding(RemoteViews contentView) { + int topPadding = Builder.calculateTopPadding(mBuilder.mContext, + mBuilder.hasThreeLines(), + mBuilder.mContext.getResources().getConfiguration().fontScale); + contentView.setViewPadding(R.id.line1, 0, topPadding, 0, 0); + } + /** * @hide */ @@ -3465,6 +3505,8 @@ public class Notification implements Parcelable contentView.setImageViewBitmap(R.id.big_picture, mPicture); + applyTopPadding(contentView); + return contentView; } @@ -3575,8 +3617,6 @@ public class Notification implements Parcelable } private RemoteViews makeBigContentView() { - // Remove the content text so line3 only shows if you have a summary - final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null); // Nasty CharSequence oldBuilderContentText = mBuilder.mContentText; @@ -3586,15 +3626,12 @@ public class Notification implements Parcelable mBuilder.mContentText = oldBuilderContentText; - if (hadThreeLines) { - // vertical centering - contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); - } - contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText)); contentView.setViewVisibility(R.id.big_text, View.VISIBLE); contentView.setViewVisibility(R.id.text2, View.GONE); + applyTopPadding(contentView); + return contentView; } @@ -3706,13 +3743,20 @@ public class Notification implements Parcelable contentView.setViewVisibility(rowId, View.GONE); } - + final boolean largeText = + mBuilder.mContext.getResources().getConfiguration().fontScale > 1f; + final float subTextSize = mBuilder.mContext.getResources().getDimensionPixelSize( + R.dimen.notification_subtext_size); int i=0; while (i < mTexts.size() && i < rowIds.length) { CharSequence str = mTexts.get(i); if (str != null && !str.equals("")) { contentView.setViewVisibility(rowIds[i], View.VISIBLE); contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); + if (largeText) { + contentView.setTextViewTextSize(rowIds[i], TypedValue.COMPLEX_UNIT_PX, + subTextSize); + } } i++; } @@ -3723,6 +3767,8 @@ public class Notification implements Parcelable contentView.setViewVisibility(R.id.inbox_more, mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE); + applyTopPadding(contentView); + return contentView; } @@ -3876,7 +3922,7 @@ public class Notification implements Parcelable private RemoteViews makeMediaContentView() { RemoteViews view = mBuilder.applyStandardTemplate( - R.layout.notification_template_material_media, true /* 1U */); + R.layout.notification_template_material_media); final int numActions = mBuilder.mActions.size(); final int N = mActionsToShowInCompact == null @@ -3901,7 +3947,7 @@ public class Notification implements Parcelable private RemoteViews makeMediaBigContentView() { RemoteViews big = mBuilder.applyStandardTemplate( - R.layout.notification_template_material_big_media, false); + R.layout.notification_template_material_big_media); final int N = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); if (N > 0) { diff --git a/core/res/res/drawable-hdpi/title_bar_shadow.9.png b/core/res/res/drawable-hdpi/title_bar_shadow.9.png deleted file mode 100644 index e6dab63b593cf35a837feef1c8ac5b3b37bf6a42..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 198 zcmeAS@N?(olHy`uVBq!ia0vp^3P8-w!3HGd1p66*lw^r(L`iUdT1k0gQ7VIDN`6wR zf@f}GdTLN=VoGJ<$y6Jlq6|+L$B>F!Nq_$Tw`W#um^e`|g+Y1evj$Tp-pGRnK>2bO z?kTp(3Nj2_wlkRb8S@Ab2t)H4>_bVH83zUd@ok(zR(ix4z!cO)78&qol`;+0O}Jvg#Z8m diff --git a/core/res/res/drawable-mdpi/title_bar_shadow.9.png b/core/res/res/drawable-mdpi/title_bar_shadow.9.png deleted file mode 100644 index dbcefee17a3290b005bef5460851a5394c46f9af..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^VnEEn!3HG%X7FDCQj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jiu^rY978H@CH?vT-=2A6!^DY#OJ+=zuuX7v;MJB`!O@WB zw!z`1@rq1?6X^!c_l*K15Af9aYB$>l-cE1}h!B>(tkPn5BY|zj!;n$~hXzIlA2#vg Tux{rnpwSGTu6{1-oD!ME zD;!SWX*+xB1-nzZwsS@i^OcH=hgS*wlKrwptA%6l8ZJer{MAk!7mlwIQ2Me}>(|td iC;M%*{{32??9IAON4O#|G-*B1W(H4JKbLh*2~7adl0xJF diff --git a/core/res/res/drawable/notification_icon_legacy_bg_inset.xml b/core/res/res/drawable/title_bar_shadow.xml similarity index 69% rename from core/res/res/drawable/notification_icon_legacy_bg_inset.xml rename to core/res/res/drawable/title_bar_shadow.xml index 96c557366189f..37b0b8f3d8832 100644 --- a/core/res/res/drawable/notification_icon_legacy_bg_inset.xml +++ b/core/res/res/drawable/title_bar_shadow.xml @@ -14,8 +14,12 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> - - + + + \ No newline at end of file diff --git a/core/res/res/layout/notification_material_action.xml b/core/res/res/layout/notification_material_action.xml index 8f8c4fba2b425..637d9410fc7d2 100644 --- a/core/res/res/layout/notification_material_action.xml +++ b/core/res/res/layout/notification_material_action.xml @@ -25,8 +25,8 @@ android:gravity="start|center_vertical" android:drawablePadding="8dp" android:paddingStart="8dp" - android:textColor="#555555" - android:textSize="@dimen/notification_text_size" + android:textColor="@color/secondary_text_material_light" + android:textSize="13sp" android:singleLine="true" android:ellipsize="end" /> diff --git a/core/res/res/layout/notification_material_action_list.xml b/core/res/res/layout/notification_material_action_list.xml index ec4919b6041c4..2a36949d70c1f 100644 --- a/core/res/res/layout/notification_material_action_list.xml +++ b/core/res/res/layout/notification_material_action_list.xml @@ -22,9 +22,6 @@ android:orientation="horizontal" android:visibility="gone" android:layout_marginBottom="8dp" - android:showDividers="middle" - android:divider="@drawable/list_divider_holo_light" - android:dividerPadding="12dp" > diff --git a/core/res/res/layout/notification_template_icon_group.xml b/core/res/res/layout/notification_template_icon_group.xml index 2ad6f9ef82fa6..fa6616327cc09 100644 --- a/core/res/res/layout/notification_template_icon_group.xml +++ b/core/res/res/layout/notification_template_icon_group.xml @@ -23,20 +23,23 @@ android:id="@+id/icon_group" > diff --git a/core/res/res/layout/notification_template_material_base.xml b/core/res/res/layout/notification_template_material_base.xml index 5e51db92ad26d..674d7b8819180 100644 --- a/core/res/res/layout/notification_template_material_base.xml +++ b/core/res/res/layout/notification_template_material_base.xml @@ -31,25 +31,12 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="top" - android:layout_marginEnd="8dp" android:layout_marginStart="@dimen/notification_large_icon_width" android:minHeight="@dimen/notification_large_icon_height" android:orientation="vertical" > - - - + + + diff --git a/core/res/res/layout/notification_template_material_big_base.xml b/core/res/res/layout/notification_template_material_big_base.xml index 2243a0927cf59..3d8a52720e9fb 100644 --- a/core/res/res/layout/notification_template_material_big_base.xml +++ b/core/res/res/layout/notification_template_material_big_base.xml @@ -31,7 +31,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" - android:layout_marginEnd="8dp" android:layout_marginStart="@dimen/notification_large_icon_width" android:minHeight="@dimen/notification_large_icon_height" android:orientation="vertical" @@ -42,22 +41,26 @@ android:textAppearance="@style/TextAppearance.StatusBar.Material.EventContent" android:layout_width="match_parent" android:layout_height="wrap_content" - android:minHeight="@dimen/notification_large_icon_height" - android:layout_weight="1" + android:layout_marginEnd="8dp" android:singleLine="false" android:visibility="gone" /> - + + android:background="@drawable/notification_template_divider" /> diff --git a/core/res/res/layout/notification_template_material_big_text.xml b/core/res/res/layout/notification_template_material_big_text.xml new file mode 100644 index 0000000000000..36f870179b2cb --- /dev/null +++ b/core/res/res/layout/notification_template_material_big_text.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + diff --git a/core/res/res/layout/notification_template_material_inbox.xml b/core/res/res/layout/notification_template_material_inbox.xml index 6133791c75258..ef6cbd07ad9d5 100644 --- a/core/res/res/layout/notification_template_material_inbox.xml +++ b/core/res/res/layout/notification_template_material_inbox.xml @@ -113,7 +113,7 @@ @@ -122,7 +122,7 @@ android:layout_height="1dip" android:id="@+id/action_divider" android:visibility="gone" - android:background="@drawable/list_divider_holo_light" /> + android:background="@drawable/notification_template_divider" /> - + android:background="@drawable/notification_template_divider" /> + diff --git a/core/res/res/layout/notification_template_part_line1.xml b/core/res/res/layout/notification_template_part_line1.xml index d652959ebd3f2..c6ea6bf591e08 100644 --- a/core/res/res/layout/notification_template_part_line1.xml +++ b/core/res/res/layout/notification_template_part_line1.xml @@ -19,9 +19,8 @@ android:id="@+id/line1" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginEnd="8dp" android:orientation="horizontal" - android:paddingTop="@dimen/notification_vert_pad" - android:layout_weight="0" > #3333B5E5 #0cffffff + #29000000 #ff9e9e9e #ff555555 diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml index e58bc6f21c4ab..6022bdc9ca2ef 100644 --- a/core/res/res/values/dimens.xml +++ b/core/res/res/values/dimens.xml @@ -215,17 +215,26 @@ 180dp - 13sp + 14sp 16sp 12sp - - 10dp + + 10dp - - 3dp + + 4dp + + + 5dp + + + -4dp + + + 11dp diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml index c8ea699ce7c51..fb70d6bd0be82 100644 --- a/core/res/res/values/styles_material.xml +++ b/core/res/res/values/styles_material.xml @@ -413,12 +413,12 @@ please see styles_device_defaults.xml. diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 0b3a132066ca7..2e5c8a4b29db2 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -349,7 +349,11 @@ - + + + + + @@ -1705,12 +1709,12 @@ + - diff --git a/packages/SystemUI/res/drawable-xxhdpi/title_bar_shadow.9.png b/packages/SystemUI/res/drawable-xxhdpi/title_bar_shadow.9.png deleted file mode 100644 index e86f891ae9759980e7bf18ffc19993a188d4d9cc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1128 zcmbVLO=#3u9DnQ7+O1X)yr>6XQxGZ6DVXoFhL(xvBg z6oAyM+nnN4^)rUeyo{CDWMVH6XaGh}#(`zGD2Fq2&h-n@e-9r^&~*yZg1_1ypX(h%JV;sK@M37c6r3ZK1?acw?Lm zT~QQkfiQc~qdu>Zf+YTA9M>^WDUUGLMv$f;HIH$gl*>BKmavHl(bR00V<&7rXX0#L zKr~fwm?%%GS`{g!5n^guu3YV6YktHn-=vJ4c(uqQw^C1H}h+_JLs$BQjQ>88BscM=PRn7HO-uERO2|Ib72w9=2(US9s??)r=M`@O}ZF?pr`|Ka`cuHSzA z^ZK6KE4%uS1DFC104s~F2j<451J_c|o-p;@v1Vnk2NVZrvF~Z`LUG{6Iha!6uLmcJ zKY+m=0ReXgcPqt`UcCEh!|Mlsq+Wj7`{Gux7lF%s?8C*s