Prevent redundant cover work in CoverView
There were two main cases where we would generate covers: when querySongs is called and when onSizeChanged is called. querySongs was sometimes called before the initial layout had occured and the CoverView's size determined (usually when the service had already been running when a new PlaybackActivity is created). onSizeChanged was sometimes called before the service had been initialized. Both of these cases are not useful, and in the former case, harmful, since the default cover art could be shown when the view should have been blank. So this removes generation in onSizeChanged except when querySongs had been called before the layout occurs, which elminates the redundant cases.
This commit is contained in:
1 parent
1ae2958041
commit
2149745f52
1 file changed
+15
-25
@@ -93,6 +93,12 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
*/
|
||||
private boolean mIgnoreNextUp;
|
||||
|
||||
/**
|
||||
* If true, querySongs was called before the view initialized and should
|
||||
* be called when initialization finishes.
|
||||
*/
|
||||
private boolean mPendingQuery;
|
||||
|
||||
/**
|
||||
* Constructor intended to be called by inflating from XML.
|
||||
*/
|
||||
@@ -157,34 +163,13 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recreate all the necessary cached bitmaps.
|
||||
*/
|
||||
private void regenerateBitmaps()
|
||||
{
|
||||
Object[] bitmaps = mBitmapCache.clear();
|
||||
for (int i = bitmaps.length; --i != -1; ) {
|
||||
if (bitmaps[i] != null)
|
||||
((Bitmap)bitmaps[i]).recycle();
|
||||
bitmaps[i] = null;
|
||||
}
|
||||
mDefaultCover = null;
|
||||
for (int i = 3; --i != -1; )
|
||||
setSong(i, mSongs[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recreate the cover art views and reset the scroll position whenever the
|
||||
* size of this view changes.
|
||||
*/
|
||||
@Override
|
||||
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
|
||||
{
|
||||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
regenerateBitmaps();
|
||||
resetScroll();
|
||||
if (mPendingQuery && width != 0 && height != 0) {
|
||||
mPendingQuery = false;
|
||||
querySongs(PlaybackService.get(getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,6 +379,11 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
*/
|
||||
public void querySongs(PlaybackService service)
|
||||
{
|
||||
if (getWidth() == 0 || getHeight() == 0) {
|
||||
mPendingQuery = true;
|
||||
return;
|
||||
}
|
||||
|
||||
mHandler.removeMessages(MSG_GENERATE_BITMAP);
|
||||
setSong(1, service.getSong(0));
|
||||
setSong(2, service.getSong(1));
|
||||
|
||||
Reference in new issue
Block a user