Merge "Fix long press after already moving off icon" into ub-now-nova

This commit is contained in:
Jason Monk
2014-04-23 18:55:47 +00:00
committed by Android (Google) Code Review
4 changed files with 54 additions and 1 deletions
@@ -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
+15 -1
View File
@@ -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<ShortcutInfo> mHiddenItems = new ArrayList<ShortcutInfo>();
@@ -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();
@@ -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();
+11
View File
@@ -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();