From 8e42f093c7c2c6128c9a7bf29098d48a7dfd8f3f Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Wed, 19 Apr 2023 12:41:32 -0400 Subject: [PATCH] Cache resources for unseen footer treatment These resources are frequently re-queried even if there is no change. Caching them will increase performance and reduce potential jank. Fixes: 266116638 Test: atest FooterViewTest Change-Id: If8f00a56c68dc57c99cd9b755b55a7e3c274a6da --- .../notification/row/FooterView.java | 44 +++++++------------ .../stack/NotificationStackScrollLayout.java | 8 +--- .../notification/row/FooterViewTest.java | 19 +++++--- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java index 49f17b664a201..6bbeebfdb431a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java @@ -17,8 +17,6 @@ package com.android.systemui.statusbar.notification.row; import android.annotation.ColorInt; -import android.annotation.DrawableRes; -import android.annotation.StringRes; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Configuration; @@ -50,8 +48,8 @@ public class FooterView extends StackScrollerDecorView { // Footer label private TextView mSeenNotifsFooterTextView; - private @StringRes int mSeenNotifsFilteredText; - private int mUnlockIconSize; + private String mSeenNotifsFilteredText; + private Drawable mSeenNotifsFilteredIcon; public FooterView(Context context, AttributeSet attrs) { super(context, attrs); @@ -87,30 +85,12 @@ public class FooterView extends StackScrollerDecorView { mManageButton = findViewById(R.id.manage_text); mSeenNotifsFooterTextView = findViewById(R.id.unlock_prompt_footer); updateResources(); - updateText(); + updateContent(); updateColors(); } - public void setFooterLabelTextAndIcon(@StringRes int text, @DrawableRes int icon) { - mSeenNotifsFilteredText = text; - if (mSeenNotifsFilteredText != 0) { - mSeenNotifsFooterTextView.setText(mSeenNotifsFilteredText); - } else { - mSeenNotifsFooterTextView.setText(null); - } - Drawable drawable; - if (icon == 0) { - drawable = null; - } else { - drawable = getResources().getDrawable(icon); - drawable.setBounds(0, 0, mUnlockIconSize, mUnlockIconSize); - } - mSeenNotifsFooterTextView.setCompoundDrawablesRelative(drawable, null, null, null); - updateFooterVisibilityMode(); - } - - private void updateFooterVisibilityMode() { - if (mSeenNotifsFilteredText != 0) { + public void setFooterLabelVisible(boolean isVisible) { + if (isVisible) { mManageButton.setVisibility(View.GONE); mClearAllButton.setVisibility(View.GONE); mSeenNotifsFooterTextView.setVisibility(View.VISIBLE); @@ -141,10 +121,10 @@ public class FooterView extends StackScrollerDecorView { return; } mShowHistory = showHistory; - updateText(); + updateContent(); } - private void updateText() { + private void updateContent() { if (mShowHistory) { mManageButton.setText(mManageNotificationHistoryText); mManageButton.setContentDescription(mManageNotificationHistoryText); @@ -152,6 +132,9 @@ public class FooterView extends StackScrollerDecorView { mManageButton.setText(mManageNotificationText); mManageButton.setContentDescription(mManageNotificationText); } + mSeenNotifsFooterTextView.setText(mSeenNotifsFilteredText); + mSeenNotifsFooterTextView + .setCompoundDrawablesRelative(mSeenNotifsFilteredIcon, null, null, null); } public boolean isHistoryShown() { @@ -166,7 +149,7 @@ public class FooterView extends StackScrollerDecorView { mClearAllButton.setContentDescription( mContext.getString(R.string.accessibility_clear_all)); updateResources(); - updateText(); + updateContent(); } /** @@ -190,8 +173,11 @@ public class FooterView extends StackScrollerDecorView { mManageNotificationText = getContext().getString(R.string.manage_notifications_text); mManageNotificationHistoryText = getContext() .getString(R.string.manage_notifications_history_text); - mUnlockIconSize = getResources() + int unlockIconSize = getResources() .getDimensionPixelSize(R.dimen.notifications_unseen_footer_icon_size); + mSeenNotifsFilteredText = getContext().getString(R.string.unlock_to_see_notif_text); + mSeenNotifsFilteredIcon = getContext().getDrawable(R.drawable.ic_friction_lock_closed); + mSeenNotifsFilteredIcon.setBounds(0, 0, unlockIconSize, unlockIconSize); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java index 555d5027c7b64..92557ab122aa8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java @@ -4741,13 +4741,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable mFooterView.setVisible(visible, animate); mFooterView.setSecondaryVisible(showDismissView, animate); mFooterView.showHistory(showHistory); - if (mHasFilteredOutSeenNotifications) { - mFooterView.setFooterLabelTextAndIcon( - R.string.unlock_to_see_notif_text, - R.drawable.ic_friction_lock_closed); - } else { - mFooterView.setFooterLabelTextAndIcon(0, 0); - } + mFooterView.setFooterLabelVisible(mHasFilteredOutSeenNotifications); } @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/FooterViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/FooterViewTest.java index 819a75bffc8ea..90cb7341377d7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/FooterViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/FooterViewTest.java @@ -24,12 +24,12 @@ import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.mock; +import android.testing.AndroidTestingRunner; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; @@ -39,7 +39,7 @@ import org.junit.Test; import org.junit.runner.RunWith; @SmallTest -@RunWith(AndroidJUnit4.class) +@RunWith(AndroidTestingRunner.class) public class FooterViewTest extends SysuiTestCase { FooterView mView; @@ -102,14 +102,21 @@ public class FooterViewTest extends SysuiTestCase { } @Test - public void testSetFooterLabelTextAndIcon() { - mView.setFooterLabelTextAndIcon( - R.string.unlock_to_see_notif_text, - R.drawable.ic_friction_lock_closed); + public void testSetFooterLabelVisible() { + mView.setFooterLabelVisible(true); assertThat(mView.findViewById(R.id.manage_text).getVisibility()).isEqualTo(View.GONE); assertThat(mView.findSecondaryView().getVisibility()).isEqualTo(View.GONE); assertThat(mView.findViewById(R.id.unlock_prompt_footer).getVisibility()) .isEqualTo(View.VISIBLE); } + + @Test + public void testSetFooterLabelInvisible() { + mView.setFooterLabelVisible(false); + assertThat(mView.findViewById(R.id.manage_text).getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mView.findSecondaryView().getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mView.findViewById(R.id.unlock_prompt_footer).getVisibility()) + .isEqualTo(View.GONE); + } }