Improve long press touch feedback
If the user moves their finger, cancel any pending long press checks
This was showing as a bug in which sometimes scrolling would "long press"
and item
Change-Id: I44059cf9d525c61569d2643dc7f24984ccf31797
diff --git a/res/values/dimen.xml b/res/values/dimen.xml
index 1a9828c..9ba1f46 100644
--- a/res/values/dimen.xml
+++ b/res/values/dimen.xml
@@ -40,6 +40,7 @@
<dimen name="date_background_height">17sp</dimen>
<dimen name="date_background_padding_left">4dip</dimen>
<dimen name="touch_slop">16dip</dimen>
+ <dimen name="move_slop">4dip</dimen>
<dimen name="standard_scaled_dimen">100sp</dimen>
<dimen name="folder_cell_width">8dip</dimen>
<dimen name="triangle_width">15dip</dimen>
diff --git a/src/com/android/mail/browse/ConversationItemView.java b/src/com/android/mail/browse/ConversationItemView.java
index 4a063e5..d237dac 100644
--- a/src/com/android/mail/browse/ConversationItemView.java
+++ b/src/com/android/mail/browse/ConversationItemView.java
@@ -121,6 +121,7 @@
private static int sDateTextColor;
private static int sDateBackgroundPaddingLeft;
private static int sTouchSlop;
+ private static int sMoveSlop;
private static int sDateBackgroundHeight;
private static int sStandardScaledDimen;
private static int sShrinkAnimationDuration;
@@ -376,6 +377,7 @@
sDateBackgroundPaddingLeft = res
.getDimensionPixelSize(R.dimen.date_background_padding_left);
sTouchSlop = res.getDimensionPixelSize(R.dimen.touch_slop);
+ sMoveSlop = res.getDimensionPixelSize(R.dimen.move_slop);
sDateBackgroundHeight = res.getDimensionPixelSize(R.dimen.date_background_height);
sStandardScaledDimen = res.getDimensionPixelSize(R.dimen.standard_scaled_dimen);
sShrinkAnimationDuration = res.getInteger(R.integer.shrink_animation_duration);
@@ -1229,16 +1231,26 @@
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
- int x = mLastTouchX = (int) event.getX();
- int y = mLastTouchY = (int) event.getY();
+ int x = (int) event.getX();
+ int y = (int) event.getY();
if (!mSwipeEnabled) {
return onTouchEventNoSwipe(event);
}
boolean handled = true;
switch (event.getAction()) {
+ case MotionEvent.ACTION_MOVE:
+ // If we move > slop, cancel the long press event.
+ if (Math.abs(mLastTouchX - x) > sMoveSlop
+ || Math.abs(mLastTouchY - y) > sMoveSlop) {
+ cancelTap();
+ resetDownEvent();
+ }
+ break;
case MotionEvent.ACTION_DOWN:
mDownEvent = true;
+ mLastTouchX = x;
+ mLastTouchY = y;
// This checks for long press. The actual tap is handled on "up".
checkForLongPress();
// In order to allow the down event and subsequent move events
@@ -1247,6 +1259,7 @@
handled = true;
break;
case MotionEvent.ACTION_CANCEL:
+ resetDownEvent();
mDownEvent = false;
setPressed(false);
break;
@@ -1280,13 +1293,19 @@
// therefore it cannot handle it.
handled = false;
}
+ resetDownEvent();
break;
}
-
// Let View try to handle it as well.
return handled || super.onTouchEvent(event);
}
+ private void resetDownEvent() {
+ mDownEvent = true;
+ mLastTouchX = -1;
+ mLastTouchY = -1;
+ }
+
private ListView getListView() {
return ((SwipeableConversationItemView) getParent()).getListView();
}
diff --git a/src/com/android/mail/ui/AnimatedAdapter.java b/src/com/android/mail/ui/AnimatedAdapter.java
index b0935e1..780b4d5 100644
--- a/src/com/android/mail/ui/AnimatedAdapter.java
+++ b/src/com/android/mail/ui/AnimatedAdapter.java
@@ -60,7 +60,7 @@
private final HashSet<Integer> mSwipeUndoingItems = new HashSet<Integer>();
private final HashMap<Long, SwipeableConversationItemView> mAnimatingViews =
new HashMap<Long, SwipeableConversationItemView>();
- private HashMap<Long, LeaveBehindItem> mFadeLeaveBehindItems =
+ private final HashMap<Long, LeaveBehindItem> mFadeLeaveBehindItems =
new HashMap<Long, LeaveBehindItem>();
/** The current account */
private final Account mAccount;
@@ -616,7 +616,7 @@
public boolean isAnimating() {
return !mUndoingItems.isEmpty()
|| !mSwipeUndoingItems.isEmpty()
- || !mFadeLeaveBehindItems.isEmpty()
+ || hasFadeLeaveBehinds()
|| !mDeletingItems.isEmpty()
|| !mSwipeDeletingItems.isEmpty();
}