diff options
20 files changed, 125 insertions, 40 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 8d4925d8182d..127a08b04e87 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -6143,6 +6143,20 @@ public class Notification implements Parcelable result.mTitleMarginSet.applyToView(contentView, p.mTextViewId); contentView.setInt(p.mTextViewId, "setNumIndentLines", p.hasTitle() ? 0 : 1); } + // The expand button uses paddings rather than margins, so we'll adjust it + // separately. + adjustExpandButtonPadding(contentView, result.mRightIconVisible); + } + + private void adjustExpandButtonPadding(RemoteViews contentView, boolean rightIconVisible) { + if (notificationsRedesignTemplates()) { + final Resources res = mContext.getResources(); + int normalPadding = res.getDimensionPixelSize(R.dimen.notification_2025_margin); + int iconSpacing = res.getDimensionPixelSize( + R.dimen.notification_2025_expand_button_right_icon_spacing); + contentView.setInt(R.id.expand_button, "setStartPadding", + rightIconVisible ? iconSpacing : normalPadding); + } } // This code is executed on behalf of other apps' notifications, sometimes even by 3p apps, @@ -6154,12 +6168,21 @@ public class Notification implements Parcelable @NonNull TemplateBindResult result) { final Resources resources = mContext.getResources(); final float density = resources.getDisplayMetrics().density; - final float iconMarginDp = resources.getDimension( - R.dimen.notification_right_icon_content_margin) / density; + int iconMarginId = notificationsRedesignTemplates() + ? R.dimen.notification_2025_right_icon_content_margin + : R.dimen.notification_right_icon_content_margin; + final float iconMarginDp = resources.getDimension(iconMarginId) / density; final float contentMarginDp = resources.getDimension( R.dimen.notification_content_margin_end) / density; - final float expanderSizeDp = resources.getDimension( - R.dimen.notification_header_expand_icon_size) / density - contentMarginDp; + float spaceForExpanderDp; + if (notificationsRedesignTemplates()) { + spaceForExpanderDp = resources.getDimension( + R.dimen.notification_2025_right_icon_expanded_margin_end) / density + - contentMarginDp; + } else { + spaceForExpanderDp = resources.getDimension( + R.dimen.notification_header_expand_icon_size) / density - contentMarginDp; + } final float viewHeightDp = resources.getDimension( R.dimen.notification_right_icon_size) / density; float viewWidthDp = viewHeightDp; // icons are 1:1 by default @@ -6176,9 +6199,10 @@ public class Notification implements Parcelable } } } + // Margin needed for the header to accommodate the icon when shown final float extraMarginEndDpIfVisible = viewWidthDp + iconMarginDp; result.setRightIconState(rightIcon != null /* visible */, viewWidthDp, - viewHeightDp, extraMarginEndDpIfVisible, expanderSizeDp); + viewHeightDp, extraMarginEndDpIfVisible, spaceForExpanderDp); } /** @@ -14658,13 +14682,19 @@ public class Notification implements Parcelable public final MarginSet mTitleMarginSet = new MarginSet(); public void setRightIconState(boolean visible, float widthDp, float heightDp, - float marginEndDpIfVisible, float expanderSizeDp) { + float marginEndDpIfVisible, float spaceForExpanderDp) { mRightIconVisible = visible; mRightIconWidthDp = widthDp; mRightIconHeightDp = heightDp; - mHeadingExtraMarginSet.setValues(0, marginEndDpIfVisible); - mHeadingFullMarginSet.setValues(expanderSizeDp, marginEndDpIfVisible + expanderSizeDp); - mTitleMarginSet.setValues(0, marginEndDpIfVisible + expanderSizeDp); + mHeadingExtraMarginSet.setValues( + /* valueIfGone = */ 0, + /* valueIfVisible = */ marginEndDpIfVisible); + mHeadingFullMarginSet.setValues( + /* valueIfGone = */ spaceForExpanderDp, + /* valueIfVisible = */ marginEndDpIfVisible + spaceForExpanderDp); + mTitleMarginSet.setValues( + /* valueIfGone = */ 0, + /* valueIfVisible = */ marginEndDpIfVisible + spaceForExpanderDp); } /** diff --git a/core/java/com/android/internal/widget/NotificationExpandButton.java b/core/java/com/android/internal/widget/NotificationExpandButton.java index dd12f69a56fb..42b1bdbc51b2 100644 --- a/core/java/com/android/internal/widget/NotificationExpandButton.java +++ b/core/java/com/android/internal/widget/NotificationExpandButton.java @@ -129,6 +129,16 @@ public class NotificationExpandButton extends FrameLayout { updateExpandedState(); } + /** + * Adjust the padding at the start of the view based on the layout direction (RTL/LTR). + * This is needed because RemoteViews don't have an equivalent for + * {@link this#setPaddingRelative}. + */ + @RemotableViewMethod + public void setStartPadding(int startPadding) { + setPaddingRelative(startPadding, getPaddingTop(), getPaddingEnd(), getPaddingBottom()); + } + private void updateExpandedState() { int drawableId; int contentDescriptionId; diff --git a/core/res/res/layout/notification_2025_expand_button.xml b/core/res/res/layout/notification_2025_expand_button.xml index 1c367544c90a..8ba844a4868b 100644 --- a/core/res/res/layout/notification_2025_expand_button.xml +++ b/core/res/res/layout/notification_2025_expand_button.xml @@ -15,6 +15,7 @@ --> <!-- extends FrameLayout --> +<!-- Note: The button's padding may be dynamically adjusted in code --> <com.android.internal.widget.NotificationExpandButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/expand_button" diff --git a/core/res/res/layout/notification_2025_right_icon.xml b/core/res/res/layout/notification_2025_right_icon.xml new file mode 100644 index 000000000000..24d381d10501 --- /dev/null +++ b/core/res/res/layout/notification_2025_right_icon.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + ~ Copyright (C) 2025 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<!-- Large icon to be used in expanded notification layouts. --> +<com.android.internal.widget.CachingIconView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/right_icon" + android:layout_width="@dimen/notification_right_icon_size" + android:layout_height="@dimen/notification_right_icon_size" + android:layout_gravity="top|end" + android:layout_marginEnd="@dimen/notification_2025_right_icon_expanded_margin_end" + android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin" + android:background="@drawable/notification_large_icon_outline" + android:clipToOutline="true" + android:importantForAccessibility="no" + android:scaleType="centerCrop" + android:maxDrawableWidth="@dimen/notification_right_icon_size" + android:maxDrawableHeight="@dimen/notification_right_icon_size" + /> diff --git a/core/res/res/layout/notification_2025_template_collapsed_base.xml b/core/res/res/layout/notification_2025_template_collapsed_base.xml index d29b7af9e24e..cfc2a997ab54 100644 --- a/core/res/res/layout/notification_2025_template_collapsed_base.xml +++ b/core/res/res/layout/notification_2025_template_collapsed_base.xml @@ -146,9 +146,8 @@ android:layout_width="@dimen/notification_right_icon_size" android:layout_height="@dimen/notification_right_icon_size" android:layout_gravity="center_vertical|end" - android:layout_marginTop="@dimen/notification_right_icon_headerless_margin" - android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin" - android:layout_marginStart="@dimen/notification_right_icon_content_margin" + android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin" + android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin" android:background="@drawable/notification_large_icon_outline" android:clipToOutline="true" android:importantForAccessibility="no" diff --git a/core/res/res/layout/notification_2025_template_collapsed_call.xml b/core/res/res/layout/notification_2025_template_collapsed_call.xml index ee691e4d6894..9fb63f6eff13 100644 --- a/core/res/res/layout/notification_2025_template_collapsed_call.xml +++ b/core/res/res/layout/notification_2025_template_collapsed_call.xml @@ -147,9 +147,8 @@ android:layout_width="@dimen/notification_right_icon_size" android:layout_height="@dimen/notification_right_icon_size" android:layout_gravity="center_vertical|end" - android:layout_marginTop="@dimen/notification_right_icon_headerless_margin" - android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin" - android:layout_marginStart="@dimen/notification_right_icon_content_margin" + android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin" + android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin" android:background="@drawable/notification_large_icon_outline" android:clipToOutline="true" android:importantForAccessibility="no" diff --git a/core/res/res/layout/notification_2025_template_collapsed_conversation.xml b/core/res/res/layout/notification_2025_template_collapsed_conversation.xml index f80411103501..a6fdcd95399e 100644 --- a/core/res/res/layout/notification_2025_template_collapsed_conversation.xml +++ b/core/res/res/layout/notification_2025_template_collapsed_conversation.xml @@ -149,9 +149,9 @@ android:layout_width="@dimen/notification_right_icon_size" android:layout_height="@dimen/notification_right_icon_size" android:layout_gravity="center_vertical|end" - android:layout_marginTop="@dimen/notification_right_icon_headerless_margin" - android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin" - android:layout_marginStart="@dimen/notification_right_icon_content_margin" + android:layout_marginTop="@dimen/notification_2025_margin" + android:layout_marginBottom="@dimen/notification_2025_margin" + android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin" android:forceHasOverlappingRendering="false" android:spacing="0dp" android:clipChildren="false" @@ -163,9 +163,8 @@ android:layout_width="@dimen/notification_right_icon_size" android:layout_height="@dimen/notification_right_icon_size" android:layout_gravity="center_vertical|end" - android:layout_marginTop="@dimen/notification_right_icon_headerless_margin" - android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin" - android:layout_marginStart="@dimen/notification_right_icon_content_margin" + android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin" + android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin" android:background="@drawable/notification_large_icon_outline" android:clipToOutline="true" android:importantForAccessibility="no" diff --git a/core/res/res/layout/notification_2025_template_collapsed_media.xml b/core/res/res/layout/notification_2025_template_collapsed_media.xml index 5beab508aecf..c4ca5b5217ba 100644 --- a/core/res/res/layout/notification_2025_template_collapsed_media.xml +++ b/core/res/res/layout/notification_2025_template_collapsed_media.xml @@ -147,9 +147,8 @@ android:layout_width="@dimen/notification_right_icon_size" android:layout_height="@dimen/notification_right_icon_size" android:layout_gravity="center_vertical|end" - android:layout_marginTop="@dimen/notification_right_icon_headerless_margin" - android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin" - android:layout_marginStart="@dimen/notification_right_icon_content_margin" + android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin" + android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin" android:background="@drawable/notification_large_icon_outline" android:clipToOutline="true" android:importantForAccessibility="no" diff --git a/core/res/res/layout/notification_2025_template_collapsed_messaging.xml b/core/res/res/layout/notification_2025_template_collapsed_messaging.xml index d7c3263904d4..3716fa6825b3 100644 --- a/core/res/res/layout/notification_2025_template_collapsed_messaging.xml +++ b/core/res/res/layout/notification_2025_template_collapsed_messaging.xml @@ -159,9 +159,9 @@ android:layout_width="@dimen/notification_right_icon_size" android:layout_height="@dimen/notification_right_icon_size" android:layout_gravity="center_vertical|end" - android:layout_marginTop="@dimen/notification_right_icon_headerless_margin" - android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin" - android:layout_marginStart="@dimen/notification_right_icon_content_margin" + android:layout_marginTop="@dimen/notification_2025_margin" + android:layout_marginBottom="@dimen/notification_2025_margin" + android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin" android:forceHasOverlappingRendering="false" android:spacing="0dp" android:clipChildren="false" @@ -173,9 +173,8 @@ android:layout_width="@dimen/notification_right_icon_size" android:layout_height="@dimen/notification_right_icon_size" android:layout_gravity="center_vertical|end" - android:layout_marginTop="@dimen/notification_right_icon_headerless_margin" - android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin" - android:layout_marginStart="@dimen/notification_right_icon_content_margin" + android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin" + android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin" android:background="@drawable/notification_large_icon_outline" android:clipToOutline="true" android:importantForAccessibility="no" diff --git a/core/res/res/layout/notification_2025_template_expanded_base.xml b/core/res/res/layout/notification_2025_template_expanded_base.xml index e12db2783191..8d99e47c5386 100644 --- a/core/res/res/layout/notification_2025_template_expanded_base.xml +++ b/core/res/res/layout/notification_2025_template_expanded_base.xml @@ -63,7 +63,7 @@ /> </LinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </FrameLayout> <ViewStub diff --git a/core/res/res/layout/notification_2025_template_expanded_big_picture.xml b/core/res/res/layout/notification_2025_template_expanded_big_picture.xml index fac9d1c47f41..e8e460d1b4ae 100644 --- a/core/res/res/layout/notification_2025_template_expanded_big_picture.xml +++ b/core/res/res/layout/notification_2025_template_expanded_big_picture.xml @@ -25,7 +25,7 @@ <include layout="@layout/notification_2025_template_header" /> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> <LinearLayout android:id="@+id/notification_action_list_margin_target" diff --git a/core/res/res/layout/notification_2025_template_expanded_big_text.xml b/core/res/res/layout/notification_2025_template_expanded_big_text.xml index 4a807cb674c6..b68db7f0a638 100644 --- a/core/res/res/layout/notification_2025_template_expanded_big_text.xml +++ b/core/res/res/layout/notification_2025_template_expanded_big_text.xml @@ -91,5 +91,5 @@ <include layout="@layout/notification_material_action_list" /> </com.android.internal.widget.RemeasuringLinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </FrameLayout> diff --git a/core/res/res/layout/notification_2025_template_expanded_call.xml b/core/res/res/layout/notification_2025_template_expanded_call.xml index bbc29664d594..7b45b55ba15b 100644 --- a/core/res/res/layout/notification_2025_template_expanded_call.xml +++ b/core/res/res/layout/notification_2025_template_expanded_call.xml @@ -68,6 +68,6 @@ </com.android.internal.widget.RemeasuringLinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </com.android.internal.widget.CallLayout> diff --git a/core/res/res/layout/notification_2025_template_expanded_conversation.xml b/core/res/res/layout/notification_2025_template_expanded_conversation.xml index d7e8bb3b6da2..592785d53018 100644 --- a/core/res/res/layout/notification_2025_template_expanded_conversation.xml +++ b/core/res/res/layout/notification_2025_template_expanded_conversation.xml @@ -70,6 +70,6 @@ </com.android.internal.widget.RemeasuringLinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </com.android.internal.widget.ConversationLayout> diff --git a/core/res/res/layout/notification_2025_template_expanded_inbox.xml b/core/res/res/layout/notification_2025_template_expanded_inbox.xml index ccab02e312cc..6459e1eab862 100644 --- a/core/res/res/layout/notification_2025_template_expanded_inbox.xml +++ b/core/res/res/layout/notification_2025_template_expanded_inbox.xml @@ -130,5 +130,5 @@ android:layout_marginTop="@dimen/notification_content_margin" /> <include layout="@layout/notification_material_action_list" /> </LinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </FrameLayout> diff --git a/core/res/res/layout/notification_2025_template_expanded_media.xml b/core/res/res/layout/notification_2025_template_expanded_media.xml index e90ab792581f..801e339b3a92 100644 --- a/core/res/res/layout/notification_2025_template_expanded_media.xml +++ b/core/res/res/layout/notification_2025_template_expanded_media.xml @@ -99,6 +99,6 @@ </LinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </com.android.internal.widget.MediaNotificationView> diff --git a/core/res/res/layout/notification_2025_template_expanded_messaging.xml b/core/res/res/layout/notification_2025_template_expanded_messaging.xml index 20abfee6a4b6..82c71527a291 100644 --- a/core/res/res/layout/notification_2025_template_expanded_messaging.xml +++ b/core/res/res/layout/notification_2025_template_expanded_messaging.xml @@ -70,6 +70,6 @@ </com.android.internal.widget.RemeasuringLinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </com.android.internal.widget.MessagingLayout> diff --git a/core/res/res/layout/notification_2025_template_expanded_progress.xml b/core/res/res/layout/notification_2025_template_expanded_progress.xml index 87ded8975cb0..2ff252747fd2 100644 --- a/core/res/res/layout/notification_2025_template_expanded_progress.xml +++ b/core/res/res/layout/notification_2025_template_expanded_progress.xml @@ -99,7 +99,7 @@ </LinearLayout> </LinearLayout> - <include layout="@layout/notification_template_right_icon" /> + <include layout="@layout/notification_2025_right_icon" /> </FrameLayout> <ViewStub diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml index a1961aedf6b7..7a4f568fe4a4 100644 --- a/core/res/res/values/dimens.xml +++ b/core/res/res/values/dimens.xml @@ -390,6 +390,16 @@ <!-- The absolute size of the notification expand icon. --> <dimen name="notification_header_expand_icon_size">56dp</dimen> + <!-- Margin to allow space for the expand button when showing the right icon in expanded --> + <!-- notifications. This is equal to notification_2025_expand_button_pill_width --> + <!-- + notification_2025_margin (end padding for expand button) --> + <!-- + notification_2025_expand_button_right_icon_spacing (space between pill and icon) --> + <dimen name="notification_2025_right_icon_expanded_margin_end">52dp</dimen> + + <!-- The large icon has a smaller vertical margin than most other notification content, to --> + <!-- allow it to grow up to 48dp. --> + <dimen name="notification_2025_right_icon_vertical_margin">12dp</dimen> + <!-- the height of the expand button pill --> <dimen name="notification_expand_button_pill_height">24dp</dimen> @@ -411,9 +421,12 @@ <!-- the padding of the expand icon in the notification header --> <dimen name="notification_2025_expand_button_horizontal_icon_padding">6dp</dimen> - <!-- a smaller padding for the end of the expand button, for use when showing the number --> + <!-- smaller padding for the end of the expand icon, for use when showing the number --> <dimen name="notification_2025_expand_button_reduced_end_padding">4dp</dimen> + <!-- the space needed between the expander pill and the large icon when visible --> + <dimen name="notification_2025_expand_button_right_icon_spacing">8dp</dimen> + <!-- the size of the notification close button --> <dimen name="notification_close_button_size">16dp</dimen> @@ -893,6 +906,8 @@ <dimen name="notification_right_icon_size">48dp</dimen> <!-- The margin between the right icon and the content. --> <dimen name="notification_right_icon_content_margin">12dp</dimen> + <!-- The margin between the right icon and the content. (2025 redesign version) --> + <dimen name="notification_2025_right_icon_content_margin">16dp</dimen> <!-- The top and bottom margin of the right icon in the normal notification states --> <dimen name="notification_right_icon_headerless_margin">20dp</dimen> <!-- The top margin of the right icon in the "big" notification states --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index c87ab283e188..833761bad734 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3267,6 +3267,8 @@ <java-symbol type="dimen" name="notification_2025_content_margin_start" /> <java-symbol type="dimen" name="notification_2025_expand_button_horizontal_icon_padding" /> <java-symbol type="dimen" name="notification_2025_expand_button_reduced_end_padding" /> + <java-symbol type="dimen" name="notification_2025_expand_button_right_icon_spacing" /> + <java-symbol type="dimen" name="notification_2025_right_icon_expanded_margin_end" /> <java-symbol type="dimen" name="notification_progress_margin_horizontal" /> <java-symbol type="dimen" name="notification_header_background_height" /> <java-symbol type="dimen" name="notification_header_touchable_height" /> @@ -3957,6 +3959,7 @@ <java-symbol type="dimen" name="notification_big_picture_max_width"/> <java-symbol type="dimen" name="notification_right_icon_size"/> <java-symbol type="dimen" name="notification_right_icon_content_margin"/> + <java-symbol type="dimen" name="notification_2025_right_icon_content_margin"/> <java-symbol type="dimen" name="notification_actions_icon_drawable_size"/> <java-symbol type="dimen" name="notification_custom_view_max_image_height"/> <java-symbol type="dimen" name="notification_custom_view_max_image_width"/> |