Add distance threshold for dragged items before accepted by targets.
am: 855b1b5
* commit '855b1b5fff5f6f03a641b3b6973780a24fd9641e':
Add distance threshold for dragged items before accepted by targets.
Change-Id: I99830fd378138599c8e8091ac21d0780e04de424
This commit is contained in:
@@ -123,6 +123,9 @@
|
||||
<dimen name="drop_target_drag_padding">14dp</dimen>
|
||||
<dimen name="drop_target_text_size">14sp</dimen>
|
||||
|
||||
<!-- the distance an icon must be dragged before button drop targets accept it -->
|
||||
<dimen name="drag_distanceThreshold">30dp</dimen>
|
||||
|
||||
<!-- the area at the edge of the screen that makes the workspace go left
|
||||
or right while you're dragging. -->
|
||||
<dimen name="scroll_zone">20dp</dimen>
|
||||
|
||||
@@ -24,13 +24,13 @@ import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -62,6 +62,8 @@ public abstract class ButtonDropTarget extends TextView
|
||||
|
||||
/** Whether this drop target is active for the current drag */
|
||||
protected boolean mActive;
|
||||
/** An item must be dragged at least this many pixels before this drop target is enabled. */
|
||||
private final int mDragDistanceThreshold;
|
||||
|
||||
/** The paint applied to the drag view on hover */
|
||||
protected int mHoverColor = 0;
|
||||
@@ -78,12 +80,14 @@ public abstract class ButtonDropTarget extends TextView
|
||||
|
||||
public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mBottomDragPadding = getResources().getDimensionPixelSize(R.dimen.drop_target_drag_padding);
|
||||
Resources resources = getResources();
|
||||
mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.ButtonDropTarget, defStyle, 0);
|
||||
mHideParentOnDisable = a.getBoolean(R.styleable.ButtonDropTarget_hideParentOnDisable, false);
|
||||
a.recycle();
|
||||
mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,7 +220,8 @@ public abstract class ButtonDropTarget extends TextView
|
||||
|
||||
@Override
|
||||
public boolean isDropEnabled() {
|
||||
return mActive;
|
||||
return mActive
|
||||
&& mLauncher.getDragController().getDistanceDragged() >= mDragDistanceThreshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -276,6 +276,9 @@ public class DragController implements DragDriver.EventListener {
|
||||
|
||||
mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||
dragView.show(mMotionDownX, mMotionDownY);
|
||||
mDistanceSinceScroll = 0;
|
||||
mLastTouch[0] = mMotionDownX;
|
||||
mLastTouch[1] = mMotionDownY;
|
||||
handleMoveEvent(mMotionDownX, mMotionDownY);
|
||||
return dragView;
|
||||
}
|
||||
@@ -536,6 +539,10 @@ public class DragController implements DragDriver.EventListener {
|
||||
checkScrollState(x, y);
|
||||
}
|
||||
|
||||
public float getDistanceDragged() {
|
||||
return mDistanceSinceScroll;
|
||||
}
|
||||
|
||||
public void forceTouchMove() {
|
||||
int[] dummyCoordinates = mCoordinatesTemp;
|
||||
DropTarget dropTarget = findDropTarget(mLastTouch[0], mLastTouch[1], dummyCoordinates);
|
||||
|
||||
Reference in New Issue
Block a user