From 397468da2ed8c785d79ebb4925c9e1397fb81d51 Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Fri, 30 Dec 2022 17:58:03 +0000 Subject: [PATCH] Support back gesture on trackpad TODO: change back animation API to consider trackpad events Bug: 255697805 Test: https://recall.googleplex.com/projects/3388b17c-d22f-46f8-b140-a102690377b4/sessions/3f751251-07f2-4cce-b577-474746bf4eab Change-Id: I50963a3a495c9f2069bdc9e2a8606bb403b51f1c --- .../plugins/MotionEventsHandlerBase.java | 31 ++++ .../plugins/NavigationEdgeBackPlugin.java | 3 + .../gestural/BackPanelController.kt | 5 + .../gestural/EdgeBackGestureHandler.java | 32 +++- .../gestural/MotionEventsHandler.java | 114 ++++++++++++++ .../gestural/NavigationBarEdgePanel.java | 26 ++-- .../navigationbar/gestural/Utilities.java | 40 +++++ .../gestural/MotionEventsHandlerTest.java | 145 ++++++++++++++++++ 8 files changed, 377 insertions(+), 19 deletions(-) create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/MotionEventsHandlerBase.java create mode 100644 packages/SystemUI/src/com/android/systemui/navigationbar/gestural/MotionEventsHandler.java create mode 100644 packages/SystemUI/src/com/android/systemui/navigationbar/gestural/Utilities.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/MotionEventsHandlerTest.java diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/MotionEventsHandlerBase.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/MotionEventsHandlerBase.java new file mode 100644 index 0000000000000..2a6418530e87b --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/MotionEventsHandlerBase.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.plugins; + +import android.view.MotionEvent; + +/** Handles both trackpad and touch events and report displacements in both axis's. */ +public interface MotionEventsHandlerBase { + + void onMotionEvent(MotionEvent ev); + + float getDisplacementX(MotionEvent ev); + + float getDisplacementY(MotionEvent ev); + + String dump(); +} diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/NavigationEdgeBackPlugin.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/NavigationEdgeBackPlugin.java index 5f6f11c16da2d..054e30056124c 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/NavigationEdgeBackPlugin.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/NavigationEdgeBackPlugin.java @@ -48,6 +48,9 @@ public interface NavigationEdgeBackPlugin extends Plugin { /** Sets the base LayoutParams for the UI. */ void setLayoutParams(WindowManager.LayoutParams layoutParams); + /** Sets the motion events handler for the plugin. */ + default void setMotionEventsHandler(MotionEventsHandlerBase motionEventsHandler) {} + /** Updates the UI based on the motion events passed in device coordinates. */ void onMotionEvent(MotionEvent motionEvent); diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt index 6e927b071727e..1950c694e07d7 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt @@ -38,6 +38,7 @@ import androidx.dynamicanimation.animation.DynamicAnimation import androidx.dynamicanimation.animation.SpringForce import com.android.internal.util.LatencyTracker import com.android.systemui.dagger.qualifiers.Main +import com.android.systemui.plugins.MotionEventsHandlerBase import com.android.systemui.plugins.NavigationEdgeBackPlugin import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.policy.ConfigurationController @@ -498,6 +499,10 @@ class BackPanelController private constructor( windowManager.addView(mView, layoutParams) } + override fun setMotionEventsHandler(motionEventsHandler: MotionEventsHandlerBase?) { + TODO("Not yet implemented") + } + private fun isFlung() = velocityTracker!!.run { computeCurrentVelocity(1000) abs(xVelocity) > MIN_FLING_VELOCITY diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java index 6c99b6764909c..e32c3011fbca7 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java @@ -18,6 +18,8 @@ package com.android.systemui.navigationbar.gestural; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_EXCLUDE_FROM_SCREEN_MAGNIFICATION; import static com.android.systemui.classifier.Classifier.BACK_GESTURE; +import static com.android.systemui.navigationbar.gestural.Utilities.getTrackpadScale; +import static com.android.systemui.navigationbar.gestural.Utilities.isTrackpadMotionEvent; import android.annotation.NonNull; import android.app.ActivityManager; @@ -241,6 +243,7 @@ public class EdgeBackGestureHandler implements PluginListener