[Status Bar Refactor] Move PanelBar#collapsePanel into

NotificationPanelViewController.

PanelBar#collapsePanel mostly just called through to
PanelViewController, so the function might as well belong in PVC.

Test: Manually verified that the same functions are called in the
correct order in various scenarios (open shade, close shade, open QS
tile into new activity, close QS via home button while in app)
Test: atest SystemUITests
Bug: 200063118

Change-Id: I3c5d41db7daf8085baea73db806c6e350a7115bf
This commit is contained in:
Caitlin Cassidy
2021-10-01 03:25:39 +00:00
parent 38b65a1565
commit 2e4f5782b6
8 changed files with 64 additions and 50 deletions

View File

@@ -1526,6 +1526,24 @@ public class NotificationPanelViewController extends PanelViewController {
mNotificationStackScrollLayoutController.resetScrollPosition();
}
/** Collapses the panel. */
public void collapsePanel(boolean animate, boolean delayed, float speedUpFactor) {
boolean waiting = false;
if (animate && !isFullyCollapsed()) {
collapse(delayed, speedUpFactor);
waiting = true;
} else {
resetViews(false /* animate */);
setExpandedFraction(0); // just in case
}
if (!waiting) {
// it's possible that nothing animated, so we replicate the termination
// conditions of panelExpansionChanged here
// TODO(b/200063118): This can likely go away in a future refactor CL.
mBar.updateState(STATE_CLOSED);
}
}
@Override
public void collapse(boolean delayed, float speedUpFactor) {
if (!canPanelBeCollapsed()) {
@@ -3052,6 +3070,7 @@ public class NotificationPanelViewController extends PanelViewController {
mAffordanceHelper.animateHideLeftRightIcon();
}
mNotificationStackScrollLayoutController.onPanelTrackingStarted();
cancelPendingPanelCollapse();
}
@Override
@@ -3671,13 +3690,27 @@ public class NotificationPanelViewController extends PanelViewController {
mNotificationStackScrollLayoutController.setScrollingEnabled(b);
}
private Runnable mHideExpandedRunnable;
private final Runnable mMaybeHideExpandedRunnable = new Runnable() {
@Override
public void run() {
if (getExpansionFraction() == 0.0f) {
mView.post(mHideExpandedRunnable);
}
}
};
/**
* Initialize objects instead of injecting to avoid circular dependencies.
*
* @param hideExpandedRunnable a runnable to run when we need to hide the expanded panel.
*/
public void initDependencies(
StatusBar statusBar,
Runnable hideExpandedRunnable,
NotificationShelfController notificationShelfController) {
setStatusBar(statusBar);
mHideExpandedRunnable = hideExpandedRunnable;
mNotificationStackScrollLayoutController.setShelfController(notificationShelfController);
mNotificationShelfController = notificationShelfController;
mLockscreenShadeTransitionController.bindController(notificationShelfController);
@@ -4568,6 +4601,11 @@ public class NotificationPanelViewController extends PanelViewController {
}
}
/** Removes any pending runnables that would collapse the panel. */
public void cancelPendingPanelCollapse() {
mView.removeCallbacks(mMaybeHideExpandedRunnable);
}
private final PanelBar.PanelStateChangeListener mPanelStateChangeListener =
new PanelBar.PanelStateChangeListener() {
@@ -4582,6 +4620,11 @@ public class NotificationPanelViewController extends PanelViewController {
if (state == STATE_OPEN && mCurrentState != state) {
mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
if (state == STATE_CLOSED) {
// Close the status bar in the next frame so we can show the end of the
// animation.
mView.post(mMaybeHideExpandedRunnable);
}
mCurrentState = state;
}
};

View File

@@ -58,6 +58,14 @@ public abstract class PanelBar extends FrameLayout {
private int mState = STATE_CLOSED;
private boolean mTracking;
/** Updates the panel state if necessary. */
public void updateState(@PanelState int state) {
if (DEBUG) LOG("update state: %d -> %d", mState, state);
if (mState != state) {
go(state);
}
}
private void go(@PanelState int state) {
if (DEBUG) LOG("go state: %d -> %d", mState, state);
mState = state;
@@ -171,32 +179,12 @@ public abstract class PanelBar extends FrameLayout {
go(STATE_OPEN);
} else if (fullyClosed && !mTracking && mState != STATE_CLOSED) {
go(STATE_CLOSED);
onPanelCollapsed();
}
if (SPEW) LOG("panelExpansionChanged: end state=%d [%s%s ]", mState,
fullyOpened?" fullyOpened":"", fullyClosed?" fullyClosed":"");
}
public void collapsePanel(boolean animate, boolean delayed, float speedUpFactor) {
boolean waiting = false;
PanelViewController pv = mPanel;
if (animate && !pv.isFullyCollapsed()) {
pv.collapse(delayed, speedUpFactor);
waiting = true;
} else {
pv.resetViews(false /* animate */);
pv.setExpandedFraction(0); // just in case
}
if (DEBUG) LOG("collapsePanel: animate=%s waiting=%s", animate, waiting);
if (!waiting && mState != STATE_CLOSED) {
// it's possible that nothing animated, so we replicate the termination
// conditions of panelExpansionChanged here
go(STATE_CLOSED);
onPanelCollapsed();
}
}
public void onPanelPeeked() {
if (DEBUG) LOG("onPanelPeeked");
}
@@ -205,10 +193,6 @@ public abstract class PanelBar extends FrameLayout {
return mState == STATE_CLOSED;
}
public void onPanelCollapsed() {
if (DEBUG) LOG("onPanelCollapsed");
}
public void onTrackingStarted() {
mTracking = true;
}

View File

@@ -1435,4 +1435,8 @@ public abstract class PanelViewController {
private void cancelJankMonitoring(int cuj) {
InteractionJankMonitor.getInstance().cancel(cuj);
}
protected float getExpansionFraction() {
return mExpandedFraction;
}
}

View File

@@ -55,14 +55,6 @@ public class PhoneStatusBarView extends PanelBar {
StatusBar mBar;
private ScrimController mScrimController;
private Runnable mHideExpandedRunnable = new Runnable() {
@Override
public void run() {
if (mPanelFraction == 0.0f) {
mBar.makeExpandedInvisible();
}
}
};
private DarkReceiver mBattery;
private DarkReceiver mClock;
private int mRotationOrientation = -1;
@@ -84,7 +76,6 @@ public class PhoneStatusBarView extends PanelBar {
* Draw this many pixels into the left/right side of the cutout to optimally use the space
*/
private int mCutoutSideNudge = 0;
private boolean mHeadsUpVisible;
public PhoneStatusBarView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -207,17 +198,6 @@ public class PhoneStatusBarView extends PanelBar {
mBar.makeExpandedVisible(false);
}
@Override
public void onPanelCollapsed() {
super.onPanelCollapsed();
// Close the status bar in the next frame so we can show the end of the animation.
post(mHideExpandedRunnable);
}
public void removePendingHideExpandedRunnables() {
removeCallbacks(mHideExpandedRunnable);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean barConsumedEvent = mBar.interceptTouchEvent(event);
@@ -238,7 +218,6 @@ public class PhoneStatusBarView extends PanelBar {
super.onTrackingStarted();
mBar.onTrackingStarted();
mScrimController.onTrackingStarted();
removePendingHideExpandedRunnables();
}
@Override

View File

@@ -128,7 +128,8 @@ public class ShadeControllerImpl implements ShadeController {
mNotificationShadeWindowController.setNotificationShadeFocusable(false);
getStatusBar().getNotificationShadeWindowViewController().cancelExpandHelper();
getStatusBarView().collapsePanel(true /* animate */, delayed, speedUpFactor);
getNotificationPanelViewController()
.collapsePanel(true /* animate */, delayed, speedUpFactor);
} else if (mBubblesOptional.isPresent()) {
mBubblesOptional.get().collapseStack();
}

View File

@@ -1316,6 +1316,7 @@ public class StatusBar extends SystemUI implements
mNotificationPanelViewController.initDependencies(
this,
this::makeExpandedInvisible,
mNotificationShelfController);
BackDropView backdrop = mNotificationShadeWindowView.findViewById(R.id.backdrop);
@@ -2157,7 +2158,8 @@ public class StatusBar extends SystemUI implements
public void animateCollapseQuickSettings() {
if (mState == StatusBarState.SHADE) {
mStatusBarView.collapsePanel(true, false /* delayed */, 1.0f /* speedUpFactor */);
mNotificationPanelViewController.collapsePanel(
true, false /* delayed */, 1.0f /* speedUpFactor */);
}
}
@@ -2170,7 +2172,7 @@ public class StatusBar extends SystemUI implements
}
// Ensure the panel is fully collapsed (just in case; bug 6765842, 7260868)
mStatusBarView.collapsePanel(/*animate=*/ false, false /* delayed*/,
mNotificationPanelViewController.collapsePanel(/*animate=*/ false, false /* delayed*/,
1.0f /* speedUpFactor */);
mNotificationPanelViewController.closeQs();
@@ -4464,7 +4466,7 @@ public class StatusBar extends SystemUI implements
mNavigationBarController.touchAutoDim(mDisplayId);
Trace.beginSection("StatusBar#updateKeyguardState");
if (mState == StatusBarState.KEYGUARD && mStatusBarView != null) {
mStatusBarView.removePendingHideExpandedRunnables();
mNotificationPanelViewController.cancelPendingPanelCollapse();
}
updateDozingState();
checkBarModes();

View File

@@ -536,7 +536,7 @@ public class StatusBarCommandQueueCallbacks implements CommandQueue.Callbacks {
}
if (mStatusBar.getStatusBarView() != null) {
if (!showing && mStatusBarStateController.getState() == StatusBarState.SHADE) {
mStatusBar.getStatusBarView().collapsePanel(
mNotificationPanelViewController.collapsePanel(
false /* animate */, false /* delayed */, 1.0f /* speedUpFactor */);
}

View File

@@ -450,6 +450,7 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
mControlsComponent);
mNotificationPanelViewController.initDependencies(
mStatusBar,
() -> {},
mNotificationShelfController);
mNotificationPanelViewController.setHeadsUpManager(mHeadsUpManager);
mNotificationPanelViewController.setBar(mPanelBar);