From a70a15864518f7841f578d4e495b62a7a9549148 Mon Sep 17 00:00:00 2001 From: Michal Brzezinski Date: Fri, 12 Feb 2021 16:32:38 +0000 Subject: [PATCH] Simplifying mVerticalTranslationListener Changing mVerticalTranslationListener to single object instead of a list. Test: atest SystemUITests Bug: 171917882 Change-Id: I3206745db47c5e1b90748b5418046f070d9648a6 --- .../phone/HeadsUpAppearanceController.java | 4 ++-- .../phone/NotificationPanelViewController.java | 15 +++++---------- .../phone/HeadsUpAppearanceControllerTest.java | 5 +++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java index 8cdaa63994e46..f4830fbb0028b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java @@ -134,7 +134,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, mStackScrollerController = stackScrollerController; mNotificationPanelViewController = notificationPanelViewController; notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp); - notificationPanelViewController.addVerticalTranslationListener(mUpdatePanelTranslation); + notificationPanelViewController.setVerticalTranslationListener(mUpdatePanelTranslation); notificationPanelViewController.setHeadsUpAppearanceController(this); mStackScrollerController.addOnExpandedHeightChangedListener(mSetExpandedHeight); mStackScrollerController.addOnLayoutChangeListener(mStackScrollLayoutChangeListener); @@ -171,7 +171,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, mHeadsUpStatusBarView.setOnDrawingRectChangedListener(null); mWakeUpCoordinator.removeListener(this); mNotificationPanelViewController.removeTrackingHeadsUpListener(mSetTrackingHeadsUp); - mNotificationPanelViewController.removeVerticalTranslationListener(mUpdatePanelTranslation); + mNotificationPanelViewController.setVerticalTranslationListener(null); mNotificationPanelViewController.setHeadsUpAppearanceController(null); mStackScrollerController.removeOnExpandedHeightChangedListener(mSetExpandedHeight); mStackScrollerController.removeOnLayoutChangeListener(mStackScrollLayoutChangeListener); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index 3b09eda4003e2..d25d927548b8b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -459,7 +459,7 @@ public class NotificationPanelViewController extends PanelViewController { private ArrayList> mTrackingHeadsUpListeners = new ArrayList<>(); - private ArrayList mVerticalTranslationListener = new ArrayList<>(); + private Runnable mVerticalTranslationListener; private HeadsUpAppearanceController mHeadsUpAppearanceController; private int mPanelAlpha; @@ -2848,9 +2848,8 @@ public class NotificationPanelViewController extends PanelViewController { protected void setHorizontalPanelTranslation(float translation) { mNotificationStackScrollLayoutController.setTranslationX(translation); mQsFrame.setTranslationX(translation); - int size = mVerticalTranslationListener.size(); - for (int i = 0; i < size; i++) { - mVerticalTranslationListener.get(i).run(); + if (mVerticalTranslationListener != null) { + mVerticalTranslationListener.run(); } } @@ -3143,12 +3142,8 @@ public class NotificationPanelViewController extends PanelViewController { mTrackingHeadsUpListeners.remove(listener); } - public void addVerticalTranslationListener(Runnable verticalTranslationListener) { - mVerticalTranslationListener.add(verticalTranslationListener); - } - - public void removeVerticalTranslationListener(Runnable verticalTranslationListener) { - mVerticalTranslationListener.remove(verticalTranslationListener); + public void setVerticalTranslationListener(Runnable verticalTranslationListener) { + mVerticalTranslationListener = verticalTranslationListener; } public void setHeadsUpAppearanceController( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java index 8dea84c4d0b6b..6e0cbd9ecfa39 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.phone; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; @@ -197,9 +198,9 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { mHeadsUpAppearanceController.destroy(); verify(mHeadsUpManager).removeListener(any()); verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any()); - verify(mPanelView).removeVerticalTranslationListener(any()); + verify(mPanelView).setVerticalTranslationListener(isNull()); verify(mPanelView).removeTrackingHeadsUpListener(any()); - verify(mPanelView).setHeadsUpAppearanceController(any()); + verify(mPanelView).setHeadsUpAppearanceController(isNull()); verify(mStackScrollerController).removeOnExpandedHeightChangedListener(any()); verify(mStackScrollerController).removeOnLayoutChangeListener(any()); }