Cache the covers retrieved with getCover
This commit is contained in:
parent
435de332b8
commit
f6298a07c3
@ -162,11 +162,8 @@ public final class CoverBitmap {
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
|
||||
if (cover != null) {
|
||||
if (cover != null)
|
||||
canvas.drawBitmap(cover, null, new Rect(0, 0, width, height), paint);
|
||||
cover.recycle();
|
||||
cover = null;
|
||||
}
|
||||
|
||||
int left = 0;
|
||||
int top = height - boxHeight;
|
||||
@ -269,8 +266,6 @@ public final class CoverBitmap {
|
||||
if (cover != null) {
|
||||
Rect rect = new Rect(0, 0, bitmapWidth, bitmapHeight);
|
||||
canvas.drawBitmap(cover, null, rect, paint);
|
||||
cover.recycle();
|
||||
cover = null;
|
||||
}
|
||||
|
||||
int left = (bitmapWidth - boxWidth) / 2;
|
||||
@ -386,8 +381,6 @@ public final class CoverBitmap {
|
||||
if (cover != null) {
|
||||
RectF rect = new RectF(0, 0, coverWidth, coverHeight);
|
||||
canvas.drawBitmap(cover, null, rect, paint);
|
||||
cover.recycle();
|
||||
cover = null;
|
||||
}
|
||||
|
||||
int top;
|
||||
|
@ -45,6 +45,11 @@ public class Song implements Parcelable {
|
||||
*/
|
||||
public static final int FLAG_RANDOM = 0x1;
|
||||
|
||||
/**
|
||||
* A cache of covers that have been loaded with getCover().
|
||||
*/
|
||||
private static final Cache<Bitmap> mCoverCache = new Cache<Bitmap>(10);
|
||||
|
||||
private static final String[] FILLED_PROJECTION = {
|
||||
MediaStore.Audio.Media._ID,
|
||||
MediaStore.Audio.Media.DATA,
|
||||
@ -247,12 +252,15 @@ public class Song implements Parcelable {
|
||||
if (id == -1)
|
||||
return null;
|
||||
|
||||
// Query the cache for the cover
|
||||
Bitmap cover = mCoverCache.get(id);
|
||||
if (cover != null)
|
||||
return cover;
|
||||
|
||||
Context context = ContextApplication.getContext();
|
||||
ContentResolver res = context.getContentResolver();
|
||||
|
||||
Bitmap cover;
|
||||
|
||||
// Query the MediaStore content provider first
|
||||
// Query the MediaStore content provider
|
||||
cover = getCoverFromMediaFile(res);
|
||||
|
||||
// If that fails, try using MediaScanner directly
|
||||
@ -263,6 +271,10 @@ public class Song implements Parcelable {
|
||||
if (cover == null)
|
||||
cover = getCoverFromMediaStoreCache(res);
|
||||
|
||||
Bitmap deletedCover = mCoverCache.put(id, cover);
|
||||
if (deletedCover != null)
|
||||
deletedCover.recycle();
|
||||
|
||||
return cover;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user