From ec9449a227b85cf31b8e5e07ae0622875d70e427 Mon Sep 17 00:00:00 2001 From: Christopher Eby Date: Tue, 13 Mar 2012 14:44:12 -0500 Subject: [PATCH] Prevent cover when art from changing when scroll is in progress The previous/next song can change while scrolling if shuffling is enabled. This saves those songs in mActiveBitmaps until scrolling is finished. This doesn't handle two successive scrolls (i.e. no time to settle) with changes, though. --- src/org/kreed/vanilla/CoverView.java | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/org/kreed/vanilla/CoverView.java b/src/org/kreed/vanilla/CoverView.java index b732c7f3..e70aa3db 100644 --- a/src/org/kreed/vanilla/CoverView.java +++ b/src/org/kreed/vanilla/CoverView.java @@ -96,6 +96,10 @@ public final class CoverView extends View implements Handler.Callback { * The covers for the current songs: 0 = previous, 1 = current, and 2 = next. */ private Bitmap[] mBitmaps = new Bitmap[3]; + /** + * The bitmaps to be drawn. Usually the same as mBitmaps, unless scrolling. + */ + private Bitmap[] mActiveBitmaps = mBitmaps; /** * Cover art to use when a song has no cover art in no info display styles. */ @@ -140,6 +144,11 @@ public final class CoverView extends View implements Handler.Callback { * its features are not required. */ private int mScrollX; + /** + * True if a scroll is in progress (i.e. mScrollX != getWidth()), false + * otherwise. + */ + private boolean mScrolling; /** * Constructor intended to be called by inflating from XML. @@ -204,7 +213,7 @@ public final class CoverView extends View implements Handler.Callback { canvas.drawColor(Color.BLACK); - for (Bitmap bitmap : mBitmaps) { + for (Bitmap bitmap : mActiveBitmaps) { if (bitmap != null && scrollX + width > x && scrollX < x + width) { int xOffset = (width - bitmap.getWidth()) / 2; int yOffset = (height - bitmap.getHeight()) / 2; @@ -235,13 +244,16 @@ public final class CoverView extends View implements Handler.Callback { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: - if (!mScroller.isFinished()) + if (!mScroller.isFinished()) { mScroller.abortAnimation(); + mActiveBitmaps = mBitmaps; + } mStartX = x; mStartY = y; mLastMotionX = x; mLastMotionY = y; + mScrolling = true; mUiHandler.sendEmptyMessageDelayed(MSG_LONG_CLICK, ViewConfiguration.getLongPressTimeout()); break; @@ -311,6 +323,16 @@ public final class CoverView extends View implements Handler.Callback { if (whichCover != 0) { scrollX = scrollX - width * whichCover; + Bitmap[] bitmaps = mBitmaps; + // Save the two covers being scrolled between, so that if one + // of them changes from switching songs (which can happen when + // shuffling), the new cover doesn't pop in during the scroll. + // mActiveBitmaps is reset when the scroll is finished. + if (whichCover == 1) { + mActiveBitmaps = new Bitmap[] { bitmaps[1], bitmaps[2], null }; + } else { + mActiveBitmaps = new Bitmap[] { null, bitmaps[0], bitmaps[1] }; + } mCallback.shiftCurrentSong(whichCover); mScrollX = scrollX; } @@ -392,6 +414,8 @@ public final class CoverView extends View implements Handler.Callback { Bitmap[] newBitmaps = new Bitmap[3]; mSongs = newSongs; mBitmaps = newBitmaps; + if (!mScrolling) + mActiveBitmaps = newBitmaps; for (int i = 0; i != 3; ++i) { if (newSongs[i] == null) @@ -450,6 +474,9 @@ public final class CoverView extends View implements Handler.Callback { mScrollX = mScroller.getCurrX(); invalidate(); mUiHandler.sendEmptyMessage(MSG_SCROLL); + } else { + mScrolling = false; + mActiveBitmaps = mBitmaps; } break; default: