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 = VelocityTracker.obtain();
|
||||||
mVelocityTracker.addMovement(ev);
|
mVelocityTracker.addMovement(ev);
|
||||||
|
|
||||||
mHandler.removeMessages(MSG_LONG_CLICK);
|
|
||||||
|
|
||||||
float x = ev.getX();
|
float x = ev.getX();
|
||||||
|
float y = ev.getY();
|
||||||
int scrollX = getScrollX();
|
int scrollX = getScrollX();
|
||||||
int width = getWidth();
|
int width = getWidth();
|
||||||
|
|
||||||
@ -234,12 +233,12 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
mScroller.abortAnimation();
|
mScroller.abortAnimation();
|
||||||
|
|
||||||
mStartX = x;
|
mStartX = x;
|
||||||
mStartY = ev.getY();
|
mStartY = y;
|
||||||
mLastMotionX = x;
|
mLastMotionX = x;
|
||||||
|
|
||||||
mHandler.sendEmptyMessageDelayed(MSG_LONG_CLICK, ViewConfiguration.getLongPressTimeout());
|
mHandler.sendEmptyMessageDelayed(MSG_LONG_CLICK, ViewConfiguration.getLongPressTimeout());
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE: {
|
||||||
int deltaX = (int) (mLastMotionX - x);
|
int deltaX = (int) (mLastMotionX - x);
|
||||||
mLastMotionX = x;
|
mLastMotionX = x;
|
||||||
|
|
||||||
@ -252,16 +251,22 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
if (availableToScroll > 0)
|
if (availableToScroll > 0)
|
||||||
scrollBy(Math.min(availableToScroll, deltaX), 0);
|
scrollBy(Math.min(availableToScroll, deltaX), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Math.abs(mStartX - x) + Math.abs(mStartY - y) < 10)
|
||||||
|
mHandler.removeMessages(MSG_LONG_CLICK);
|
||||||
break;
|
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
|
// A long press was performed and thus the normal action should
|
||||||
// not be executed.
|
// not be executed.
|
||||||
if (mIgnoreNextUp)
|
if (mIgnoreNextUp)
|
||||||
mIgnoreNextUp = false;
|
mIgnoreNextUp = false;
|
||||||
else
|
else
|
||||||
performClick();
|
performClick();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
VelocityTracker velocityTracker = mVelocityTracker;
|
VelocityTracker velocityTracker = mVelocityTracker;
|
||||||
velocityTracker.computeCurrentVelocity(250);
|
velocityTracker.computeCurrentVelocity(250);
|
||||||
int velocity = (int) velocityTracker.getXVelocity();
|
int velocity = (int) velocityTracker.getXVelocity();
|
||||||
@ -283,7 +288,6 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
mTentativeCover = whichCover;
|
mTentativeCover = whichCover;
|
||||||
|
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
}
|
|
||||||
|
|
||||||
if (mVelocityTracker != null) {
|
if (mVelocityTracker != null) {
|
||||||
mVelocityTracker.recycle();
|
mVelocityTracker.recycle();
|
||||||
@ -292,6 +296,7 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user