[Status Bar Refactor] 2/3: Remove
HeadsUpAppearanceController#readFrom(oldController). Instead, the old values are read from the parent controllers. This CL plus the next CL will allow us to not keep track of old HeadsUpAppearanceController instances; instead, each HeadsUpAppearanceController knows how to correctly set itself up and tear itself down without needing the old controller. Bug: 205609837 Test: atest SystemUITests Test: manual (verified via logging that new controller gets old values) Change-Id: I15adc79982b5b7ca264e2bb45e92ba48b9844c1a
This commit is contained in:
@@ -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})
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Consumer<ExpandableNotificationRow>>
|
||||
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<Consumer<ExpandableNotificationRow>>
|
||||
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<ExpandableNotificationRow> 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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user