Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e4f5782 authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[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
parent 38b65a15
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -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;
                }
            };
+8 −24
Original line number Diff line number Diff line
@@ -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;
    }
+4 −0
Original line number Diff line number Diff line
@@ -1435,4 +1435,8 @@ public abstract class PanelViewController {
    private void cancelJankMonitoring(int cuj) {
        InteractionJankMonitor.getInstance().cancel(cuj);
    }

    protected float getExpansionFraction() {
        return mExpandedFraction;
    }
}
+0 −21
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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();
        }
Loading