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

Commit d2e7e355 authored by Jun Mukai's avatar Jun Mukai
Browse files

Allow sticky immersive mode by mouse hover.

When the app enters into the immersive mode, swipe down from the
top edge makes immersive_sticky (showing transient status bar),
but this is hardly done by mouse. As is discussed in the bug,
we want to make the same effect for mouse hover at the very top
line of the screen for 500msec.

Same applied to navigation bar with the bottom of the screen.

Bug: 20093789
Change-Id: If4484b5bcee567ea89c28ed06807564cb8f9ccef
parent 0867d262
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -635,6 +635,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_POWER_DELAYED_PRESS = 13;
    private static final int MSG_POWER_LONG_PRESS = 14;
    private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
    private static final int MSG_REQUEST_TRANSIENT_BARS = 16;

    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;

    private class PolicyHandler extends Handler {
        @Override
@@ -686,6 +690,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
                    updateDreamingSleepToken(msg.arg1 != 0);
                    break;
                case MSG_REQUEST_TRANSIENT_BARS:
                    WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
                            mStatusBar : mNavigationBar;
                    if (targetBar != null) {
                        requestTransientBars(targetBar);
                    }
                    break;
            }
        }
    }
@@ -1503,6 +1514,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    public void onUpOrCancel() {
                        mOrientationListener.onTouchEnd();
                    }
                    @Override
                    public void onMouseHoverAtTop() {
                        mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
                        Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
                        msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
                        mHandler.sendMessageDelayed(msg, 500);
                    }
                    @Override
                    public void onMouseHoverAtBottom() {
                        mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
                        Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
                        msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
                        mHandler.sendMessageDelayed(msg, 500);
                    }
                    @Override
                    public void onMouseLeaveFromEdge() {
                        mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
                    }
                });
        mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
        mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
+24 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
    private int mDownPointers;
    private boolean mSwipeFireable;
    private boolean mDebugFireable;
    private boolean mMouseHoveringAtEdge;

    public SystemGesturesPointerEventListener(Context context, Callbacks callbacks) {
        mCallbacks = checkNull("callbacks", callbacks);
@@ -75,6 +76,10 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
                mDebugFireable = true;
                mDownPointers = 0;
                captureDown(event, 0);
                if (mMouseHoveringAtEdge) {
                    mMouseHoveringAtEdge = false;
                    mCallbacks.onMouseLeaveFromEdge();
                }
                mCallbacks.onDown();
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
@@ -103,6 +108,22 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
                    }
                }
                break;
            case MotionEvent.ACTION_HOVER_MOVE:
                if (event.getPointerCount() == 1
                        && event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
                    if (!mMouseHoveringAtEdge && event.getY() == 0) {
                        mCallbacks.onMouseHoverAtTop();
                        mMouseHoveringAtEdge = true;
                    } else if (!mMouseHoveringAtEdge && event.getY() >= screenHeight - 1) {
                        mCallbacks.onMouseHoverAtBottom();
                        mMouseHoveringAtEdge = true;
                    } else if (mMouseHoveringAtEdge
                            && (event.getY() > 0 && event.getY() < screenHeight - 1)) {
                        mCallbacks.onMouseLeaveFromEdge();
                        mMouseHoveringAtEdge = false;
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mSwipeFireable = false;
@@ -196,6 +217,9 @@ public class SystemGesturesPointerEventListener implements PointerEventListener
        void onSwipeFromRight();
        void onDown();
        void onUpOrCancel();
        void onMouseHoverAtTop();
        void onMouseHoverAtBottom();
        void onMouseLeaveFromEdge();
        void onDebug();
    }
}