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

Unverified Commit 1dd61d82 authored by someone5678's avatar someone5678 Committed by Michael Bestas
Browse files

Implement edge long swipe gesture to new back gesture affordance

Author: Nico <nicorg2529@gmail.com>
Date:   Sun Mar 8 11:39:47 2020 +0000

    Implement edge long swipe gesture [1/3]

    The gesture will activate if user executes edge swipe for a long
    horizontal motion. The triggered action is configurable in Button
    Settings.

    Reference:
    https://gerrit.dirtyunicorns.com/q/topic:%22back-longswipe-actions%22

    Change-Id: Ie1bbe6645b6a00d346af60d6bb5e4d584997d6e9

Author: LuK1337 <priv.luk@gmail.com>
Date:   Thu Nov 25 17:39:29 2021 +0100

    Use custom flag for edge long swipe gesture

    Previously we were using same flags that'd be used for regular back key
    long press thus being unable to determine whether the event was sent
    from EdgeBackGestureHandle or not.

    Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/4194


    Change-Id: I5c4fd455f581ac5c9c5e3a146095be33e82e8d6e

Author: someone5678 <nemui3353@gmail.com>
Date:   Fri, 14 Jul 2023 17:26:19 +0900

    Adapt and fix from original long swipe gesture impl

    Change-Id: I22c6442299df0cf15d046718fa40df6fb6aee07c
    Signed-off-by: default avatarsomeone5678 <nemui3353@gmail.com>

Author: someone5678 <nemui3353@gmail.com>
Date:   Sun Jul 30 20:55:13 2023 +0900

    Flip back gesture canvas if started from left

    * Better than constant right arrow direction

    Change-Id: I45108f185130d6f778660ba11f3beb758826ba99
    Signed-off-by: default avatarsomeone5678 <nemui3353@gmail.com>

Author: someone5678 <nemui3353@gmail.com>
Date:   Tue Aug 1 12:25:00 2023 +0900

    Always add second arrow in front on long swipe

    * After last commit if long swipe gesture started from left, second arrow is added
      in back instead of front.

    * This looks unnatural and causes inconsistency with right.

    * Hardcode to -1 so that second arrow always added in front of first one.

    Change-Id: Ia043a749218ab40c40520736fa54ffaa26919137
    Signed-off-by: default avatarsomeone5678 <nemui3353@gmail.com>

Change-Id: I6a54d781b64aeec278b9f1be4a42bcfaf681b160
parent 8fa113cf
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1314,6 +1314,12 @@ public class KeyEvent extends InputEvent implements Parcelable {
     */
    public static final int FLAG_FALLBACK = 0x400;

    /**
     * Flag that indicates that event was sent from EdgeBackGestureHandler.
     * @hide
     */
    public static final int FLAG_LONG_SWIPE = 0x800;

    /**
     * This flag indicates that this event was modified by or generated from an accessibility
     * service. Value = 0x800
+5 −0
Original line number Diff line number Diff line
@@ -53,6 +53,11 @@ public interface BackAnimation {
     */
    void setTriggerBack(boolean triggerBack);

    /**
     * Sets whether the back long swipe gesture is past the trigger threshold or not.
     */
    void setTriggerLongSwipe(boolean triggerLongSwipe);

    /**
     * Sets the threshold values that define edge swipe behavior.<br>
     * <br>
+38 −0
Original line number Diff line number Diff line
@@ -113,6 +113,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    private boolean mShouldStartOnNextMoveEvent = false;
    /** @see #setTriggerBack(boolean) */
    private boolean mTriggerBack;
    /** @see #setTriggerLongSwipe(boolean) */
    private boolean mTriggerLongSwipe;
    private FlingAnimationUtils mFlingAnimationUtils;

    @Nullable
@@ -300,6 +302,12 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            mShellExecutor.execute(() -> BackAnimationController.this.setTriggerBack(triggerBack));
        }

        @Override
        public void setTriggerLongSwipe(boolean triggerLongSwipe) {
            mShellExecutor.execute(
                    () -> BackAnimationController.this.setTriggerLongSwipe(triggerLongSwipe));
        }

        @Override
        public void setSwipeThresholds(
                float linearDistance,
@@ -608,6 +616,17 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        mTouchTracker.setTriggerBack(triggerBack);
    }

    /**
     * Sets to true when the back long swipe gesture has passed the triggering threshold,
     * false otherwise.
     */
    public void setTriggerLongSwipe(boolean triggerLongSwipe) {
        if (mPostCommitAnimationInProgress) {
            return;
        }
        mTriggerLongSwipe = triggerLongSwipe;
    }

    private void setSwipeThresholds(
            float linearDistance,
            float maxDistance,
@@ -669,6 +688,12 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            finishBackNavigation();
            return;
        }
        if (mTriggerLongSwipe) {
            // Let key event handlers deal with back long swipe gesture
            sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK, KeyEvent.FLAG_LONG_SWIPE);
            sendEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK, KeyEvent.FLAG_LONG_SWIPE);
            return;
        }

        final int backType = mBackNavigationInfo.getType();
        final BackAnimationRunner runner = mAnimationDefinition.get(backType);
