Merge "[Status Bar Refactor] 3/3: Remove HeadsUpAppearanceController#destroy and migrate the controller to a ViewController model instead." into sc-v2-dev

This commit is contained in:
Caitlin Cassidy
2021-11-25 02:48:18 +00:00
committed by Android (Google) Code Review
4 changed files with 35 additions and 38 deletions

View File

@@ -39,6 +39,7 @@ import com.android.systemui.statusbar.notification.stack.NotificationStackScroll
import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentScope; import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentScope;
import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener; import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.util.ViewController;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -49,14 +50,15 @@ import javax.inject.Inject;
* Controls the appearance of heads up notifications in the icon area and the header itself. * Controls the appearance of heads up notifications in the icon area and the header itself.
*/ */
@StatusBarFragmentScope @StatusBarFragmentScope
public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, public class HeadsUpAppearanceController extends ViewController<HeadsUpStatusBarView>
DarkIconDispatcher.DarkReceiver, NotificationWakeUpCoordinator.WakeUpListener { implements OnHeadsUpChangedListener,
DarkIconDispatcher.DarkReceiver,
NotificationWakeUpCoordinator.WakeUpListener {
public static final int CONTENT_FADE_DURATION = 110; public static final int CONTENT_FADE_DURATION = 110;
public static final int CONTENT_FADE_DELAY = 100; public static final int CONTENT_FADE_DELAY = 100;
private final NotificationIconAreaController mNotificationIconAreaController; private final NotificationIconAreaController mNotificationIconAreaController;
private final HeadsUpManagerPhone mHeadsUpManager; private final HeadsUpManagerPhone mHeadsUpManager;
private final NotificationStackScrollLayoutController mStackScrollerController; private final NotificationStackScrollLayoutController mStackScrollerController;
private final HeadsUpStatusBarView mHeadsUpStatusBarView;
private final View mCenteredIconView; private final View mCenteredIconView;
private final View mClockView; private final View mClockView;
private final View mOperatorNameView; private final View mOperatorNameView;
@@ -125,13 +127,10 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
View clockView, View clockView,
View operatorNameView, View operatorNameView,
View centeredIconView) { View centeredIconView) {
super(headsUpStatusBarView);
mNotificationIconAreaController = notificationIconAreaController; mNotificationIconAreaController = notificationIconAreaController;
mHeadsUpManager = headsUpManager; mHeadsUpManager = headsUpManager;
mHeadsUpManager.addListener(this);
mHeadsUpStatusBarView = headsUpStatusBarView;
mCenteredIconView = centeredIconView; mCenteredIconView = centeredIconView;
headsUpStatusBarView.setOnDrawingRectChangedListener(
() -> updateIsolatedIconLocation(true /* requireUpdate */));
// We may be mid-HUN-expansion when this controller is re-created (for example, if the user // 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 // has started pulling down the notification shade from the HUN and then the font size
@@ -143,16 +142,12 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
mStackScrollerController = stackScrollerController; mStackScrollerController = stackScrollerController;
mNotificationPanelViewController = notificationPanelViewController; mNotificationPanelViewController = notificationPanelViewController;
notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp);
notificationPanelViewController.setHeadsUpAppearanceController(this);
mStackScrollerController.addOnExpandedHeightChangedListener(mSetExpandedHeight);
mStackScrollerController.setHeadsUpAppearanceController(this); mStackScrollerController.setHeadsUpAppearanceController(this);
mClockView = clockView; mClockView = clockView;
mOperatorNameView = operatorNameView; mOperatorNameView = operatorNameView;
mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class); mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class);
mDarkIconDispatcher.addDarkReceiver(this);
mHeadsUpStatusBarView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { mView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override @Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) { int oldLeft, int oldTop, int oldRight, int oldBottom) {
@@ -162,21 +157,32 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
// trigger scroller to notify the latest panel translation // trigger scroller to notify the latest panel translation
mStackScrollerController.requestLayout(); mStackScrollerController.requestLayout();
} }
mHeadsUpStatusBarView.removeOnLayoutChangeListener(this); mView.removeOnLayoutChangeListener(this);
} }
}); });
mBypassController = bypassController; mBypassController = bypassController;
mStatusBarStateController = stateController; mStatusBarStateController = stateController;
mWakeUpCoordinator = wakeUpCoordinator; mWakeUpCoordinator = wakeUpCoordinator;
wakeUpCoordinator.addListener(this);
mCommandQueue = commandQueue; mCommandQueue = commandQueue;
mKeyguardStateController = keyguardStateController; mKeyguardStateController = keyguardStateController;
} }
@Override
protected void onViewAttached() {
mHeadsUpManager.addListener(this);
mView.setOnDrawingRectChangedListener(
() -> updateIsolatedIconLocation(true /* requireUpdate */));
mWakeUpCoordinator.addListener(this);
mNotificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp);
mNotificationPanelViewController.setHeadsUpAppearanceController(this);
mStackScrollerController.addOnExpandedHeightChangedListener(mSetExpandedHeight);
mDarkIconDispatcher.addDarkReceiver(this);
}
public void destroy() { @Override
protected void onViewDetached() {
mHeadsUpManager.removeListener(this); mHeadsUpManager.removeListener(this);
mHeadsUpStatusBarView.setOnDrawingRectChangedListener(null); mView.setOnDrawingRectChangedListener(null);
mWakeUpCoordinator.removeListener(this); mWakeUpCoordinator.removeListener(this);
mNotificationPanelViewController.removeTrackingHeadsUpListener(mSetTrackingHeadsUp); mNotificationPanelViewController.removeTrackingHeadsUpListener(mSetTrackingHeadsUp);
mNotificationPanelViewController.setHeadsUpAppearanceController(null); mNotificationPanelViewController.setHeadsUpAppearanceController(null);
@@ -186,7 +192,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
private void updateIsolatedIconLocation(boolean requireStateUpdate) { private void updateIsolatedIconLocation(boolean requireStateUpdate) {
mNotificationIconAreaController.setIsolatedIconLocation( mNotificationIconAreaController.setIsolatedIconLocation(
mHeadsUpStatusBarView.getIconDrawingRect(), requireStateUpdate); mView.getIconDrawingRect(), requireStateUpdate);
} }
@Override @Override
@@ -200,8 +206,8 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
if (shouldBeVisible()) { if (shouldBeVisible()) {
newEntry = mHeadsUpManager.getTopEntry(); newEntry = mHeadsUpManager.getTopEntry();
} }
NotificationEntry previousEntry = mHeadsUpStatusBarView.getShowingEntry(); NotificationEntry previousEntry = mView.getShowingEntry();
mHeadsUpStatusBarView.setEntry(newEntry); mView.setEntry(newEntry);
if (newEntry != previousEntry) { if (newEntry != previousEntry) {
boolean animateIsolation = false; boolean animateIsolation = false;
if (newEntry == null) { if (newEntry == null) {
@@ -226,8 +232,8 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
mShown = isShown; mShown = isShown;
if (isShown) { if (isShown) {
updateParentClipping(false /* shouldClip */); updateParentClipping(false /* shouldClip */);
mHeadsUpStatusBarView.setVisibility(View.VISIBLE); mView.setVisibility(View.VISIBLE);
show(mHeadsUpStatusBarView); show(mView);
hide(mClockView, View.INVISIBLE); hide(mClockView, View.INVISIBLE);
if (mCenteredIconView.getVisibility() != View.GONE) { if (mCenteredIconView.getVisibility() != View.GONE) {
hide(mCenteredIconView, View.INVISIBLE); hide(mCenteredIconView, View.INVISIBLE);
@@ -243,21 +249,21 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
if (mOperatorNameView != null) { if (mOperatorNameView != null) {
show(mOperatorNameView); show(mOperatorNameView);
} }
hide(mHeadsUpStatusBarView, View.GONE, () -> { hide(mView, View.GONE, () -> {
updateParentClipping(true /* shouldClip */); updateParentClipping(true /* shouldClip */);
}); });
} }
// Show the status bar icons when the view gets shown / hidden // Show the status bar icons when the view gets shown / hidden
if (mStatusBarStateController.getState() != StatusBarState.SHADE) { if (mStatusBarStateController.getState() != StatusBarState.SHADE) {
mCommandQueue.recomputeDisableFlags( mCommandQueue.recomputeDisableFlags(
mHeadsUpStatusBarView.getContext().getDisplayId(), false); mView.getContext().getDisplayId(), false);
} }
} }
} }
private void updateParentClipping(boolean shouldClip) { private void updateParentClipping(boolean shouldClip) {
ViewClippingUtil.setClippingDeactivated( ViewClippingUtil.setClippingDeactivated(
mHeadsUpStatusBarView, !shouldClip, mParentClippingParams); mView, !shouldClip, mParentClippingParams);
} }
/** /**
@@ -396,7 +402,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
@Override @Override
public void onDarkChanged(Rect area, float darkIntensity, int tint) { public void onDarkChanged(Rect area, float darkIntensity, int tint) {
mHeadsUpStatusBarView.onDarkChanged(area, darkIntensity, tint); mView.onDarkChanged(area, darkIntensity, tint);
} }
public void onStateChanged() { public void onStateChanged() {

View File

@@ -664,7 +664,6 @@ public class StatusBar extends SystemUI implements
private boolean mNoAnimationOnNextBarModeChange; private boolean mNoAnimationOnNextBarModeChange;
private final SysuiStatusBarStateController mStatusBarStateController; private final SysuiStatusBarStateController mStatusBarStateController;
private HeadsUpAppearanceController mHeadsUpAppearanceController;
private final ActivityLaunchAnimator mActivityLaunchAnimator; private final ActivityLaunchAnimator mActivityLaunchAnimator;
private NotificationLaunchAnimatorControllerProvider mNotificationAnimationProvider; private NotificationLaunchAnimatorControllerProvider mNotificationAnimationProvider;
protected StatusBarNotificationPresenter mPresenter; protected StatusBarNotificationPresenter mPresenter;
@@ -1164,17 +1163,6 @@ public class StatusBar extends SystemUI implements
mNotificationPanelViewController.updatePanelExpansionAndVisibility(); mNotificationPanelViewController.updatePanelExpansionAndVisibility();
setBouncerShowingForStatusBarComponents(mBouncerShowing); setBouncerShowingForStatusBarComponents(mBouncerShowing);
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
// class doesn't need to hold a reference to the old one.
mHeadsUpAppearanceController.destroy();
}
// TODO (b/136993073) Separate notification shade and status bar
// TODO(b/205609837): Migrate this to StatusBarFragmentComponent.
mHeadsUpAppearanceController =
statusBarFragmentComponent.getHeadsUpAppearanceController();
mLightsOutNotifController.setLightsOutNotifView( mLightsOutNotifController.setLightsOutNotifView(
mStatusBarView.findViewById(R.id.notification_lights_out)); mStatusBarView.findViewById(R.id.notification_lights_out));
mNotificationShadeWindowViewController.setStatusBarView(mStatusBarView); mNotificationShadeWindowViewController.setStatusBarView(mStatusBarView);

View File

@@ -57,6 +57,7 @@ public interface StatusBarFragmentComponent {
// No one accesses this controller, so we need to make sure we reference it here so it does // No one accesses this controller, so we need to make sure we reference it here so it does
// get initialized. // get initialized.
getBatteryMeterViewController().init(); getBatteryMeterViewController().init();
getHeadsUpAppearanceController().init();
} }
/** */ /** */

View File

@@ -193,7 +193,9 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
reset(mDarkIconDispatcher); reset(mDarkIconDispatcher);
reset(mPanelView); reset(mPanelView);
reset(mStackScrollerController); reset(mStackScrollerController);
mHeadsUpAppearanceController.destroy();
mHeadsUpAppearanceController.onViewDetached();
verify(mHeadsUpManager).removeListener(any()); verify(mHeadsUpManager).removeListener(any());
verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any()); verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any());
verify(mPanelView).removeTrackingHeadsUpListener(any()); verify(mPanelView).removeTrackingHeadsUpListener(any());