diff options
| author | 2020-11-12 09:29:16 -0500 | |
|---|---|---|
| committer | 2020-11-13 13:16:02 -0500 | |
| commit | dc81adf34e104cdf5e7d44c17d7ae24ff58f4eda (patch) | |
| tree | 4606f1d53ff945783bcd3fefc6cc4087d750d855 | |
| parent | 87257cbb6e51a3a36c6f565d8614177c0fe77195 (diff) | |
Reduce notification minimized height
Bug: 163626038
Test: manual
Change-Id: Ic5e94389f2f41eebcecc8df393ff2f26c1d7e426
6 files changed, 144 insertions, 28 deletions
diff --git a/core/java/com/android/internal/widget/NotificationMaxHeightFrameLayout.java b/core/java/com/android/internal/widget/NotificationMaxHeightFrameLayout.java new file mode 100644 index 000000000000..6d5fb66b27ef --- /dev/null +++ b/core/java/com/android/internal/widget/NotificationMaxHeightFrameLayout.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2020 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. + */ + +package com.android.internal.widget; + +import android.annotation.Nullable; +import android.content.Context; +import android.util.AttributeSet; +import android.widget.FrameLayout; +import android.widget.RemoteViews; + +/** + * This custom subclass of FrameLayout enforces that its calculated height be no larger than the + * standard height of a notification. This is not required in the normal case, as the + * NotificationContentView gets this same value from the ExpandableNotificationRow, and enforces it + * as a maximum. It is required in the case of the HUN version of the headerless notification, + * because that style puts the actions below the headerless portion. If we don't cap this, then in + * certain situations (larger fonts, decorated custom views) the contents of the headerless + * notification push on the margins and increase the size of that view, which causes the actions to + * be cropped on the bottom by the HUN notification max height. + */ +@RemoteViews.RemoteView +public class NotificationMaxHeightFrameLayout extends FrameLayout { + private final int mNotificationMaxHeight; + + public NotificationMaxHeightFrameLayout(Context context) { + this(context, null, 0, 0); + } + + public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0, 0); + } + + public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs, + int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + public NotificationMaxHeightFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + // `notification_min_height` refers to "minimized" not "minimum"; it is a max height + mNotificationMaxHeight = getFontScaledHeight(mContext, + com.android.internal.R.dimen.notification_min_height); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (MeasureSpec.getSize(heightMeasureSpec) > mNotificationMaxHeight) { + final int mode = MeasureSpec.getMode(heightMeasureSpec); + heightMeasureSpec = MeasureSpec.makeMeasureSpec(mNotificationMaxHeight, mode); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + + /** + * NOTE: This is copied from com.android.systemui.statusbar.notification.NotificationUtils + * + * @param dimenId the dimen to look up + * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp + */ + private static int getFontScaledHeight(Context context, int dimenId) { + final int dimensionPixelSize = context.getResources().getDimensionPixelSize(dimenId); + final float factor = Math.max(1.0f, context.getResources().getDisplayMetrics().scaledDensity + / context.getResources().getDisplayMetrics().density); + return (int) (dimensionPixelSize * factor); + } +} diff --git a/core/res/res/layout/notification_template_material_base.xml b/core/res/res/layout/notification_template_material_base.xml index 25ec8a3837a3..46b3a8f4644f 100644 --- a/core/res/res/layout/notification_template_material_base.xml +++ b/core/res/res/layout/notification_template_material_base.xml @@ -14,7 +14,7 @@ ~ limitations under the License --> -<FrameLayout +<com.android.internal.widget.NotificationMaxHeightFrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/status_bar_latest_event_content" android:layout_width="match_parent" @@ -125,4 +125,4 @@ </FrameLayout> -</FrameLayout> +</com.android.internal.widget.NotificationMaxHeightFrameLayout> diff --git a/core/res/res/layout/notification_template_material_heads_up_base.xml b/core/res/res/layout/notification_template_material_heads_up_base.xml index 3153db8d13c3..d55499130dcc 100644 --- a/core/res/res/layout/notification_template_material_heads_up_base.xml +++ b/core/res/res/layout/notification_template_material_heads_up_base.xml @@ -23,32 +23,43 @@ android:tag="headsUp" > - <LinearLayout - android:id="@+id/notification_action_list_margin_target" + <com.android.internal.widget.RemeasuringLinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/notification_action_list_height" + android:clipChildren="false" android:orientation="vertical" > - <include layout="@layout/notification_template_material_base" /> - - <ViewStub - android:layout="@layout/notification_material_reply_text" - android:id="@+id/notification_material_reply_container" - android:layout_width="match_parent" - android:layout_height="wrap_content" + <include + layout="@layout/notification_template_material_base" + android:id="@null" /> - <include - layout="@layout/notification_template_smart_reply_container" + <com.android.internal.widget.RemeasuringLinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="@dimen/notification_content_margin_start" - android:layout_marginEnd="@dimen/notification_content_margin_end" - android:layout_marginTop="@dimen/notification_content_margin" - /> + android:layout_marginTop="-12dp" + android:clipChildren="false" + android:orientation="vertical" + > + + <ViewStub + android:layout="@layout/notification_material_reply_text" + android:id="@+id/notification_material_reply_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + /> + + <include + layout="@layout/notification_template_smart_reply_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/notification_content_margin_start" + android:layout_marginEnd="@dimen/notification_content_margin_end" + android:layout_marginTop="@dimen/notification_content_margin" + /> - <include layout="@layout/notification_material_action_list" /> - </LinearLayout> + <include layout="@layout/notification_material_action_list" /> + </com.android.internal.widget.RemeasuringLinearLayout> + </com.android.internal.widget.RemeasuringLinearLayout> </FrameLayout> diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml index 1c51cb961e05..4eeeb18cbcd5 100644 --- a/core/res/res/values/dimens.xml +++ b/core/res/res/values/dimens.xml @@ -308,7 +308,7 @@ <dimen name="notification_headerless_min_height">56dp</dimen> <!-- Height of a small notification in the status bar --> - <dimen name="notification_min_height">106dp</dimen> + <dimen name="notification_min_height">76dp</dimen> <!-- The width of the big icons in notifications. --> <dimen name="notification_large_icon_width">64dp</dimen> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index d946f7cb11c1..0e4f4ddf01c9 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -133,17 +133,23 @@ <!-- Height of a small notification in the status bar which was used before android P --> <dimen name="notification_min_height_before_p">92dp</dimen> + <!-- Height of a small notification in the status bar which was used before android S --> + <dimen name="notification_min_height_before_s">106dp</dimen> + <!-- Height of a large notification in the status bar --> <dimen name="notification_max_height">294dp</dimen> <!-- Height of a heads up notification in the status bar for legacy custom views --> <dimen name="notification_max_heads_up_height_legacy">128dp</dimen> - <!-- Height of a heads up notification in the status bar for custom views before andoid P --> + <!-- Height of a heads up notification in the status bar for custom views before android P --> <dimen name="notification_max_heads_up_height_before_p">148dp</dimen> + <!-- Height of a heads up notification in the status bar for custom views before android S --> + <dimen name="notification_max_heads_up_height_before_s">162dp</dimen> + <!-- Height of a heads up notification in the status bar --> - <dimen name="notification_max_heads_up_height">162dp</dimen> + <dimen name="notification_max_heads_up_height">132dp</dimen> <!-- Height of a heads up notification in the status bar --> <dimen name="notification_max_heads_up_height_increased">188dp</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java index 2253b2ba26f2..b7613b41f1ec 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java @@ -35,7 +35,6 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; -import android.graphics.Color; import android.graphics.Path; import android.graphics.drawable.AnimatedVectorDrawable; import android.graphics.drawable.AnimationDrawable; @@ -154,10 +153,12 @@ public class ExpandableNotificationRow extends ActivatableNotificationView private int mIconTransformContentShift; private int mMaxHeadsUpHeightBeforeN; private int mMaxHeadsUpHeightBeforeP; + private int mMaxHeadsUpHeightBeforeS; private int mMaxHeadsUpHeight; private int mMaxHeadsUpHeightIncreased; private int mNotificationMinHeightBeforeN; private int mNotificationMinHeightBeforeP; + private int mNotificationMinHeightBeforeS; private int mNotificationMinHeight; private int mNotificationMinHeightLarge; private int mNotificationMinHeightMedia; @@ -647,6 +648,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView != com.android.internal.R.id.status_bar_latest_event_content; boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N; boolean beforeP = mEntry.targetSdk < Build.VERSION_CODES.P; + boolean beforeS = mEntry.targetSdk < Build.VERSION_CODES.S; int minHeight; View expandedView = layout.getExpandedChild(); @@ -654,8 +656,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView && expandedView.findViewById(com.android.internal.R.id.media_actions) != null; boolean showCompactMediaSeekbar = mMediaManager.getShowCompactMediaSeekbar(); - if (customView && beforeP && !mIsSummaryWithChildren) { - minHeight = beforeN ? mNotificationMinHeightBeforeN : mNotificationMinHeightBeforeP; + if (customView && beforeS && !mIsSummaryWithChildren) { + if (beforeN) { + minHeight = mNotificationMinHeightBeforeN; + } else if (beforeP) { + minHeight = mNotificationMinHeightBeforeP; + } else { + minHeight = mNotificationMinHeightBeforeS; + } } else if (isMediaLayout && showCompactMediaSeekbar) { minHeight = mNotificationMinHeightMedia; } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) { @@ -667,8 +675,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView layout.getHeadsUpChild().getId() != com.android.internal.R.id.status_bar_latest_event_content; int headsUpHeight; - if (headsUpCustom && beforeP) { - headsUpHeight = beforeN ? mMaxHeadsUpHeightBeforeN : mMaxHeadsUpHeightBeforeP; + if (headsUpCustom && beforeS) { + if (beforeN) { + headsUpHeight = mMaxHeadsUpHeightBeforeN; + } else if (beforeP) { + headsUpHeight = mMaxHeadsUpHeightBeforeP; + } else { + headsUpHeight = mMaxHeadsUpHeightBeforeS; + } } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) { headsUpHeight = mMaxHeadsUpHeightIncreased; } else { @@ -1604,6 +1618,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView R.dimen.notification_min_height_legacy); mNotificationMinHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext, R.dimen.notification_min_height_before_p); + mNotificationMinHeightBeforeS = NotificationUtils.getFontScaledHeight(mContext, + R.dimen.notification_min_height_before_s); mNotificationMinHeight = NotificationUtils.getFontScaledHeight(mContext, R.dimen.notification_min_height); mNotificationMinHeightLarge = NotificationUtils.getFontScaledHeight(mContext, @@ -1616,6 +1632,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView R.dimen.notification_max_heads_up_height_legacy); mMaxHeadsUpHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext, R.dimen.notification_max_heads_up_height_before_p); + mMaxHeadsUpHeightBeforeS = NotificationUtils.getFontScaledHeight(mContext, + R.dimen.notification_max_heads_up_height_before_s); mMaxHeadsUpHeight = NotificationUtils.getFontScaledHeight(mContext, R.dimen.notification_max_heads_up_height); mMaxHeadsUpHeightIncreased = NotificationUtils.getFontScaledHeight(mContext, |