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

Unverified Commit 0d84febc authored by someone5678's avatar someone5678 Committed by Michael Bestas
Browse files

Implement edge long swipe gesture to new back gesture affordance



Co-authored-by: default avatarLuK1337 <priv.luk@gmail.com>
Co-authored-by: default avatarNico <nicorg2529@gmail.com>
Co-authored-by: default avatarOnlyTomInSecond <q2781273965@gmail.com>
Change-Id: I6a54d781b64aeec278b9f1be4a42bcfaf681b160
parent 16a91df1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2151,6 +2151,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
@@ -55,6 +55,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>
+41 −0
Original line number Diff line number Diff line
@@ -135,6 +135,9 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    /** Registry for the back animations */
    private final ShellBackAnimationRegistry mShellBackAnimationRegistry;

    /** @see #setTriggerLongSwipe(boolean) */
    private boolean mTriggerLongSwipe;

    @Nullable
    private BackNavigationInfo mBackNavigationInfo;
    private boolean mReceivedNullNavigationInfo = false;
@@ -362,6 +365,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,
@@ -842,6 +851,17 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        }
    }

    /**
     * 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,
@@ -869,6 +889,11 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
                dispatchOnBackInvoked(callback);
            } else {
                tryDispatchOnBackCancelled(callback);
                if (mTriggerLongSwipe) {
                    sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK,
                            KeyEvent.FLAG_LONG_SWIPE);
                    sendEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK, KeyEvent.FLAG_LONG_SWIPE);
                }
            }
        }
        mRealCallbackInvoked = false;
@@ -886,6 +911,9 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
                    "onGestureFinished called while no gesture is started");
            return;
        }
        if (mTriggerLongSwipe) {
            mCurrentTracker.setTriggerBack(false);
        }
        boolean triggerBack = activeTouchTracker.getTriggerBack();
        ProtoLog.d(WM_SHELL_BACK_PREVIEW, "onGestureFinished() mTriggerBack == %s", triggerBack);

@@ -942,6 +970,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 mContext.getSystemService(InputManager.class).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.
@@ -1079,6 +1119,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            mBackNavigationInfo = null;
            requestTopUi(false, mPreviousNavigationType);
        }
        mTriggerLongSwipe = false;
    }

    private void startLatencyTracking() {
+11 −1
Original line number Diff line number Diff line
@@ -42,6 +42,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);

@@ -54,7 +57,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();
@@ -65,5 +68,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(context: Context, private val latencyTracker: LatencyTracker) :
            maximumValue = 1f,
        )

    var triggerLongSwipe = false

    private val allAnimatedFloat =
        setOf(
            arrowLength,
@@ -295,6 +297,9 @@ class BackPanel(context: Context, private val latencyTracker: LatencyTracker) :
        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
    }

@@ -509,6 +514,9 @@ class BackPanel(context: Context, private val latencyTracker: LatencyTracker) :
        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