diff options
-rw-r--r-- | src/com/android/bitmap/drawable/BasicBitmapDrawable.java | 19 | ||||
-rw-r--r-- | src/com/android/bitmap/view/BitmapDrawableImageView.java | 13 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java index 831f410..42c4fbf 100644 --- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java @@ -135,6 +135,8 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, * Binds to the given key and start the decode process. This will first look in the cache, then * decode from the request key if not found. * + * The key being replaced will be kept in {@link #mPrevKey}. + * * All UI operations should be called from the UI thread. */ public void bind(RequestKey key) { @@ -150,11 +152,28 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, * Unbinds the current key and bitmap from the drawable. This will cause the bitmap to decrement * its ref count. * + * This will assume that you do not want to keep the unbound key in {@link #mPrevKey}. + * * All UI operations should be called from the UI thread. */ public void unbind() { + unbind(false); + } + + /** + * Unbinds the current key and bitmap from the drawable. This will cause the bitmap to decrement + * its ref count. + * + * If the temporary parameter is true, we will keep the unbound key in {@link #mPrevKey}. + * + * All UI operations should be called from the UI thread. + */ + public void unbind(boolean temporary) { Trace.beginSection("unbind"); setImage(null); + if (!temporary) { + mPrevKey = null; + } Trace.endSection(); } diff --git a/src/com/android/bitmap/view/BitmapDrawableImageView.java b/src/com/android/bitmap/view/BitmapDrawableImageView.java index 5d42b6c..e9df6d3 100644 --- a/src/com/android/bitmap/view/BitmapDrawableImageView.java +++ b/src/com/android/bitmap/view/BitmapDrawableImageView.java @@ -34,6 +34,9 @@ import com.android.bitmap.drawable.BasicBitmapDrawable; public class BitmapDrawableImageView extends ImageView { private static final boolean HAS_TRANSIENT_STATE_SUPPORTED = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; + private static final boolean TEMPORARY = true; + private static final boolean PERMANENT = !TEMPORARY; + private BasicBitmapDrawable mDrawable; private boolean mAttachedToWindow; @@ -74,8 +77,12 @@ public class BitmapDrawableImageView extends ImageView { } private void unbindDrawable() { + unbindDrawable(PERMANENT); + } + + private void unbindDrawable(boolean temporary) { if (mDrawable != null) { - mDrawable.unbind(); + mDrawable.unbind(temporary); } } @@ -121,7 +128,7 @@ public class BitmapDrawableImageView extends ImageView { super.onDetachedFromWindow(); mAttachedToWindow = false; if (HAS_TRANSIENT_STATE_SUPPORTED && !hasTransientState()) { - unbindDrawable(); + unbindDrawable(TEMPORARY); } } @@ -129,7 +136,7 @@ public class BitmapDrawableImageView extends ImageView { public void setHasTransientState(boolean hasTransientState) { super.setHasTransientState(hasTransientState); if (!hasTransientState && !mAttachedToWindow) { - unbindDrawable(); + unbindDrawable(TEMPORARY); } } } |