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

Commit 57920a80 authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Handle key events in Launcher.

Change-Id: I7531080a7534ba2788cebec723ce552609c92b1c
Fixes: 125551024
Test: Swipe up from app and press back. It takes user back to the current app.
parent 3d6f8aab
Loading
Loading
Loading
Loading
+1.92 KiB (152 KiB)

File changed.

No diff preview for this file type.

+16 −6
Original line number Diff line number Diff line
@@ -17,15 +17,13 @@ package com.android.quickstep;

import android.annotation.TargetApi;
import android.os.Build;
import android.view.InputEvent;
import android.view.KeyEvent;
import android.view.MotionEvent;

import java.util.function.Consumer;

@TargetApi(Build.VERSION_CODES.O)
@FunctionalInterface
public interface TouchConsumer extends Consumer<MotionEvent> {

    TouchConsumer NO_OP = (ev) -> {};
public interface InputConsumer {
    InputConsumer NO_OP = new InputConsumer() { };

    default boolean isActive() {
        return false;
@@ -35,4 +33,16 @@ public interface TouchConsumer extends Consumer<MotionEvent> {
     * Called by the event queue when the consumer is about to be switched to a new consumer.
     */
    default void onConsumerAboutToBeSwitched() { }

    default void onMotionEvent(MotionEvent ev) { }

    default void onKeyEvent(KeyEvent ev) { }

    default void onInputEvent(InputEvent ev) {
        if (ev instanceof MotionEvent) {
            onMotionEvent((MotionEvent) ev);
        } else {
            onKeyEvent((KeyEvent) ev);
        }
    }
}
+8 −8
Original line number Diff line number Diff line
@@ -62,13 +62,13 @@ import com.android.systemui.shared.system.WindowManagerWrapper;
import java.util.function.Consumer;

/**
 * Touch consumer for handling events originating from an activity other than Launcher
 * Input consumer for handling events originating from an activity other than Launcher
 */
@TargetApi(Build.VERSION_CODES.P)
public class OtherActivityTouchConsumer extends ContextWrapper implements TouchConsumer {
public class OtherActivityInputConsumer extends ContextWrapper implements InputConsumer {

    public static final String DOWN_EVT = "OtherActivityTouchConsumer.DOWN";
    private static final String UP_EVT = "OtherActivityTouchConsumer.UP";
    public static final String DOWN_EVT = "OtherActivityInputConsumer.DOWN";
    private static final String UP_EVT = "OtherActivityInputConsumer.UP";

    private final CachedEventDispatcher mRecentsViewDispatcher = new CachedEventDispatcher();
    private final RunningTaskInfo mRunningTask;
@@ -83,7 +83,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
    private final int mDisplayRotation;
    private final Rect mStableInsets = new Rect();

    private final Consumer<OtherActivityTouchConsumer> mOnCompleteCallback;
    private final Consumer<OtherActivityInputConsumer> mOnCompleteCallback;
    private final MotionPauseDetector mMotionPauseDetector;
    private VelocityTracker mVelocityTracker;

@@ -105,11 +105,11 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
    // TODO: Start displacement should have both x and y
    private float mStartDisplacement;

    public OtherActivityTouchConsumer(Context base, RunningTaskInfo runningTaskInfo,
    public OtherActivityInputConsumer(Context base, RunningTaskInfo runningTaskInfo,
            RecentsModel recentsModel, Intent homeIntent, ActivityControlHelper activityControl,
            boolean isDeferredDownTarget, OverviewCallbacks overviewCallbacks,
            TaskOverlayFactory taskOverlayFactory, InputConsumerController inputConsumer,
            Consumer<OtherActivityTouchConsumer> onCompleteCallback,
            Consumer<OtherActivityInputConsumer> onCompleteCallback,
            SwipeSharedState swipeSharedState) {
        super(base);

@@ -139,7 +139,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
    }

    @Override
    public void accept(MotionEvent ev) {
    public void onMotionEvent(MotionEvent ev) {
        if (mVelocityTracker == null) {
            return;
        }
+18 −9
Original line number Diff line number Diff line
@@ -20,10 +20,12 @@ import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_UP;

import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
import static com.android.quickstep.TouchInteractionService.TOUCH_INTERACTION_LOG;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS;

import android.graphics.PointF;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

@@ -33,10 +35,10 @@ import com.android.quickstep.util.CachedEventDispatcher;
import com.android.systemui.shared.system.ActivityManagerWrapper;

/**
 * Touch consumer for handling touch on the recents/Launcher activity.
 * Input consumer for handling touch on the recents/Launcher activity.
 */
public class OverviewTouchConsumer<T extends BaseDraggingActivity>
        implements TouchConsumer {
public class OverviewInputConsumer<T extends BaseDraggingActivity>
        implements InputConsumer {

    private final CachedEventDispatcher mCachedEventDispatcher = new CachedEventDispatcher();
    private final T mActivity;
@@ -50,7 +52,7 @@ public class OverviewTouchConsumer<T extends BaseDraggingActivity>
    private boolean mTrackingStarted = false;
    private boolean mInvalidated = false;

    OverviewTouchConsumer(T activity, boolean startingInActivityBounds) {
    OverviewInputConsumer(T activity, boolean startingInActivityBounds) {
        mActivity = activity;
        mTarget = activity.getDragLayer();
        mTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop();
@@ -58,7 +60,7 @@ public class OverviewTouchConsumer<T extends BaseDraggingActivity>
    }

    @Override
    public void accept(MotionEvent ev) {
    public void onMotionEvent(MotionEvent ev) {
        if (mInvalidated) {
            return;
        }
@@ -96,11 +98,18 @@ public class OverviewTouchConsumer<T extends BaseDraggingActivity>

            // Set an empty consumer to that all the cached events are cleared
            if (!mCachedEventDispatcher.hasConsumer()) {
                mCachedEventDispatcher.setConsumer(NO_OP);
                mCachedEventDispatcher.setConsumer(motionEvent -> { });
            }
        }
    }

    @Override
    public void onKeyEvent(KeyEvent ev) {
        if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            mActivity.dispatchKeyEvent(ev);
        }
    }

    private void startTouchTracking(MotionEvent ev, boolean updateLocationOffset,
            boolean closeActiveWindows) {
        if (updateLocationOffset) {
@@ -135,12 +144,12 @@ public class OverviewTouchConsumer<T extends BaseDraggingActivity>
        ev.setEdgeFlags(flags);
    }

    public static TouchConsumer newInstance(ActivityControlHelper activityHelper,
    public static InputConsumer newInstance(ActivityControlHelper activityHelper,
            boolean startingInActivityBounds) {
        BaseDraggingActivity activity = activityHelper.getCreatedActivity();
        if (activity == null) {
            return TouchConsumer.NO_OP;
            return InputConsumer.NO_OP;
        }
        return new OverviewTouchConsumer(activity, startingInActivityBounds);
        return new OverviewInputConsumer(activity, startingInActivityBounds);
    }
}
 No newline at end of file
+30 −13
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;

import android.view.InputEvent;
import android.view.KeyEvent;
import android.view.MotionEvent;

import com.android.launcher3.util.Preconditions;
@@ -43,18 +45,18 @@ public class RecentsAnimationWrapper {

    private boolean mWindowThresholdCrossed = false;

    private final InputConsumerController mInputConsumer;
    private final Supplier<TouchConsumer> mTouchProxySupplier;
    private final InputConsumerController mInputConsumerController;
    private final Supplier<InputConsumer> mInputProxySupplier;

    private TouchConsumer mTouchConsumer;
    private InputConsumer mInputConsumer;
    private boolean mTouchInProgress;

    private boolean mFinishPending;

    public RecentsAnimationWrapper(InputConsumerController inputConsumer,
            Supplier<TouchConsumer> touchProxySupplier) {
        mInputConsumer = inputConsumer;
        mTouchProxySupplier = touchProxySupplier;
    public RecentsAnimationWrapper(InputConsumerController inputConsumerController,
            Supplier<InputConsumer> inputProxySupplier) {
        mInputConsumerController = inputConsumerController;
        mInputProxySupplier = inputProxySupplier;
    }

    @UiThread
@@ -132,15 +134,30 @@ public class RecentsAnimationWrapper {
        }
    }

    public void enableTouchProxy() {
        mInputConsumer.setTouchListener(this::onInputConsumerTouch);
    public void enableInputProxy() {
        mInputConsumerController.setInputListener(this::onInputConsumerEvent);
    }

    private boolean onInputConsumerTouch(MotionEvent ev) {
    private boolean onInputConsumerEvent(InputEvent ev) {
        if (ev instanceof MotionEvent) {
            onInputConsumerMotionEvent((MotionEvent) ev);
        } else if (ev instanceof KeyEvent) {
            if (mInputConsumer == null) {
                mInputConsumer = mInputProxySupplier.get();
            }
            mInputConsumer.onKeyEvent((KeyEvent) ev);
            return true;
        }
        return false;
    }

    private boolean onInputConsumerMotionEvent(MotionEvent ev) {
        int action = ev.getAction();
        if (action == ACTION_DOWN) {
            mTouchInProgress = true;
            mTouchConsumer = mTouchProxySupplier.get();
            if (mInputConsumer == null) {
                mInputConsumer = mInputProxySupplier.get();
            }
        } else if (action == ACTION_CANCEL || action == ACTION_UP) {
            // Finish any pending actions
            mTouchInProgress = false;
@@ -149,8 +166,8 @@ public class RecentsAnimationWrapper {
                finishAndClear(true /* toRecents */, null);
            }
        }
        if (mTouchConsumer != null) {
            mTouchConsumer.accept(ev);
        if (mInputConsumer != null) {
            mInputConsumer.onMotionEvent(ev);
        }

        return true;
Loading