aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-07-22 16:13:07 -0700
committerdaneren2005 <daneren2005@gmail.com>2013-07-22 16:13:07 -0700
commit9eced048e8f5d7eadc0901575a4d3a5867ce8cf8 (patch)
tree8d40fb0a737ff1a4df6aae24bddde1a93726f8e8
parent117ad219919c50a13d1ff558c5e5c27ad55f405a (diff)
parent5a668ae60367ceccd452d37699842c1e3386f1be (diff)
downloaddsub-9eced048e8f5d7eadc0901575a4d3a5867ce8cf8.tar.gz
dsub-9eced048e8f5d7eadc0901575a4d3a5867ce8cf8.tar.bz2
dsub-9eced048e8f5d7eadc0901575a4d3a5867ce8cf8.zip
Merge pull request #151 from FennyFatal/master
Fix for recycled images in Android 4.3
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/receiver/MediaButtonIntentReceiver.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java56
2 files changed, 39 insertions, 21 deletions
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.
}
+ }
}
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java
index f84116f7..331bc629 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java
@@ -101,14 +101,17 @@ 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;
}
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) {
@@ -116,21 +119,24 @@ 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;
}
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,28 +178,38 @@ 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;
}
}
-
- 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 {
+ Log.e(TAG, "Tried to load a recycled bitmap.");
+ remoteControl.editMetadata(false)
+ .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null)
+ .apply();
+ }
+ }
+ }
private void setUnknownImage(View view, boolean large) {
if (large) {