From af57cc541d24bd7bfa792e1ea75f343be4f0ffb4 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 30 Nov 2013 10:42:28 -0800 Subject: Fix #197 RemoteControlClient recycles bitmaps on it's own --- src/github/daneren2005/dsub/util/ImageLoader.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java index 42143d3a..9e9875aa 100644 --- a/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/src/github/daneren2005/dsub/util/ImageLoader.java @@ -25,6 +25,7 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.media.RemoteControlClient; +import android.os.Build; import android.os.Handler; import android.util.DisplayMetrics; import android.util.Log; @@ -75,7 +76,7 @@ public class ImageLoader implements Runnable { protected void entryRemoved(boolean evicted, String key, Bitmap oldBitmap, Bitmap newBitmap) { if(evicted) { if(oldBitmap != nowPlaying) { - // oldBitmap.recycle(); + oldBitmap.recycle(); } else { cache.put(key, oldBitmap); } @@ -131,8 +132,9 @@ public class ImageLoader implements Runnable { } public void loadImage(Context context, RemoteControlClient remoteControl, MusicDirectory.Entry entry) { - if (largeUnknownImage != null && ((BitmapDrawable)largeUnknownImage).getBitmap().isRecycled()) - createLargeUnknownImage(context); + if (largeUnknownImage != null && ((BitmapDrawable)largeUnknownImage).getBitmap().isRecycled()) { + createLargeUnknownImage(context); + } if (entry == null || entry.getCoverArt() == null) { setUnknownImage(remoteControl); @@ -199,13 +201,16 @@ public class ImageLoader implements Runnable { private void setImage(RemoteControlClient remoteControl, Drawable drawable) { if(remoteControl != null && drawable != null) { Bitmap origBitmap = ((BitmapDrawable)drawable).getBitmap(); + if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { + origBitmap = origBitmap.copy(origBitmap.getConfig(), false); + } if ( origBitmap != null && !origBitmap.isRecycled()) { remoteControl.editMetadata(false).putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, origBitmap).apply(); } else { Log.e(TAG, "Tried to load a recycled bitmap."); remoteControl.editMetadata(false) - .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null) - .apply(); + .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null) + .apply(); } } } -- cgit v1.2.3