diff --git a/src/org/kreed/vanilla/CoverView.java b/src/org/kreed/vanilla/CoverView.java index 7f2849f1..65ca73a6 100644 --- a/src/org/kreed/vanilla/CoverView.java +++ b/src/org/kreed/vanilla/CoverView.java @@ -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;