diff options
author | Tracy Zhou <tracyzhou@google.com> | 2019-02-21 19:53:27 -0800 |
---|---|---|
committer | Tracy Zhou <tracyzhou@google.com> | 2019-02-27 10:21:42 -0800 |
commit | 6ab083273940c796fd5ab4853bb9c55131aa33e6 (patch) | |
tree | b0c6bda0651d861274d0aba372a24199621eda14 | |
parent | fd6d850d72297aa46bdb1137f52731186dccb98d (diff) | |
download | android_packages_apps_Trebuchet-6ab083273940c796fd5ab4853bb9c55131aa33e6.tar.gz android_packages_apps_Trebuchet-6ab083273940c796fd5ab4853bb9c55131aa33e6.tar.bz2 android_packages_apps_Trebuchet-6ab083273940c796fd5ab4853bb9c55131aa33e6.zip |
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.
9 files changed, 91 insertions, 56 deletions
diff --git a/quickstep/libs/sysui_shared.jar b/quickstep/libs/sysui_shared.jar Binary files differindex 5ec699cd0..8c58e3ed5 100644 --- a/quickstep/libs/sysui_shared.jar +++ b/quickstep/libs/sysui_shared.jar diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/InputConsumer.java index 12ae7b633..8dfb9abdd 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/InputConsumer.java @@ -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); + } + } } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityInputConsumer.java index 012e6709c..67bfeaa24 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityTouchConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/OtherActivityInputConsumer.java @@ -64,13 +64,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; @@ -85,7 +85,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; @@ -113,11 +113,11 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC true /* restoreHomeStackPosition */); }; - 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); @@ -148,7 +148,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC } @Override - public void accept(MotionEvent ev) { + public void onMotionEvent(MotionEvent ev) { if (mVelocityTracker == null) { return; } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewTouchConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewInputConsumer.java index 4da52e15c..28c4db46a 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewTouchConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewInputConsumer.java @@ -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 diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java index 5e7c1a1c5..f0bc223de 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsAnimationWrapper.java @@ -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; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java index b54270192..4b660d4cf 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionLog.java @@ -42,7 +42,7 @@ public class TouchInteractionLog { getCurrentLog().add("[" + mDateFormat.format(mCalendar.getTime()) + "]"); } - public void setTouchConsumer(TouchConsumer consumer) { + public void setInputConsumer(InputConsumer consumer) { getCurrentLog().add("tc=" + consumer.getClass().getSimpleName()); } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java index 0ccd141a3..ddf3ad584 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java @@ -159,7 +159,7 @@ public class TouchInteractionService extends Service { private InputConsumerController mInputConsumer; private SwipeSharedState mSwipeSharedState; - private TouchConsumer mConsumer = TouchConsumer.NO_OP; + private InputConsumer mConsumer = InputConsumer.NO_OP; private Choreographer mMainChoreographer; private InputEventReceiver mInputEventReceiver; @@ -226,34 +226,34 @@ public class TouchInteractionService extends Service { boolean useSharedState = mConsumer.isActive(); mConsumer.onConsumerAboutToBeSwitched(); mConsumer = newConsumer(useSharedState, event); - TOUCH_INTERACTION_LOG.setTouchConsumer(mConsumer); + TOUCH_INTERACTION_LOG.setInputConsumer(mConsumer); } TOUCH_INTERACTION_LOG.addMotionEvent(event); - mConsumer.accept(event); + mConsumer.onMotionEvent(event); } - private TouchConsumer newConsumer(boolean useSharedState, MotionEvent event) { + private InputConsumer newConsumer(boolean useSharedState, MotionEvent event) { RunningTaskInfo runningTaskInfo = mAM.getRunningTask(0); if (!useSharedState) { mSwipeSharedState.clearAllState(); } if (runningTaskInfo == null && !mSwipeSharedState.goingToLauncher) { - return TouchConsumer.NO_OP; + return InputConsumer.NO_OP; } else if (mSwipeSharedState.goingToLauncher || mOverviewComponentObserver.getActivityControlHelper().isResumed()) { - return OverviewTouchConsumer.newInstance( + return OverviewInputConsumer.newInstance( mOverviewComponentObserver.getActivityControlHelper(), false); } else if (ENABLE_QUICKSTEP_LIVE_TILE.get() && mOverviewComponentObserver.getActivityControlHelper().isInLiveTileMode()) { - return OverviewTouchConsumer.newInstance( + return OverviewInputConsumer.newInstance( mOverviewComponentObserver.getActivityControlHelper(), false); } else { ActivityControlHelper activityControl = mOverviewComponentObserver.getActivityControlHelper(); boolean shouldDefer = activityControl.deferStartingActivity(mActiveNavBarRegion, event); - return new OtherActivityTouchConsumer(this, runningTaskInfo, mRecentsModel, + return new OtherActivityInputConsumer(this, runningTaskInfo, mRecentsModel, mOverviewComponentObserver.getOverviewIntent(), activityControl, shouldDefer, mOverviewCallbacks, mTaskOverlayFactory, mInputConsumer, this::onConsumerInactive, mSwipeSharedState); @@ -263,9 +263,9 @@ public class TouchInteractionService extends Service { /** * To be called by the consumer when it's no longer active. */ - private void onConsumerInactive(TouchConsumer caller) { + private void onConsumerInactive(InputConsumer caller) { if (mConsumer == caller) { - mConsumer = TouchConsumer.NO_OP; + mConsumer = InputConsumer.NO_OP; } } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java index f578149a9..4d0136e0d 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -56,7 +56,6 @@ import android.os.Build; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; -import android.util.Log; import android.view.HapticFeedbackConstants; import android.view.MotionEvent; import android.view.View; @@ -274,7 +273,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> .createActivityInitListener(this::onActivityInit); mContinuingLastGesture = continuingLastGesture; mRecentsAnimationWrapper = new RecentsAnimationWrapper(inputConsumer, - this::createNewTouchProxyHandler); + this::createNewInputProxyHandler); mClipAnimationHelper = new ClipAnimationHelper(context); mTransformParams = new ClipAnimationHelper.TransformParams(); @@ -719,7 +718,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> } @UiThread - private TouchConsumer createNewTouchProxyHandler() { + private InputConsumer createNewInputProxyHandler() { mCurrentShift.finishAnimation(); if (mLauncherTransitionController != null) { mLauncherTransitionController.getAnimationPlayer().end(); @@ -729,7 +728,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> setTargetAlphaProvider(WindowTransformSwipeHandler::getHiddenTargetAlpha); } - return OverviewTouchConsumer.newInstance(mActivityControlHelper, true); + return OverviewInputConsumer.newInstance(mActivityControlHelper, true); } @UiThread @@ -823,7 +822,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> setShelfState(ShelfAnimState.CANCEL, LINEAR, 0); duration = Math.max(MIN_OVERSHOOT_DURATION, duration); } else if (endTarget == RECENTS) { - mRecentsAnimationWrapper.enableTouchProxy(); + mRecentsAnimationWrapper.enableInputProxy(); if (mRecentsView != null) { duration = Math.max(duration, mRecentsView.getScroller().getDuration()); } diff --git a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java index c24396862..fe789aade 100644 --- a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java +++ b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java @@ -63,11 +63,11 @@ public class StartLauncherViaGestureTests extends AbstractQuickStepTest { public void testPressHome() { runTest(enterEvt(Launcher.ON_CREATE_EVT), exitEvt(Launcher.ON_CREATE_EVT), - enterEvt(OtherActivityTouchConsumer.DOWN_EVT), - exitEvt(OtherActivityTouchConsumer.DOWN_EVT)); + enterEvt(OtherActivityInputConsumer.DOWN_EVT), + exitEvt(OtherActivityInputConsumer.DOWN_EVT)); - runTest(enterEvt(OtherActivityTouchConsumer.DOWN_EVT), - exitEvt(OtherActivityTouchConsumer.DOWN_EVT), + runTest(enterEvt(OtherActivityInputConsumer.DOWN_EVT), + exitEvt(OtherActivityInputConsumer.DOWN_EVT), enterEvt(Launcher.ON_CREATE_EVT), exitEvt(Launcher.ON_CREATE_EVT)); } |