From 4018c5075acd0f40e0bb2c2349a10430ccfd25ab Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Thu, 11 Mar 2021 14:39:20 -0500 Subject: [PATCH] Hide app name from collapsed CallStyle. Also some small fixes: * Bind the title in the CallStyle builder. * Remove an unnecessary findViewById. * Rename a method overload for clarity. Bug: 179178086 Test: manual inspection Change-Id: I6e96864c17718b9729b108e4db82534aad33675f --- core/java/android/app/Notification.java | 57 ++++++++++++++----- .../android/internal/widget/CallLayout.java | 1 - .../row/NotificationContentView.java | 4 +- .../stack/NotificationChildrenContainer.java | 2 +- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index c66f3f746b659..b31048cafbd72 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -5011,9 +5011,13 @@ public class Notification implements Parcelable boolean showProgress = handleProgressBar(contentView, ex, p); boolean hasSecondLine = showProgress; if (p.hasTitle()) { - contentView.setViewVisibility(R.id.title, View.VISIBLE); - contentView.setTextViewText(R.id.title, processTextSpans(p.title)); - setTextViewColorPrimary(contentView, R.id.title, p); + contentView.setViewVisibility(p.mTitleViewId, View.VISIBLE); + contentView.setTextViewText(p.mTitleViewId, processTextSpans(p.title)); + setTextViewColorPrimary(contentView, p.mTitleViewId, p); + } else if (p.mTitleViewId != R.id.title) { + // This alternate title view ID is not cleared by resetStandardTemplate + contentView.setViewVisibility(p.mTitleViewId, View.GONE); + contentView.setTextViewText(p.mTitleViewId, null); } if (p.text != null && p.text.length() != 0 && (!showProgress || p.mAllowTextWithProgress)) { @@ -5441,6 +5445,11 @@ public class Notification implements Parcelable // keep the divider visible between that title and the next text element. return true; } + if (p.mHideAppName) { + // The app name is being hidden, so we definitely want to return here. + // Assume that there is a title which will replace it in the header. + return p.hasTitle(); + } contentView.setViewVisibility(R.id.app_name_text, View.VISIBLE); contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); contentView.setTextColor(R.id.app_name_text, getSecondaryTextColor(p)); @@ -5817,7 +5826,7 @@ public class Notification implements Parcelable * * @hide */ - public RemoteViews makeNotificationHeader() { + public RemoteViews makeNotificationGroupHeader() { return makeNotificationHeader(mParams.reset() .viewType(StandardTemplateParams.VIEW_TYPE_GROUP_HEADER) .fillTextsFrom(this)); @@ -9440,7 +9449,9 @@ public class Notification implements Parcelable } private RemoteViews makeCallLayout(int viewType) { + final boolean isCollapsed = viewType == StandardTemplateParams.VIEW_TYPE_NORMAL; Bundle extras = mBuilder.mN.extras; + CharSequence title = mPerson != null ? mPerson.getName() : null; CharSequence text = mBuilder.processLegacyText(extras.getCharSequence(EXTRA_TEXT)); if (text == null) { text = getDefaultText(); @@ -9452,22 +9463,26 @@ public class Notification implements Parcelable .callStyleActions(true) .allowTextWithProgress(true) .hideLargeIcon(true) + .hideAppName(isCollapsed) + .titleViewId(R.id.conversation_text) + .title(title) .text(text) .summaryText(mBuilder.processLegacyText(mVerificationText)); mBuilder.mActions = getActionsListWithSystemActions(); final RemoteViews contentView; - if (p.mViewType != StandardTemplateParams.VIEW_TYPE_NORMAL) { - contentView = mBuilder.applyStandardTemplateWithActions( - R.layout.notification_template_material_big_call, p, null /* result */); - } else { + if (isCollapsed) { contentView = mBuilder.applyStandardTemplate( R.layout.notification_template_material_call, p, null /* result */); + } else { + contentView = mBuilder.applyStandardTemplateWithActions( + R.layout.notification_template_material_big_call, p, null /* result */); } // Bind some extra conversation-specific header fields. - mBuilder.setTextViewColorPrimary(contentView, R.id.conversation_text, p); - mBuilder.setTextViewColorSecondary(contentView, R.id.app_name_divider, p); - contentView.setViewVisibility(R.id.app_name_divider, View.VISIBLE); + if (!p.mHideAppName) { + mBuilder.setTextViewColorSecondary(contentView, R.id.app_name_divider, p); + contentView.setViewVisibility(R.id.app_name_divider, View.VISIBLE); + } bindCallerVerification(contentView, p); // Bind some custom CallLayout properties @@ -12144,12 +12159,13 @@ public class Notification implements Parcelable public static int VIEW_TYPE_NORMAL = 1; public static int VIEW_TYPE_BIG = 2; public static int VIEW_TYPE_HEADS_UP = 3; - public static int VIEW_TYPE_MINIMIZED = 4; - public static int VIEW_TYPE_PUBLIC = 5; - public static int VIEW_TYPE_GROUP_HEADER = 6; + public static int VIEW_TYPE_MINIMIZED = 4; // header only for minimized state + public static int VIEW_TYPE_PUBLIC = 5; // header only for automatic public version + public static int VIEW_TYPE_GROUP_HEADER = 6; // header only for top of group int mViewType = VIEW_TYPE_UNSPECIFIED; boolean mHeaderless; + boolean mHideAppName; boolean mHideTitle; boolean mHideActions; boolean mHideProgress; @@ -12157,6 +12173,7 @@ public class Notification implements Parcelable boolean mPromotePicture; boolean mCallStyleActions; boolean mAllowTextWithProgress; + int mTitleViewId; int mTextViewId; CharSequence title; CharSequence text; @@ -12170,6 +12187,7 @@ public class Notification implements Parcelable final StandardTemplateParams reset() { mViewType = VIEW_TYPE_UNSPECIFIED; mHeaderless = false; + mHideAppName = false; mHideTitle = false; mHideActions = false; mHideProgress = false; @@ -12177,6 +12195,7 @@ public class Notification implements Parcelable mPromotePicture = false; mCallStyleActions = false; mAllowTextWithProgress = false; + mTitleViewId = R.id.title; mTextViewId = R.id.text; title = null; text = null; @@ -12202,6 +12221,11 @@ public class Notification implements Parcelable return this; } + public StandardTemplateParams hideAppName(boolean hideAppName) { + mHideAppName = hideAppName; + return this; + } + final StandardTemplateParams hideActions(boolean hideActions) { this.mHideActions = hideActions; return this; @@ -12237,6 +12261,11 @@ public class Notification implements Parcelable return this; } + public StandardTemplateParams titleViewId(int titleViewId) { + mTitleViewId = titleViewId; + return this; + } + public StandardTemplateParams textViewId(int textViewId) { mTextViewId = textViewId; return this; diff --git a/core/java/com/android/internal/widget/CallLayout.java b/core/java/com/android/internal/widget/CallLayout.java index 6cc5a4aacda59..83345dad8ed9a 100644 --- a/core/java/com/android/internal/widget/CallLayout.java +++ b/core/java/com/android/internal/widget/CallLayout.java @@ -100,7 +100,6 @@ public class CallLayout extends FrameLayout { } // TODO(b/179178086): crop/clip the icon to a circle? mConversationIconView.setImageIcon(icon); - mConversationText.setText(callerName); } @RemotableViewMethod diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java index dabea582798fa..8c21e767c5c95 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java @@ -1346,9 +1346,7 @@ public class NotificationContentView extends FrameLayout { } ImageView bubbleButton = layout.findViewById(com.android.internal.R.id.bubble_button); View actionContainer = layout.findViewById(com.android.internal.R.id.actions_container); - LinearLayout actionContainerLayout = - layout.findViewById(com.android.internal.R.id.actions_container_layout); - if (bubbleButton == null || actionContainer == null || actionContainerLayout == null) { + if (bubbleButton == null || actionContainer == null) { return; } boolean isPersonWithShortcut = diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java index 2b194ba158168..dac3b8b739baf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainer.java @@ -324,7 +324,7 @@ public class NotificationChildrenContainer extends ViewGroup { StatusBarNotification notification = mContainingNotification.getEntry().getSbn(); final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(), notification.getNotification()); - RemoteViews header = builder.makeNotificationHeader(); + RemoteViews header = builder.makeNotificationGroupHeader(); if (mNotificationHeader == null) { mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this); mNotificationHeader.findViewById(com.android.internal.R.id.expand_button)