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 6a127102b726d..ab08865c8bef8 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 @@ -6092,6 +6092,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable return mExpandHelperCallback; } + float getAppearFraction() { + return mLastSentAppear; + } + + float getExpandedHeight() { + return mLastSentExpandedHeight; + } + /** Enum for selecting some or all notification rows (does not included non-notif views). */ @Retention(SOURCE) @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE}) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java index 03fc76760133a..f14cc93c2046e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java @@ -858,6 +858,14 @@ public class NotificationStackScrollLayoutController { mView.setHeadsUpAppearanceController(controller); } + public float getAppearFraction() { + return mView.getAppearFraction(); + } + + public float getExpandedHeight() { + return mView.getExpandedHeight(); + } + public void requestLayout() { mView.requestLayout(); } 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 0664900e25389..db4b8e8e47b2b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java @@ -72,8 +72,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, @VisibleForTesting float mExpandedHeight; @VisibleForTesting - boolean mIsExpanded; - @VisibleForTesting float mAppearFraction; private ExpandableNotificationRow mTrackedChild; private boolean mShown; @@ -134,6 +132,15 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, mCenteredIconView = centeredIconView; headsUpStatusBarView.setOnDrawingRectChangedListener( () -> updateIsolatedIconLocation(true /* requireUpdate */)); + + // We may be mid-HUN-expansion when this controller is re-created (for example, if the user + // has started pulling down the notification shade from the HUN and then the font size + // changes). We need to re-fetch these values since they're used to correctly display the + // HUN during this shade expansion. + mTrackedChild = notificationPanelViewController.getTrackedHeadsUpNotification(); + mAppearFraction = stackScrollerController.getAppearFraction(); + mExpandedHeight = stackScrollerController.getExpandedHeight(); + mStackScrollerController = stackScrollerController; mNotificationPanelViewController = notificationPanelViewController; notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp); @@ -201,12 +208,12 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, // no heads up anymore, lets start the disappear animation setShown(false); - animateIsolation = !mIsExpanded; + animateIsolation = !isExpanded(); } else if (previousEntry == null) { // We now have a headsUp and didn't have one before. Let's start the disappear // animation setShown(true); - animateIsolation = !mIsExpanded; + animateIsolation = !isExpanded(); } updateIsolatedIconLocation(false /* requireUpdate */); mNotificationIconAreaController.showIconIsolated(newEntry == null ? null @@ -319,7 +326,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, */ public boolean shouldBeVisible() { boolean notificationsShown = !mWakeUpCoordinator.getNotificationsFullyHidden(); - boolean canShow = !mIsExpanded && notificationsShown; + boolean canShow = !isExpanded() && notificationsShown; if (mBypassController.getBypassEnabled() && (mStatusBarStateController.getState() == StatusBarState.KEYGUARD || mKeyguardStateController.isKeyguardGoingAway()) @@ -337,17 +344,17 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, public void setAppearFraction(float expandedHeight, float appearFraction) { boolean changed = expandedHeight != mExpandedHeight; + boolean oldIsExpanded = isExpanded(); + mExpandedHeight = expandedHeight; mAppearFraction = appearFraction; - boolean isExpanded = expandedHeight > 0; // We only notify if the expandedHeight changed and not on the appearFraction, since // otherwise we may run into an infinite loop where the panel and this are constantly // updating themselves over just a small fraction if (changed) { updateHeadsUpHeaders(); } - if (isExpanded != mIsExpanded) { - mIsExpanded = isExpanded; + if (isExpanded() != oldIsExpanded) { updateTopEntry(); } } @@ -367,6 +374,10 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, } } + private boolean isExpanded() { + return mExpandedHeight > 0; + } + private void updateHeadsUpHeaders() { mHeadsUpManager.getAllEntries().forEach(entry -> { updateHeader(entry); @@ -392,15 +403,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, updateTopEntry(); } - void readFrom(HeadsUpAppearanceController oldController) { - if (oldController != null) { - mTrackedChild = oldController.mTrackedChild; - mExpandedHeight = oldController.mExpandedHeight; - mIsExpanded = oldController.mIsExpanded; - mAppearFraction = oldController.mAppearFraction; - } - } - @Override public void onFullyHiddenChanged(boolean isFullyHidden) { updateTopEntry(); 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 9b5fa2a49ff12..0312c30c73ecc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -88,6 +88,7 @@ import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.FrameLayout; +import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintSet; import com.android.internal.annotations.VisibleForTesting; @@ -451,9 +452,13 @@ public class NotificationPanelViewController extends PanelViewController { private boolean mUserSetupComplete; private boolean mHideIconsDuringLaunchAnimation = true; private int mStackScrollerMeasuringPass; - private ArrayList> - mTrackingHeadsUpListeners = - new ArrayList<>(); + /** + * Non-null if there's a heads-up notification that we're currently tracking the position of. + */ + @Nullable + private ExpandableNotificationRow mTrackedHeadsUpNotification; + private final ArrayList> + mTrackingHeadsUpListeners = new ArrayList<>(); private HeadsUpAppearanceController mHeadsUpAppearanceController; private int mPanelAlpha; @@ -3050,18 +3055,24 @@ public class NotificationPanelViewController extends PanelViewController { mQsExpandImmediate = false; mNotificationStackScrollLayoutController.setShouldShowShelfOnly(false); mTwoFingerQsExpandPossible = false; - notifyListenersTrackingHeadsUp(null); + updateTrackingHeadsUp(null); mExpandingFromHeadsUp = false; setPanelScrimMinFraction(0.0f); } - private void notifyListenersTrackingHeadsUp(ExpandableNotificationRow pickedChild) { + private void updateTrackingHeadsUp(@Nullable ExpandableNotificationRow pickedChild) { + mTrackedHeadsUpNotification = pickedChild; for (int i = 0; i < mTrackingHeadsUpListeners.size(); i++) { Consumer listener = mTrackingHeadsUpListeners.get(i); listener.accept(pickedChild); } } + @Nullable + public ExpandableNotificationRow getTrackedHeadsUpNotification() { + return mTrackedHeadsUpNotification; + } + private void setListening(boolean listening) { mKeyguardStatusBarViewController.setBatteryListening(listening); if (mQs == null) return; @@ -3298,7 +3309,7 @@ public class NotificationPanelViewController extends PanelViewController { public void setTrackedHeadsUp(ExpandableNotificationRow pickedChild) { if (pickedChild != null) { - notifyListenersTrackingHeadsUp(pickedChild); + updateTrackingHeadsUp(pickedChild); mExpandingFromHeadsUp = true; } // otherwise we update the state when the expansion is finished diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index c4ef2221602b3..fed75eb2d4f55 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -1164,7 +1164,6 @@ public class StatusBar extends SystemUI implements mNotificationPanelViewController.updatePanelExpansionAndVisibility(); setBouncerShowingForStatusBarComponents(mBouncerShowing); - HeadsUpAppearanceController oldController = mHeadsUpAppearanceController; if (mHeadsUpAppearanceController != null) { // This view is being recreated, let's destroy the old one // TODO(b/205609837): Automatically destroy the old controller so that this @@ -1175,9 +1174,6 @@ public class StatusBar extends SystemUI implements // TODO(b/205609837): Migrate this to StatusBarFragmentComponent. mHeadsUpAppearanceController = statusBarFragmentComponent.getHeadsUpAppearanceController(); - // TODO(b/205609837): Delete this readFrom method so that this class doesn't - // need to hold a reference to the old controller. - mHeadsUpAppearanceController.readFrom(oldController); mLightsOutNotifController.setLightsOutNotifView( mStatusBarView.findViewById(R.id.notification_lights_out)); 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 bafbccdb87d27..4bdf73efa0860 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 @@ -162,8 +162,11 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { } @Test - public void testHeaderReadFromOldController() { - mHeadsUpAppearanceController.setAppearFraction(1.0f, 1.0f); + public void constructor_animationValuesUpdated() { + float appearFraction = .75f; + float expandedHeight = 400f; + when(mStackScrollerController.getAppearFraction()).thenReturn(appearFraction); + when(mStackScrollerController.getExpandedHeight()).thenReturn(expandedHeight); HeadsUpAppearanceController newController = new HeadsUpAppearanceController( mock(NotificationIconAreaController.class), @@ -179,14 +182,9 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { new View(mContext), new View(mContext), new View(mContext)); - newController.readFrom(mHeadsUpAppearanceController); - Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight, - newController.mExpandedHeight, 0.0f); - Assert.assertEquals(mHeadsUpAppearanceController.mAppearFraction, - newController.mAppearFraction, 0.0f); - Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded, - newController.mIsExpanded); + Assert.assertEquals(expandedHeight, newController.mExpandedHeight, 0.0f); + Assert.assertEquals(appearFraction, newController.mAppearFraction, 0.0f); } @Test