From 9c1f4e12c90f36ffb8d0840c2ea17cc2270324ef Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Tue, 11 May 2021 17:05:36 -0400 Subject: [PATCH] Show minimized header text with the correct text weight Fixes: 184863420 Test: visual Change-Id: Ic16f9e88e118e7ea5fe14054cf1c35318d4a6ddd --- core/java/android/app/Notification.java | 4 +++- .../android/view/NotificationHeaderView.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 2dcdd07c99462..d3d2e21c017f4 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -6053,11 +6053,13 @@ public class Notification implements Parcelable .viewType(StandardTemplateParams.VIEW_TYPE_MINIMIZED) .highlightExpander(false) .fillTextsFrom(this); - if (!useRegularSubtext || TextUtils.isEmpty(mParams.summaryText)) { + if (!useRegularSubtext || TextUtils.isEmpty(p.summaryText)) { p.summaryText(createSummaryText()); } RemoteViews header = makeNotificationHeader(p); header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); + // The low priority header has no app name and shows the text + header.setBoolean(R.id.notification_header, "styleTextAsTitle", true); return header; } diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index 6c8753b95cc1c..000c68503ea46 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -29,6 +29,7 @@ import android.os.Build; import android.util.AttributeSet; import android.widget.RelativeLayout; import android.widget.RemoteViews; +import android.widget.TextView; import com.android.internal.R; import com.android.internal.widget.CachingIconView; @@ -174,6 +175,28 @@ public class NotificationHeaderView extends RelativeLayout { (int) (extraMarginEndDp * getResources().getDisplayMetrics().density)); } + /** + * This is used to make the low-priority header show the bolded text of a title. + * + * @param styleTextAsTitle true if this header's text is to have the style of a title + */ + @RemotableViewMethod + public void styleTextAsTitle(boolean styleTextAsTitle) { + int styleResId = styleTextAsTitle + ? R.style.TextAppearance_DeviceDefault_Notification_Title + : R.style.TextAppearance_DeviceDefault_Notification_Info; + // Most of the time, we're showing text in the minimized state + View headerText = findViewById(R.id.header_text); + if (headerText instanceof TextView) { + ((TextView) headerText).setTextAppearance(styleResId); + } + // If there's no summary or text, we show the app name instead of nothing + View appNameText = findViewById(R.id.app_name_text); + if (appNameText instanceof TextView) { + ((TextView) appNameText).setTextAppearance(styleResId); + } + } + /** * Get the current margin end value for the header text. * Add this to {@link #getTopLineBaseMarginEnd()} to get the total margin of the top line.