From 392b54035b8e6cbd780a7e1b67f9cf4baa3b5302 Mon Sep 17 00:00:00 2001 From: Fenny Fatal Date: Sun, 21 Jul 2013 21:20:16 -0600 Subject: Bandaid Fix so we don't crash on android 4.3. --- .../github/daneren2005/dsub/util/ImageLoader.java | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java index f84116f7..782d74d6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java @@ -183,17 +183,23 @@ public class ImageLoader implements Runnable { } } } - - private void setImage(RemoteControlClient remoteControl, Drawable drawable) { - if(remoteControl != null && drawable != null) { - Bitmap origBitmap = ((BitmapDrawable)drawable).getBitmap(); - remoteControl.editMetadata(false) - .putBitmap( - RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, - origBitmap) - .apply(); - } - } + + private void setImage(RemoteControlClient remoteControl, Drawable drawable) { + if(remoteControl != null && drawable != null) { + Bitmap origBitmap = ((BitmapDrawable)drawable).getBitmap(); + if ( origBitmap != null && !origBitmap.isRecycled()) { + remoteControl.editMetadata(false) + .putBitmap( + RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, + origBitmap) + .apply(); + } else { + remoteControl.editMetadata(true) + .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null) + .apply(); + } + } + } private void setUnknownImage(View view, boolean large) { if (large) { -- cgit v1.2.3 From 9235964fe5267ccbfbf2149b902e7c619fec491b Mon Sep 17 00:00:00 2001 From: Fenny Fatal Date: Sun, 21 Jul 2013 21:59:28 -0600 Subject: Make Media button events less spammy in logcat. --- .../github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java b/subsonic-android/src/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java index 9796971f..9ea04474 100644 --- a/subsonic-android/src/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java +++ b/subsonic-android/src/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java @@ -40,11 +40,13 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver { Intent serviceIntent = new Intent(context, DownloadServiceImpl.class); serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event); context.startService(serviceIntent); - + if (isOrderedBroadcast()) + { try { abortBroadcast(); } catch (Exception x) { // Ignored. } + } } } -- cgit v1.2.3 From adbfbc61b33e9e1b505f7a05b844af1c1d078b20 Mon Sep 17 00:00:00 2001 From: Fenny Fatal Date: Mon, 22 Jul 2013 01:47:34 -0600 Subject: Okay, now we load all images if they have been recycled. We also check for a recycled current image if we are trying to transition. No more CRASHES on 4.3 --- .../src/github/daneren2005/dsub/util/ImageLoader.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java index 782d74d6..1fb5f083 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java @@ -108,7 +108,7 @@ public class ImageLoader implements Runnable { int size = large ? imageSizeLarge : imageSizeDefault; Bitmap bitmap = cache.get(getKey(entry.getCoverArt(), size)); - if (bitmap != null) { + if (bitmap != null && !bitmap.isRecycled()) { final Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap); setImage(view, drawable, large); if(large) { @@ -130,7 +130,7 @@ public class ImageLoader implements Runnable { } Bitmap bitmap = cache.get(getKey(entry.getCoverArt(), imageSizeLarge)); - if (bitmap != null) { + if (bitmap != null && !bitmap.isRecycled()) { Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap); setImage(remoteControl, drawable); return; @@ -172,15 +172,18 @@ public class ImageLoader implements Runnable { // Do nothing, just means that the drawable is a flat image } } - + if (!(((BitmapDrawable)existingDrawable).getBitmap().isRecycled())) + { // We will flow through to the non-transition if the old image is recycled... Yay 4.3 Drawable[] layers = new Drawable[]{existingDrawable, drawable}; TransitionDrawable transitionDrawable = new TransitionDrawable(layers); imageView.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(250); - } else { - imageView.setImageDrawable(drawable); + return; + } } + imageView.setImageDrawable(drawable); + return; } } @@ -194,7 +197,8 @@ public class ImageLoader implements Runnable { origBitmap) .apply(); } else { - remoteControl.editMetadata(true) + Log.e(TAG, "Tried to load a recycled bitmap."); + remoteControl.editMetadata(false) .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null) .apply(); } -- cgit v1.2.3 From 5a668ae60367ceccd452d37699842c1e3386f1be Mon Sep 17 00:00:00 2001 From: Fenny Fatal Date: Mon, 22 Jul 2013 16:00:36 -0600 Subject: Additional case where the album art is unknown. It must be reloaded from resources as well, because it's getting recycled by the new more invasive Android GC. --- .../src/github/daneren2005/dsub/util/ImageLoader.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java index 1fb5f083..331bc629 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java @@ -101,7 +101,10 @@ public class ImageLoader implements Runnable { } public void loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) { - if (entry == null || entry.getCoverArt() == null) { + if (largeUnknownImage != null && ((BitmapDrawable)largeUnknownImage).getBitmap().isRecycled()) + createLargeUnknownImage(view.getContext()); + + if (entry == null || entry.getCoverArt() == null) { setUnknownImage(view, large); return; } @@ -116,15 +119,18 @@ public class ImageLoader implements Runnable { } return; } - - if (!large) { + + if (!large) { setUnknownImage(view, large); } queue.offer(new Task(view.getContext(), entry, size, imageSizeLarge, large, new ViewTaskHandler(view, crossfade))); } public void loadImage(Context context, RemoteControlClient remoteControl, MusicDirectory.Entry entry) { - if (entry == null || entry.getCoverArt() == null) { + if (largeUnknownImage != null && ((BitmapDrawable)largeUnknownImage).getBitmap().isRecycled()) + createLargeUnknownImage(context); + + if (entry == null || entry.getCoverArt() == null) { setUnknownImage(remoteControl); return; } -- cgit v1.2.3