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

Commit 195653af authored by Joey's avatar Joey Committed by Luca Stefani
Browse files

SystemUI: add top exclusion to the back gesture



Allow the user to exclude the top ?dp of the device from the
back edge gesture area

Change-Id: I1f3c07706d4121461395af568ac4662b942d8488
Signed-off-by: default avatarJoey <joey@lineageos.org>
Signed-off-by: default avatarLuca Stefani <luca.stefani.ge1@gmail.com>
Signed-off-by: default avatarJesse Chan <jc@lineageos.org>
parent 9d42c48c
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
    private static final String KEY_EDGE_LONG_SWIPE_ACTION =
            "lineagesystem:" + LineageSettings.System.KEY_EDGE_LONG_SWIPE_ACTION;

    private static final String KEY_GESTURE_BACK_EXCLUDE_TOP =
            "lineagesecure:" + LineageSettings.Secure.GESTURE_BACK_EXCLUDE_TOP;

    private final IPinnedStackListener.Stub mImeChangedListener = new IPinnedStackListener.Stub() {
        @Override
        public void onListenerRegistered(IPinnedStackController controller) {
@@ -152,6 +155,8 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun


    private final int mNavBarHeight;
    // User-limited area
    private int mUserExclude;

    private final PointF mDownPoint = new PointF();
    private boolean mThresholdCrossed = false;
@@ -190,6 +195,7 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun

        final TunerService tunerService = Dependency.get(TunerService.class);
        tunerService.addTunable(this, KEY_EDGE_LONG_SWIPE_ACTION);
        tunerService.addTunable(this, KEY_GESTURE_BACK_EXCLUDE_TOP);

        // Reduce the default touch slop to ensure that we can intercept the gesture
        // before the app starts to react to it.
@@ -338,8 +344,14 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
    }

    private boolean isWithinTouchRegion(int x, int y) {
        final int baseY = mDisplaySize.y - Math.max(mImeHeight, mNavBarHeight);
        // Disallow if over the IME
        if (y > (mDisplaySize.y - Math.max(mImeHeight, mNavBarHeight))) {
        if (y > baseY) {
            return false;
        }

        // Disallow if over user exclusion area
        if (mUserExclude > 0 && y < baseY - mUserExclude) {
            return false;
        }

@@ -511,6 +523,7 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
                .getDisplay(mDisplayId)
                .getRealSize(mDisplaySize);
        updateLongSwipeWidth();
        loadUserExclusion();
    }

    @Override
@@ -519,6 +532,8 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
            mIsLongSwipeEnabled = newValue != null
                    && Action.fromIntSafe(Integer.parseInt(newValue)) != Action.NOTHING;
            updateLongSwipeWidth();
        } else if (KEY_GESTURE_BACK_EXCLUDE_TOP.equals(key)) {
            loadUserExclusion();
        }
    }

@@ -542,6 +557,19 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
        InputManager.getInstance().injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    }

    private void loadUserExclusion() {
        if (mDisplaySize == null) return;

        final int excludedPercentage = LineageSettings.Secure.getInt(mContext.getContentResolver(),
                LineageSettings.Secure.GESTURE_BACK_EXCLUDE_TOP, 0);
        if (excludedPercentage != 0) {
            // Exclude a part of the top of the vertical display size
            mUserExclude = mDisplaySize.y - mDisplaySize.y * excludedPercentage / 100;
        } else {
            mUserExclude = 0;
        }
    }

    public void setInsets(int leftInset, int rightInset) {
        mLeftInset = leftInset;
        mRightInset = rightInset;