From 02dd7aea3d8ac94126a8f8069e6762592ea60326 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Tue, 15 Apr 2014 15:23:31 -0400 Subject: Fix long press after already moving off icon When an icon is in the Hotseat and a user drags off from the icon, but continues holding down, the icon gets a long press triggered by the CheckLongPressHelper. To fix this a check has been added on move events to see if the point has moved outside the view and to cancel the long press check callback if it has. Bug: 13569451 Change-Id: Id175cdc220d70b5e9f8e492ed5a3cc7c3f11db10 --- src/com/android/launcher3/BubbleTextView.java | 9 +++++++++ src/com/android/launcher3/FolderIcon.java | 16 +++++++++++++++- .../android/launcher3/LauncherAppWidgetHostView.java | 19 +++++++++++++++++++ src/com/android/launcher3/Utilities.java | 11 +++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) (limited to 'src/com') diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index c180d3227..95300c133 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -28,6 +28,7 @@ import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; import android.view.MotionEvent; +import android.view.ViewConfiguration; import android.widget.TextView; /** @@ -60,6 +61,8 @@ public class BubbleTextView extends TextView { private int mPressedOutlineColor; private int mPressedGlowColor; + private float mSlop; + private int mTextColor; private boolean mShadowsEnabled = true; private boolean mIsTextVisible; @@ -272,6 +275,11 @@ public class BubbleTextView extends TextView { mLongPressHelper.cancelLongPress(); break; + case MotionEvent.ACTION_MOVE: + if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) { + mLongPressHelper.cancelLongPress(); + } + break; } return result; } @@ -356,6 +364,7 @@ public class BubbleTextView extends TextView { protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mBackground != null) mBackground.setCallback(this); + mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); } @Override diff --git a/src/com/android/launcher3/FolderIcon.java b/src/com/android/launcher3/FolderIcon.java index 71a746138..25c496288 100644 --- a/src/com/android/launcher3/FolderIcon.java +++ b/src/com/android/launcher3/FolderIcon.java @@ -33,6 +33,7 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; @@ -105,6 +106,8 @@ public class FolderIcon extends FrameLayout implements FolderListener { boolean mAnimating = false; private Rect mOldBounds = new Rect(); + private float mSlop; + private PreviewItemDrawingParams mParams = new PreviewItemDrawingParams(0, 0, 0, 0); private PreviewItemDrawingParams mAnimParams = new PreviewItemDrawingParams(0, 0, 0, 0); private ArrayList mHiddenItems = new ArrayList(); @@ -386,7 +389,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { public void performDestroyAnimation(final View finalView, Runnable onCompleteRunnable) { Drawable animateDrawable = ((TextView) finalView).getCompoundDrawables()[1]; - computePreviewDrawingParams(animateDrawable.getIntrinsicWidth(), + computePreviewDrawingParams(animateDrawable.getIntrinsicWidth(), finalView.getMeasuredWidth()); // This will animate the first item from it's position as an icon into its @@ -703,10 +706,21 @@ public class FolderIcon extends FrameLayout implements FolderListener { case MotionEvent.ACTION_UP: mLongPressHelper.cancelLongPress(); break; + case MotionEvent.ACTION_MOVE: + if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) { + mLongPressHelper.cancelLongPress(); + } + break; } return result; } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); + } + @Override public void cancelLongPress() { super.cancelLongPress(); diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java index 51a649a07..f47fd13ec 100644 --- a/src/com/android/launcher3/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java @@ -21,6 +21,7 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.RemoteViews; @@ -36,6 +37,8 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc private int mPreviousOrientation; private DragLayer mDragLayer; + private float mSlop; + public LauncherAppWidgetHostView(Context context) { super(context); mContext = context; @@ -90,6 +93,11 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc case MotionEvent.ACTION_CANCEL: mLongPressHelper.cancelLongPress(); break; + case MotionEvent.ACTION_MOVE: + if (!Utilities.pointInView(this, ev.getX(), ev.getY(), mSlop)) { + mLongPressHelper.cancelLongPress(); + } + break; } // Otherwise continue letting touch events fall through to children @@ -104,10 +112,21 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc case MotionEvent.ACTION_CANCEL: mLongPressHelper.cancelLongPress(); break; + case MotionEvent.ACTION_MOVE: + if (!Utilities.pointInView(this, ev.getX(), ev.getY(), mSlop)) { + mLongPressHelper.cancelLongPress(); + } + break; } return false; } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); + } + @Override public void cancelLongPress() { super.cancelLongPress(); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index cbc978585..8deadf1d9 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -305,6 +305,17 @@ public final class Utilities { return scale; } + /** + * Utility method to determine whether the given point, in local coordinates, + * is inside the view, where the area of the view is expanded by the slop factor. + * This method is called while processing touch-move events to determine if the event + * is still within the view. + */ + public static boolean pointInView(View v, float localX, float localY, float slop) { + return localX >= -slop && localY >= -slop && localX < (v.getWidth() + slop) && + localY < (v.getHeight() + slop); + } + private static void initStatics(Context context) { final Resources resources = context.getResources(); final DisplayMetrics metrics = resources.getDisplayMetrics(); -- cgit v1.2.3