summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSiarhei Vishniakou <svv@google.com>2019-04-23 10:00:59 -0500
committerSiarhei Vishniakou <svv@google.com>2019-04-23 10:00:59 -0500
commitdff3beb6b923160dbe55e3db025fbca4ceb844f5 (patch)
treeff4b841d2b9473654cb0fc940027f54de4482ac5 /src
parentf31848fe8dbb7b360a90cab7c6cbc40cfa99e590 (diff)
downloadandroid_packages_apps_Trebuchet-dff3beb6b923160dbe55e3db025fbca4ceb844f5.tar.gz
android_packages_apps_Trebuchet-dff3beb6b923160dbe55e3db025fbca4ceb844f5.tar.bz2
android_packages_apps_Trebuchet-dff3beb6b923160dbe55e3db025fbca4ceb844f5.zip
Use GestureDetector in WorkspaceTouchListener
Replace the current callback logic in WorkspaceTouchListener with the use of GestureDetector. Platform-provided api will now be used for detecting long press. Test: long press on empty home screen Bug: 126596502 Change-Id: I5beb9158ee0d9ec6ac031465f15923eed2d5f066
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/touch/WorkspaceTouchListener.java17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/com/android/launcher3/touch/WorkspaceTouchListener.java b/src/com/android/launcher3/touch/WorkspaceTouchListener.java
index 4de082e90..07ddccb31 100644
--- a/src/com/android/launcher3/touch/WorkspaceTouchListener.java
+++ b/src/com/android/launcher3/touch/WorkspaceTouchListener.java
@@ -20,12 +20,12 @@ import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_POINTER_UP;
import static android.view.MotionEvent.ACTION_UP;
-import static android.view.ViewConfiguration.getLongPressTimeout;
import static com.android.launcher3.LauncherState.NORMAL;
import android.graphics.PointF;
import android.graphics.Rect;
+import android.view.GestureDetector;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
@@ -45,7 +45,8 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
/**
* Helper class to handle touch on empty space in workspace and show options popup on long press
*/
-public class WorkspaceTouchListener implements OnTouchListener, Runnable {
+public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListener
+ implements OnTouchListener {
/**
* STATE_PENDING_PARENT_INFORM is the state between longPress performed & the next motionEvent.
@@ -66,16 +67,21 @@ public class WorkspaceTouchListener implements OnTouchListener, Runnable {
private int mLongPressState = STATE_CANCELLED;
+ private final GestureDetector mGestureDetector;
+
public WorkspaceTouchListener(Launcher launcher, Workspace workspace) {
mLauncher = launcher;
mWorkspace = workspace;
// Use twice the touch slop as we are looking for long press which is more
// likely to cause movement.
mTouchSlop = 2 * ViewConfiguration.get(launcher).getScaledTouchSlop();
+ mGestureDetector = new GestureDetector(workspace.getContext(), this);
}
@Override
public boolean onTouch(View view, MotionEvent ev) {
+ mGestureDetector.onTouchEvent(ev);
+
int action = ev.getActionMasked();
if (action == ACTION_DOWN) {
// Check if we can handle long press.
@@ -97,7 +103,6 @@ public class WorkspaceTouchListener implements OnTouchListener, Runnable {
if (handleLongPress) {
mLongPressState = STATE_REQUESTED;
mTouchDownPoint.set(ev.getX(), ev.getY());
- mWorkspace.postDelayed(this, getLongPressTimeout());
}
mWorkspace.onTouchEvent(ev);
@@ -143,9 +148,6 @@ public class WorkspaceTouchListener implements OnTouchListener, Runnable {
}
}
- if (action == ACTION_UP || action == ACTION_CANCEL) {
- cancelLongPress();
- }
return result;
}
@@ -155,12 +157,11 @@ public class WorkspaceTouchListener implements OnTouchListener, Runnable {
}
private void cancelLongPress() {
- mWorkspace.removeCallbacks(this);
mLongPressState = STATE_CANCELLED;
}
@Override
- public void run() {
+ public void onLongPress(MotionEvent event) {
if (mLongPressState == STATE_REQUESTED) {
if (canHandleLongPress()) {
mLongPressState = STATE_PENDING_PARENT_INFORM;