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

Commit 13a56d50 authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Status Bar Refactor] Remove final StatusBar references from

PhoneStatusBarView.

The references are moved into NotificationPanelViewController, which
admittedly isn't *that* much better of a location but it's better for it
to be in a controller instead of a view, and NPVC already has 40+
references to StatusBar.

Fixes: 199733640
Test: manual (verified StatusBar's callback still triggers)
Test: atest SystemUITests
Change-Id: I05a4f0ed52c02f0caff621f64d188189cceb48d0
parent 8a9fb9c2
Loading
Loading
Loading
Loading
+50 −40
Original line number Diff line number Diff line
@@ -3789,45 +3789,6 @@ public class NotificationPanelViewController extends PanelViewController {

            private long mLastTouchDownTime = -1L;

            @Override
            public boolean onTouchForwardedFromStatusBar(MotionEvent event) {
                // TODO(b/202981994): Move the touch debugging in this method to a central location.
                //  (Right now, it's split between StatusBar and here.)

                // If panels aren't enabled, ignore the gesture and don't pass it down to the
                // panel view.
                if (!mCommandQueue.panelsEnabled()) {
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        Log.v(
                                TAG,
                                String.format(
                                        "onTouchForwardedFromStatusBar: "
                                                + "panel disabled, ignoring touch at (%d,%d)",
                                        (int) event.getX(),
                                        (int) event.getY()
                                )
                        );
                    }
                    return false;
                }

                // If the view that would receive the touch is disabled, just have status bar eat
                // the gesture.
                if (event.getAction() == MotionEvent.ACTION_DOWN && !mView.isEnabled()) {
                    Log.v(TAG,
                            String.format(
                                    "onTouchForwardedFromStatusBar: "
                                            + "panel view disabled, eating touch at (%d,%d)",
                                    (int) event.getX(),
                                    (int) event.getY()
                            )
                    );
                    return true;
                }

                return mView.dispatchTouchEvent(event);
            }

            @Override
            public boolean onInterceptTouchEvent(MotionEvent event) {
                if (mBlockTouches || mQs.disallowPanelTouches()) {
@@ -3939,6 +3900,55 @@ public class NotificationPanelViewController extends PanelViewController {
        };
    }

    private final PhoneStatusBarView.TouchEventHandler mStatusBarViewTouchEventHandler =
            new PhoneStatusBarView.TouchEventHandler() {
                @Override
                public void onInterceptTouchEvent(MotionEvent event) {
                    mStatusBar.onTouchEvent(event);
                }

                @Override
                public boolean handleTouchEvent(MotionEvent event) {
                    mStatusBar.onTouchEvent(event);

                    // TODO(b/202981994): Move the touch debugging in this method to a central
                    //  location. (Right now, it's split between StatusBar and here.)

                    // If panels aren't enabled, ignore the gesture and don't pass it down to the
                    // panel view.
                    if (!mCommandQueue.panelsEnabled()) {
                        if (event.getAction() == MotionEvent.ACTION_DOWN) {
                            Log.v(
                                    TAG,
                                    String.format(
                                            "onTouchForwardedFromStatusBar: "
                                                    + "panel disabled, ignoring touch at (%d,%d)",
                                            (int) event.getX(),
                                            (int) event.getY()
                                    )
                            );
                        }
                        return false;
                    }

                    // If the view that would receive the touch is disabled, just have status bar
                    // eat the gesture.
                    if (event.getAction() == MotionEvent.ACTION_DOWN && !mView.isEnabled()) {
                        Log.v(TAG,
                                String.format(
                                        "onTouchForwardedFromStatusBar: "
                                                + "panel view disabled, eating touch at (%d,%d)",
                                        (int) event.getX(),
                                        (int) event.getY()
                                )
                        );
                        return true;
                    }

                    return mView.dispatchTouchEvent(event);
                }
            };

    @Override
    protected PanelViewController.OnConfigurationChangedListener
            createOnConfigurationChangedListener() {
@@ -4698,6 +4708,6 @@ public class NotificationPanelViewController extends PanelViewController {

    /** Returns the handler that the status bar should forward touches to. */
    public PhoneStatusBarView.TouchEventHandler getStatusBarTouchEventHandler() {
        return getTouchHandler()::onTouchForwardedFromStatusBar;
        return mStatusBarViewTouchEventHandler;
    }
}
+1 −15
Original line number Diff line number Diff line
@@ -292,10 +292,6 @@ public abstract class PanelViewController {
                : mTouchSlop;
    }

    protected TouchHandler getTouchHandler() {
        return mTouchHandler;
    }

    private void addMovement(MotionEvent event) {
        // Add movement to velocity tracker using raw screen X and Y coordinates instead
        // of window coordinates because the window frame may be moving at the same time.
@@ -1161,17 +1157,7 @@ public abstract class PanelViewController {
        return new OnConfigurationChangedListener();
    }

    public abstract class TouchHandler implements View.OnTouchListener {
        /**
         * Method called when a touch has occurred on {@link PhoneStatusBarView}.
         *
         * Touches that occur on the status bar view may have ramifications for the notification
         * panel (e.g. a touch that pulls down the shade could start on the status bar), so we need
         * to notify the panel controller when these touches occur.
         *
         * Returns true if the event was handled and false otherwise.
         */
        public abstract boolean onTouchForwardedFromStatusBar(MotionEvent event);
    public class TouchHandler implements View.OnTouchListener {

        public boolean onInterceptTouchEvent(MotionEvent event) {
            if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted
+18 −17
Original line number Diff line number Diff line
@@ -50,9 +50,6 @@ public class PhoneStatusBarView extends FrameLayout {
    private static final String TAG = "PhoneStatusBarView";
    private final StatusBarContentInsetsProvider mContentInsetsProvider;

    StatusBar mBar;

    private ScrimController mScrimController;
    private DarkReceiver mBattery;
    private DarkReceiver mClock;
    private int mRotationOrientation = -1;
@@ -76,18 +73,10 @@ public class PhoneStatusBarView extends FrameLayout {
        mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class);
    }

    public void setBar(StatusBar bar) {
        mBar = bar;
    }

    void setTouchEventHandler(TouchEventHandler handler) {
        mTouchEventHandler = handler;
    }

    public void setScrimController(ScrimController scrimController) {
        mScrimController = scrimController;
    }

    @Override
    public void onFinishInflate() {
        mBattery = findViewById(R.id.battery);
@@ -174,7 +163,6 @@ public class PhoneStatusBarView extends FrameLayout {

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        mBar.onTouchEvent(event);
        if (mTouchEventHandler == null) {
            Log.w(
                    TAG,
@@ -191,7 +179,7 @@ public class PhoneStatusBarView extends FrameLayout {

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        mBar.onTouchEvent(event);
        mTouchEventHandler.onInterceptTouchEvent(event);
        return super.onInterceptTouchEvent(event);
    }

@@ -275,13 +263,26 @@ public class PhoneStatusBarView extends FrameLayout {
    }

    /**
     * A handler repsonsible for all touch event handling on the status bar.
     * A handler responsible for all touch event handling on the status bar.
     *
     * The handler will be notified each time {@link this#onTouchEvent} is called, and the return
     * value from the handler will be returned from {@link this#onTouchEvent}.
     * Touches that occur on the status bar view may have ramifications for the notification
     * panel (e.g. a touch that pulls down the shade could start on the status bar), so this
     * interface provides a way to notify the panel controller when these touches occur.
     *
     * The handler will be notified each time {@link PhoneStatusBarView#onTouchEvent} and
     * {@link PhoneStatusBarView#onInterceptTouchEvent} are called.
     **/
    public interface TouchEventHandler {
        /** Called each time {@link this#onTouchEvent} is called. */
        /** Called each time {@link PhoneStatusBarView#onInterceptTouchEvent} is called. */
        void onInterceptTouchEvent(MotionEvent event);

        /**
         * Called each time {@link PhoneStatusBarView#onTouchEvent} is called.
         *
         * Should return true if the touch was handled by this handler and false otherwise. The
         * return value from the handler will be returned from
         * {@link PhoneStatusBarView#onTouchEvent}.
         */
        boolean handleTouchEvent(MotionEvent event);
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -1142,8 +1142,6 @@ public class StatusBar extends SystemUI implements

                    PhoneStatusBarView oldStatusBarView = mStatusBarView;
                    mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView();
                    mStatusBarView.setBar(this);
                    mStatusBarView.setScrimController(mScrimController);

                    mPhoneStatusBarViewController = mPhoneStatusBarViewControllerFactory
                            .create(mStatusBarView, mNotificationPanelViewController
+14 −10
Original line number Diff line number Diff line
@@ -523,10 +523,12 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
    }

    @Test
    public void onTouchForwardedFromStatusBar_panelsNotEnabled_returnsFalseAndNoViewEvent() {
    public void handleTouchEventFromStatusBar_panelsNotEnabled_returnsFalseAndNoViewEvent() {
        when(mCommandQueue.panelsEnabled()).thenReturn(false);

        boolean returnVal = mTouchHandler.onTouchForwardedFromStatusBar(
        boolean returnVal = mNotificationPanelViewController
                .getStatusBarTouchEventHandler()
                .handleTouchEvent(
                        MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));

        assertThat(returnVal).isFalse();
@@ -534,11 +536,13 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
    }

    @Test
    public void onTouchForwardedFromStatusBar_viewNotEnabled_returnsTrueAndNoViewEvent() {
    public void handleTouchEventFromStatusBar_viewNotEnabled_returnsTrueAndNoViewEvent() {
        when(mCommandQueue.panelsEnabled()).thenReturn(true);
        when(mView.isEnabled()).thenReturn(false);

        boolean returnVal = mTouchHandler.onTouchForwardedFromStatusBar(
        boolean returnVal = mNotificationPanelViewController
                .getStatusBarTouchEventHandler()
                .handleTouchEvent(
                        MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));

        assertThat(returnVal).isTrue();
@@ -546,23 +550,23 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
    }

    @Test
    public void onTouchForwardedFromStatusBar_viewNotEnabledButIsMoveEvent_viewReceivesEvent() {
    public void handleTouchEventFromStatusBar_viewNotEnabledButIsMoveEvent_viewReceivesEvent() {
        when(mCommandQueue.panelsEnabled()).thenReturn(true);
        when(mView.isEnabled()).thenReturn(false);
        MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 0f, 0f, 0);

        mTouchHandler.onTouchForwardedFromStatusBar(event);
        mNotificationPanelViewController.getStatusBarTouchEventHandler().handleTouchEvent(event);

        verify(mView).dispatchTouchEvent(event);
    }

    @Test
    public void onTouchForwardedFromStatusBar_panelAndViewEnabled_viewReceivesEvent() {
    public void handleTouchEventFromStatusBar_panelAndViewEnabled_viewReceivesEvent() {
        when(mCommandQueue.panelsEnabled()).thenReturn(true);
        when(mView.isEnabled()).thenReturn(true);
        MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0);

        mTouchHandler.onTouchForwardedFromStatusBar(event);
        mNotificationPanelViewController.getStatusBarTouchEventHandler().handleTouchEvent(event);

        verify(mView).dispatchTouchEvent(event);
    }
Loading