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 e6dab63b593cf..0000000000000 Binary files a/core/res/res/drawable-hdpi/title_bar_shadow.9.png and /dev/null differ 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 dbcefee17a329..0000000000000 Binary files a/core/res/res/drawable-mdpi/title_bar_shadow.9.png and /dev/null differ diff --git a/core/res/res/drawable-xhdpi/title_bar_shadow.9.png b/core/res/res/drawable-xhdpi/title_bar_shadow.9.png deleted file mode 100644 index 45b545602d560..0000000000000 Binary files a/core/res/res/drawable-xhdpi/title_bar_shadow.9.png and /dev/null differ 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 9b3c05efe3732..af73c02e04ee7 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -350,7 +350,11 @@ - + + + + + @@ -1704,12 +1708,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 e86f891ae9759..0000000000000 Binary files a/packages/SystemUI/res/drawable-xxhdpi/title_bar_shadow.9.png and /dev/null differ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 53bdcbfd2c925..3a20b006331c8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -1183,7 +1183,10 @@ public abstract class BaseStatusBar extends SystemUI implements icon.setImageDrawable(iconDrawable); if (mNotificationColorUtil.isGrayscale(iconDrawable)) { icon.setBackgroundResource( - com.android.internal.R.drawable.notification_icon_legacy_bg_inset); + com.android.internal.R.drawable.notification_icon_legacy_bg); + int padding = mContext.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.notification_large_icon_circle_padding); + icon.setPadding(padding, padding, padding, padding); } if (profileIcon != null) { @@ -1214,6 +1217,11 @@ public abstract class BaseStatusBar extends SystemUI implements R.style.TextAppearance_StatusBar_Material_EventContent_Parenthetical); } + int topPadding = Notification.Builder.calculateTopPadding(mContext, + false /* hasThreeLines */, + mContext.getResources().getConfiguration().fontScale); + title.setPadding(0, topPadding, 0, 0); + entry.autoRedacted = true; }