From 7c8fb786fa529c76fc88b8b24dec2d39e225546b Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 8 Mar 2019 17:04:57 -0800 Subject: [PATCH] Use GestureDetector in WorkspaceTouchListener Replace the current callback logic in WorkspaceTouchListener with the use of GestureDetector. That means, platform api is now going to be used for detecting long press. There now are some unused variables and unneeded code in this file. It will be cleaned up in a follow-up CL. Test: long press on empty home screen Bug: 126596502 Change-Id: I57302b403f7d7118f2156166d8c707ab3f9ccefd --- .../launcher3/touch/WorkspaceTouchListener.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/touch/WorkspaceTouchListener.java b/src/com/android/launcher3/touch/WorkspaceTouchListener.java index 4de082e90e..78017569e0 100644 --- a/src/com/android/launcher3/touch/WorkspaceTouchListener.java +++ b/src/com/android/launcher3/touch/WorkspaceTouchListener.java @@ -29,6 +29,7 @@ import android.graphics.Rect; import android.view.HapticFeedbackConstants; import android.view.MotionEvent; import android.view.View; +import android.view.GestureDetector; import android.view.View.OnTouchListener; import android.view.ViewConfiguration; @@ -45,7 +46,7 @@ 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); @@ -155,12 +160,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;