diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-11-09 17:35:11 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-11-09 17:35:11 -0800 |
commit | d396e0120e6d8a910e2e36e80c2656c83b80d745 (patch) | |
tree | d0445ec63f0dcf7df2c81946eaa1cb9a8f899838 /app/src/main/java/github/daneren2005/dsub/view | |
parent | ae77659307ef8b9dfadf2eb3dae0e406ddae7903 (diff) | |
download | dsub-d396e0120e6d8a910e2e36e80c2656c83b80d745.tar.gz dsub-d396e0120e6d8a910e2e36e80c2656c83b80d745.tar.bz2 dsub-d396e0120e6d8a910e2e36e80c2656c83b80d745.zip |
#296 Improve low memory handling
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/view')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/view/RecyclingImageView.java | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/view/RecyclingImageView.java b/app/src/main/java/github/daneren2005/dsub/view/RecyclingImageView.java index a7208cee..501b363d 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/RecyclingImageView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/RecyclingImageView.java @@ -28,6 +28,7 @@ import android.widget.ImageView; public class RecyclingImageView extends ImageView { private boolean invalidated = false; + private OnInvalidated onInvalidated; public RecyclingImageView(Context context) { super(context); @@ -53,7 +54,7 @@ public class RecyclingImageView extends ImageView { if(drawable instanceof BitmapDrawable) { if (isBitmapRecycled(drawable)) { this.setImageDrawable(null); - invalidated = true; + setInvalidated(true); } } else if(drawable instanceof TransitionDrawable) { TransitionDrawable transitionDrawable = (TransitionDrawable) drawable; @@ -62,7 +63,7 @@ public class RecyclingImageView extends ImageView { Drawable lastDrawable = transitionDrawable.getDrawable(transitionDrawable.getNumberOfLayers() - 1); if(isBitmapRecycled(lastDrawable)) { this.setImageDrawable(null); - invalidated = true; + setInvalidated(true); } else { // Go through earlier bitmaps and make sure that they are not recycled for (int i = 0; i < transitionDrawable.getNumberOfLayers(); i++) { @@ -83,7 +84,7 @@ public class RecyclingImageView extends ImageView { @Override public void setImageDrawable(Drawable drawable) { super.setImageDrawable(drawable); - invalidated = false; + setInvalidated(false); } private boolean isBitmapRecycled(Drawable drawable) { @@ -99,7 +100,22 @@ public class RecyclingImageView extends ImageView { } } + public void setInvalidated(boolean invalidated) { + this.invalidated = invalidated; + + if(invalidated && onInvalidated != null) { + onInvalidated.onInvalidated(this); + } + } public boolean isInvalidated() { return invalidated; } + + public void setOnInvalidated(OnInvalidated onInvalidated) { + this.onInvalidated = onInvalidated; + } + + public interface OnInvalidated { + void onInvalidated(RecyclingImageView imageView); + } } |