Use existing StatusBarTouchController to handle swipe down

This commit is contained in:
Suphon Thanakornpakapong
2021-04-28 10:34:14 +07:00
parent 664d443b1a
commit 7235a78603
2 changed files with 22 additions and 6 deletions
@@ -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;
}
}
@@ -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();