From 7235a7860310ed21014ed328edf4fdff4cd45f94 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Wed, 28 Apr 2021 10:34:14 +0700 Subject: [PATCH] Use existing StatusBarTouchController to handle swipe down --- .../StatusBarTouchController.java | 23 ++++++++++++++++++- .../touch/WorkspaceTouchListener.java | 5 ---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java index 7a7cbb4d9b..d91cad0525 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java @@ -21,6 +21,7 @@ import static android.view.MotionEvent.ACTION_UP; import static android.view.MotionEvent.ACTION_CANCEL; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN; +import android.annotation.SuppressLint; import android.graphics.PointF; import android.util.SparseArray; import android.view.MotionEvent; @@ -39,6 +40,7 @@ import com.android.launcher3.util.TouchController; import com.android.quickstep.SystemUiProxy; import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; /** * TouchController for handling touch events that get sent to the StatusBar. Once the @@ -69,6 +71,8 @@ public class StatusBarTouchController implements TouchController { /* If {@code false}, this controller should not handle the input {@link MotionEvent}.*/ private boolean mCanIntercept; + private boolean mExpanded; + public StatusBarTouchController(Launcher l) { mLauncher = l; mSystemUiProxy = SystemUiProxy.INSTANCE.get(mLauncher); @@ -89,6 +93,22 @@ public class StatusBarTouchController implements TouchController { if (mSystemUiProxy.isActive()) { mLastAction = ev.getActionMasked(); mSystemUiProxy.onStatusBarMotionEvent(ev); + } else { + if (!mExpanded) { + mExpanded = true; + expand(); + } + } + } + + @SuppressLint({"WrongConstant", "PrivateApi"}) + private void expand() { + try { + Class.forName("android.app.StatusBarManager") + .getMethod("expandNotificationsPanel") + .invoke(mLauncher.getSystemService("statusbar")); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) { + e.printStackTrace(); } } @@ -102,6 +122,7 @@ public class StatusBarTouchController implements TouchController { if (!mCanIntercept) { return false; } + mExpanded = false; mDownEvents.put(pid, new PointF(ev.getX(), ev.getY())); } else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { // Check!! should only set it only when threshold is not entered. @@ -168,6 +189,6 @@ public class StatusBarTouchController implements TouchController { return false; } } - return SystemUiProxy.INSTANCE.get(mLauncher).isActive(); + return true; } } \ No newline at end of file diff --git a/src/com/android/launcher3/touch/WorkspaceTouchListener.java b/src/com/android/launcher3/touch/WorkspaceTouchListener.java index b208ade1d8..e4fa5248d7 100644 --- a/src/com/android/launcher3/touch/WorkspaceTouchListener.java +++ b/src/com/android/launcher3/touch/WorkspaceTouchListener.java @@ -45,8 +45,6 @@ import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.views.OptionsPopupView; -import app.lawnchair.gestures.SwipeDownGesture; - /** * Helper class to handle touch on empty space in workspace and show options popup on long press */ @@ -73,7 +71,6 @@ public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListe private int mLongPressState = STATE_CANCELLED; private final GestureDetector mGestureDetector; - private final SwipeDownGesture mSwipeDown; public WorkspaceTouchListener(Launcher launcher, Workspace workspace) { mLauncher = launcher; @@ -82,12 +79,10 @@ public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListe // likely to cause movement. mTouchSlop = 2 * ViewConfiguration.get(launcher).getScaledTouchSlop(); mGestureDetector = new GestureDetector(workspace.getContext(), this); - mSwipeDown = new SwipeDownGesture(workspace.getContext()); } @Override public boolean onTouch(View view, MotionEvent ev) { - mSwipeDown.onTouch(view, ev); mGestureDetector.onTouchEvent(ev); int action = ev.getActionMasked();