@@ -690,6 +715,18 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        startPostCommitAnimation();
    }

    private boolean sendEvent(int action, int code, int flags) {
        long when = SystemClock.uptimeMillis();
        final KeyEvent ev = new KeyEvent(when, when, action, code, 0 /* repeat */,
                0 /* metaState */, KeyCharacterMap.VIRTUAL_KEYBOARD, 0 /* scancode */,
                flags | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
                InputDevice.SOURCE_KEYBOARD);

        ev.setDisplayId(mContext.getDisplay().getDisplayId());
        return InputManager.getInstance().injectInputEvent(
                ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    }

    /**
     * Start the phase 2 animation when gesture is released.
     * Callback to {@link #onBackAnimationFinished} when it is finished or timeout.
@@ -748,6 +785,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            mBackNavigationInfo = null;
        }
        mTriggerBack = false;
        mTriggerLongSwipe = false;
    }

    private BackAnimationRunner getAnimationRunnerAndInit() {
+11 −1
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ public interface NavigationEdgeBackPlugin extends Plugin {
    /** Sets the callback that should be invoked when a Back gesture is detected. */
    void setBackCallback(BackCallback callback);

    /** Specifies if the long swipe should be enabled or not. */
    default void setLongSwipeEnabled(boolean enabled) {}

    /** Sets the base LayoutParams for the UI. */
    void setLayoutParams(WindowManager.LayoutParams layoutParams);

@@ -57,7 +60,7 @@ public interface NavigationEdgeBackPlugin extends Plugin {
    /** Callback to let the system react to the detected back gestures. */
    interface BackCallback {
        /** Indicates that a Back gesture was recognized and the system should go back. */
        void triggerBack();
        void triggerBack(boolean isLongPress);

        /** Indicates that the gesture was cancelled and the system should not go back. */
        void cancelBack();
@@ -68,5 +71,12 @@ public interface NavigationEdgeBackPlugin extends Plugin {
         * @param triggerBack if back will be triggered in current state.
         */
        void setTriggerBack(boolean triggerBack);

        /**
         * Indicates if long swipe will be triggered if committed in current state.
         *
         * @param triggerLongSwipe if long swipe will be triggered in current state.
         */
        void setTriggerLongSwipe(boolean triggerLongSwipe);
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -121,6 +121,8 @@ class BackPanel(
            maximumValue = 1f
    )

    var triggerLongSwipe = false

    private val allAnimatedFloat = setOf(
            arrowLength,
            arrowHeight,
@@ -293,6 +295,9 @@ class BackPanel(
        arrowPath.lineTo(0f, 0f)
        arrowPath.lineTo(dx, dy)
        arrowPath.moveTo(dx, -dy)
        if (triggerLongSwipe) {
            arrowPath.addPath(arrowPath, arrowPaint.strokeWidth * 2.0f * -1, 0.0f)
        }
        return arrowPath
    }

@@ -502,6 +507,9 @@ class BackPanel(
        val arrowPath = calculateArrowPath(dx = dx, dy = dy)
        val arrowPaint = arrowPaint
                .apply { alpha = (255 * min(arrowAlpha.pos, backgroundAlpha.pos)).toInt() }
        if (isLeftPanel) {
            canvas.scale(-1f, 1f, dx / 2f, dy / 2f)
        }
        canvas.drawPath(arrowPath, arrowPaint)
        canvas.restore()

Loading