Handle CoverView long-presses better.
This treats them the same way as normal presses: they can be activated with up to a small amount of movement. Also executes scroll-reset code even when a press is detected. Before small movements were not being reset.
This commit is contained in:
parent
0303cfb08f
commit
09cf5a8930
@ -222,9 +222,8 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
mVelocityTracker = VelocityTracker.obtain();
|
||||
mVelocityTracker.addMovement(ev);
|
||||
|
||||
mHandler.removeMessages(MSG_LONG_CLICK);
|
||||
|
||||
float x = ev.getX();
|
||||
float y = ev.getY();
|
||||
int scrollX = getScrollX();
|
||||
int width = getWidth();
|
||||
|
||||
@ -234,12 +233,12 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
mScroller.abortAnimation();
|
||||
|
||||
mStartX = x;
|
||||
mStartY = ev.getY();
|
||||
mStartY = y;
|
||||
mLastMotionX = x;
|
||||
|
||||
mHandler.sendEmptyMessageDelayed(MSG_LONG_CLICK, ViewConfiguration.getLongPressTimeout());
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
case MotionEvent.ACTION_MOVE: {
|
||||
int deltaX = (int) (mLastMotionX - x);
|
||||
mLastMotionX = x;
|
||||
|
||||
@ -252,16 +251,22 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
if (availableToScroll > 0)
|
||||
scrollBy(Math.min(availableToScroll, deltaX), 0);
|
||||
}
|
||||
|
||||
if (Math.abs(mStartX - x) + Math.abs(mStartY - y) < 10)
|
||||
mHandler.removeMessages(MSG_LONG_CLICK);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (Math.abs(mStartX - x) + Math.abs(mStartY - ev.getY()) < 10) {
|
||||
}
|
||||
case MotionEvent.ACTION_UP: {
|
||||
mHandler.removeMessages(MSG_LONG_CLICK);
|
||||
if (Math.abs(mStartX - x) + Math.abs(mStartY - y) < 10) {
|
||||
// A long press was performed and thus the normal action should
|
||||
// not be executed.
|
||||
if (mIgnoreNextUp)
|
||||
mIgnoreNextUp = false;
|
||||
else
|
||||
performClick();
|
||||
} else {
|
||||
}
|
||||
|
||||
VelocityTracker velocityTracker = mVelocityTracker;
|
||||
velocityTracker.computeCurrentVelocity(250);
|
||||
int velocity = (int) velocityTracker.getXVelocity();
|
||||
@ -283,7 +288,6 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
mTentativeCover = whichCover;
|
||||
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
if (mVelocityTracker != null) {
|
||||
mVelocityTracker.recycle();
|
||||
@ -292,6 +296,7 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user