From da7c24580e80d501d8243f8aff2b1e075546b087 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 16 Apr 2020 16:44:58 -0400 Subject: [PATCH] Add history onboarding Test: atest Fixes: 153150072 Change-Id: I0d90eaff168cc38ca0a1123bb65ed941c9e283f8 --- .../notification/row/FooterView.java | 22 +++++++++++++-- .../stack/NotificationStackScrollLayout.java | 28 ++++++++++++------- .../notification/row/FooterViewTest.java | 17 +++++++++++ .../NotificationStackScrollLayoutTest.java | 22 +++++++++++---- 4 files changed, 70 insertions(+), 19 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 41b248fb96340..3ec8c23747189 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 @@ -29,6 +29,7 @@ public class FooterView extends StackScrollerDecorView { private final int mClearAllTopPadding; private FooterViewButton mDismissButton; private FooterViewButton mManageButton; + private boolean mShowHistory; public FooterView(Context context, AttributeSet attrs) { super(context, attrs); @@ -72,15 +73,30 @@ public class FooterView extends StackScrollerDecorView { || touchY > mContent.getY() + mContent.getHeight(); } + public void showHistory(boolean showHistory) { + mShowHistory = showHistory; + if (mShowHistory) { + mManageButton.setText(R.string.manage_notifications_history_text); + mManageButton.setContentDescription( + mContext.getString(R.string.manage_notifications_history_text)); + } else { + mManageButton.setText(R.string.manage_notifications_text); + mManageButton.setContentDescription( + mContext.getString(R.string.manage_notifications_text)); + } + } + + public boolean isHistoryShown() { + return mShowHistory; + } + @Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDismissButton.setText(R.string.clear_all_notifications_text); mDismissButton.setContentDescription( mContext.getString(R.string.accessibility_clear_all)); - mManageButton.setText(R.string.manage_notifications_history_text); - mManageButton.setContentDescription( - mContext.getString(R.string.manage_notifications_history_text)); + showHistory(mShowHistory); } public boolean isButtonVisible() { 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 6054b507185e6..ed26c2ff479b1 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 @@ -628,8 +628,11 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd mHighPriorityBeforeSpeedBump = "1".equals(newValue); } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { updateDismissRtlSetting("1".equals(newValue)); + } else if (key.equals(Settings.Secure.NOTIFICATION_HISTORY_ENABLED)) { + updateFooter(); } - }, HIGH_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL); + }, HIGH_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL, + Settings.Secure.NOTIFICATION_HISTORY_ENABLED); mFeatureFlags = featureFlags; mNotifPipeline = notifPipeline; @@ -742,12 +745,17 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd @VisibleForTesting @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) public void updateFooter() { + if (mFooterView == null) { + return; + } boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL); boolean showFooterView = (showDismissView || hasActiveNotifications()) && mStatusBarState != StatusBarState.KEYGUARD && !mRemoteInputManager.getController().isRemoteInputActive(); + boolean showHistory = Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0) == 1; - updateFooterView(showFooterView, showDismissView); + updateFooterView(showFooterView, showDismissView, showHistory); } /** @@ -4979,13 +4987,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd } @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) - public void updateFooterView(boolean visible, boolean showDismissView) { + public void updateFooterView(boolean visible, boolean showDismissView, boolean showHistory) { if (mFooterView == null) { return; } boolean animate = mIsExpanded && mAnimationsEnabled; mFooterView.setVisible(visible, animate); mFooterView.setSecondaryVisible(showDismissView, animate); + mFooterView.showHistory(showHistory); } @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) @@ -5565,12 +5574,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd mIconAreaController = controller; } - @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) - public void manageNotifications(View v) { - Intent intent = new Intent(Settings.ACTION_NOTIFICATION_HISTORY); - mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); - } - @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) @VisibleForTesting void clearNotifications( @@ -5705,7 +5708,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd mMetricsLogger.action(MetricsEvent.ACTION_DISMISS_ALL_NOTES); clearNotifications(ROWS_ALL, true /* closeShade */); }); - footerView.setManageButtonClickListener(this::manageNotifications); + footerView.setManageButtonClickListener(v -> { + Intent intent = footerView.isHistoryShown() ? new Intent( + Settings.ACTION_NOTIFICATION_HISTORY) : new Intent( + Settings.ACTION_NOTIFICATION_SETTINGS); + mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP); + }); setFooterView(footerView); } 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 2336958482986..9039e1b8f8e3c 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,6 +24,7 @@ import static org.mockito.Mockito.mock; import android.view.LayoutInflater; import android.view.View; +import android.widget.TextView; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -66,6 +67,22 @@ public class FooterViewTest extends SysuiTestCase { assertTrue(mView.findViewById(R.id.manage_text).hasOnClickListeners()); } + @Test + public void setHistoryShown() { + mView.showHistory(true); + assertTrue(mView.isHistoryShown()); + assertTrue(((TextView) mView.findViewById(R.id.manage_text)) + .getText().toString().contains("History")); + } + + @Test + public void setHistoryNotShown() { + mView.showHistory(false); + assertFalse(mView.isHistoryShown()); + assertTrue(((TextView) mView.findViewById(R.id.manage_text)) + .getText().toString().contains("Manage")); + } + @Test public void testPerformVisibilityAnimation() { mView.setVisible(false /* visible */, false /* animate */); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java index 657bc8d614cf5..1cb4d898f9d2d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java @@ -13,6 +13,7 @@ package com.android.systemui.statusbar.notification.stack; +import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED; import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL; import static junit.framework.Assert.assertEquals; @@ -151,6 +152,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { NOTIFICATION_NEW_INTERRUPTION_MODEL, 0); Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_HISTORY_ENABLED, 1); // Inject dependencies before initializing the layout mDependency.injectMockDependency(VisualStabilityManager.class); @@ -311,7 +313,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { mStackScroller.setFooterView(view); when(view.willBeGone()).thenReturn(true); - mStackScroller.updateFooterView(true, false); + mStackScroller.updateFooterView(true, false, true); verify(view).setVisible(eq(true), anyBoolean()); verify(view).setSecondaryVisible(eq(false), anyBoolean()); @@ -323,7 +325,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { mStackScroller.setFooterView(view); when(view.willBeGone()).thenReturn(true); - mStackScroller.updateFooterView(true, true); + mStackScroller.updateFooterView(true, true, true); verify(view).setVisible(eq(true), anyBoolean()); verify(view).setSecondaryVisible(eq(true), anyBoolean()); @@ -344,8 +346,10 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { setBarStateForTest(StatusBarState.SHADE); assertEquals(0, mEntryManager.getActiveNotificationsCount()); + FooterView view = mock(FooterView.class); + mStackScroller.setFooterView(view); mStackScroller.updateFooter(); - verify(mStackScroller, atLeastOnce()).updateFooterView(false, false); + verify(mStackScroller, atLeastOnce()).updateFooterView(false, false, true); } @Test @@ -361,8 +365,10 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { when(mStackScroller.getChildAt(anyInt())).thenReturn(row); when(mRemoteInputController.isRemoteInputActive()).thenReturn(true); + FooterView view = mock(FooterView.class); + mStackScroller.setFooterView(view); mStackScroller.updateFooter(); - verify(mStackScroller).updateFooterView(false, true); + verify(mStackScroller).updateFooterView(false, true, true); } @Test @@ -378,8 +384,10 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { when(mStackScroller.getChildCount()).thenReturn(1); when(mStackScroller.getChildAt(anyInt())).thenReturn(row); + FooterView view = mock(FooterView.class); + mStackScroller.setFooterView(view); mStackScroller.updateFooter(); - verify(mStackScroller).updateFooterView(true, true); + verify(mStackScroller).updateFooterView(true, true, true); } @Test @@ -390,8 +398,10 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { entries.add(new NotificationEntryBuilder().build()); addEntriesToEntryManager(entries); + FooterView view = mock(FooterView.class); + mStackScroller.setFooterView(view); mStackScroller.updateFooter(); - verify(mStackScroller).updateFooterView(true, false); + verify(mStackScroller).updateFooterView(true, false, true); } @Test