aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-28 10:19:18 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-28 10:19:18 -0700
commit2ca4046cd93f8a4385a2d9925fef20a407946543 (patch)
treed91d2b29dfb0b291311800537b5f2295402d4020 /src
parent3e2998185b9cdd9c5cf4a87ce5b3bea866b89a55 (diff)
downloaddsub-2ca4046cd93f8a4385a2d9925fef20a407946543.tar.gz
dsub-2ca4046cd93f8a4385a2d9925fef20a407946543.tar.bz2
dsub-2ca4046cd93f8a4385a2d9925fef20a407946543.zip
Fix for recycling old transition drawable
The old implementation only kept current + 1 old drawable. While this reduced the number of cases where the old drawable was attempted to be used, it did not completely eliminate it. There were still cases where the + 1 old drawable was used and caused a crash. This new implementation just completely clears the old transition drawable from the stack after a certain amount of time.
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/util/ImageLoader.java45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java
index dc10ebba..d42fd5b9 100644
--- a/src/github/daneren2005/dsub/util/ImageLoader.java
+++ b/src/github/daneren2005/dsub/util/ImageLoader.java
@@ -185,13 +185,13 @@ public class ImageLoader {
return coverArtId + size;
}
- private void setImage(View view, Drawable drawable, boolean crossfade) {
+ private void setImage(View view, final Drawable drawable, boolean crossfade) {
if (view instanceof TextView) {
// Cross-fading is not implemented for TextView since it's not in use. It would be easy to add it, though.
TextView textView = (TextView) view;
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
} else if (view instanceof ImageView) {
- ImageView imageView = (ImageView) view;
+ final ImageView imageView = (ImageView) view;
if (crossfade) {
Drawable existingDrawable = imageView.getDrawable();
if (existingDrawable == null) {
@@ -202,27 +202,30 @@ public class ImageLoader {
emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault, Bitmap.Config.ARGB_8888);
}
existingDrawable = new BitmapDrawable(context.getResources(), emptyImage);
- } else {
- // Try to get rid of old transitions
- try {
- TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
- int layers = tmp.getNumberOfLayers();
- existingDrawable = tmp.getDrawable(layers - 1);
- } catch(Exception e) {
- // 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);
- return;
+ } else if(existingDrawable instanceof TransitionDrawable) {
+ // This should only ever be used if user is skipping through many songs quickly
+ TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
+ exisitingDrawable = tmp.getDrawable(tmp.getNumberOfLayers() - 1);
}
+
+ Drawable[] layers = new Drawable[] {existingDrawable, drawable};
+ final TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
+ imageView.setImageDrawable(transitionDrawable);
+ transitionDrawable.startTransition(250);
+
+ // Get rid of transition drawable after transition occurs
+ imageView.getHandler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ // Only execute if still on same transition drawable
+ if(imageView.getDrawable() == transitionDrawable) {
+ imageView.setImageDrawable(drawable);
+ }
+ }
+ }, 500L);
+ } else {
+ imageView.setImageDrawable(drawable);
}
- imageView.setImageDrawable(drawable);
}
}