Make swipes harder to accidently trigger

This commit is contained in:
Christopher Eby 2011-09-26 19:45:59 -05:00
parent 7c98ba54ed
commit 4a939a4ac1

View File

@ -41,7 +41,7 @@ import android.widget.Scroller;
* generated by CoverBitmap.
*/
public final class CoverView extends View implements Handler.Callback {
private static int SNAP_VELOCITY = -1;
private static int sSnapVelocity = -1;
/**
* The Handler with which to do background work. Will be null until
@ -93,8 +93,8 @@ public final class CoverView extends View implements Handler.Callback {
mScroller = new Scroller(context);
if (SNAP_VELOCITY == -1)
SNAP_VELOCITY = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();
if (sSnapVelocity == -1)
sSnapVelocity = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();
}
/**
@ -236,21 +236,15 @@ public final class CoverView extends View implements Handler.Callback {
VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(250);
int velocity = (int) velocityTracker.getXVelocity();
int velocityX = (int) velocityTracker.getXVelocity();
int velocityY = (int) velocityTracker.getYVelocity();
int min = mSongs[0] == null ? 1 : 0;
int max = 2;
int nearestCover = (scrollX + width / 2) / width;
int whichCover = Math.max(min, Math.min(nearestCover, max));
if (velocity > SNAP_VELOCITY)
whichCover = min;
else if (velocity < -SNAP_VELOCITY)
whichCover = max;
int whichCover = 1;
float diffX = Math.abs(mStartX - x);
float diffY = Math.abs(mStartY - y);
if (diffX + diffY < 10) {
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)
@ -258,12 +252,17 @@ public final class CoverView extends View implements Handler.Callback {
else
performClick();
whichCover = 1;
} else if (diffY > diffX) {
if (mStartY - y > 0)
mCallback.upSwipe();
else
mCallback.downSwipe();
whichCover = 1;
} else if (velocityX > sSnapVelocity) {
whichCover = min;
} else if (velocityX < -sSnapVelocity) {
whichCover = max;
} else if (velocityY < -sSnapVelocity) {
mCallback.upSwipe();
} else if (velocityY > sSnapVelocity) {
mCallback.downSwipe();
} else {
int nearestCover = (scrollX + width / 2) / width;
whichCover = Math.max(min, Math.min(nearestCover, max));
}
int newX = whichCover * width;