From d80ebdfd9fcd306b0465296d05f69c0b4ceced1e Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Mon, 31 Oct 2016 11:57:16 -0700 Subject: [PATCH] Intercept touches in DeepShortcutContainer after moving beyond touch slop Otherwise it's possible for a long press to trigger when swiping on a shortcut, which causes it to drag far away from the finger. Bug: 32309824 Change-Id: I40bd5c1daac49d6edb59744083a1e23dcf4f0ce6 --- .../shortcuts/DeepShortcutsContainer.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java index 2f9c6d6807..08ca2429f4 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java @@ -28,6 +28,7 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Point; +import android.graphics.PointF; import android.graphics.Rect; import android.graphics.drawable.ShapeDrawable; import android.os.Build; @@ -38,6 +39,7 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.accessibility.AccessibilityEvent; import android.view.animation.DecelerateInterpolator; import android.widget.LinearLayout; @@ -89,6 +91,7 @@ public class DeepShortcutsContainer extends AbstractFloatingView private BubbleTextView mOriginalIcon; private final Rect mTempRect = new Rect(); + private PointF mInterceptTouchDown = new PointF(); private Point mIconLastTouchPos = new Point(); private boolean mIsLeftAligned; private boolean mIsAboveIcon; @@ -413,6 +416,17 @@ public class DeepShortcutsContainer extends AbstractFloatingView }; } + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + if (ev.getAction() == MotionEvent.ACTION_DOWN) { + mInterceptTouchDown.set(ev.getX(), ev.getY()); + return false; + } + // Stop sending touch events to deep shortcut views if user moved beyond touch slop. + return Math.hypot(mInterceptTouchDown.x - ev.getX(), mInterceptTouchDown.y - ev.getY()) + > ViewConfiguration.get(getContext()).getScaledTouchSlop(); + } + /** * We need to handle touch events to prevent them from falling through to the workspace below. */