From ad97cd0e0753930ec68f189e6be1023dc0f62f75 Mon Sep 17 00:00:00 2001 From: Mark Wei Date: Sun, 2 Mar 2014 16:52:56 -0800 Subject: When detached from window, the last known RequestKey is saved inside of the BasicBitmapDrawable instead of referenced separately in the BitmapDrawableImageView. This fixes a bug where you could bind() a stale RequestKey to the drawable, after having called drawable.unbind() before it is attached back to the window. Change-Id: Idba62fea647871d5c1c495b2c89e10779289a53b --- src/com/android/bitmap/drawable/BasicBitmapDrawable.java | 4 ++++ src/com/android/bitmap/view/BitmapDrawableImageView.java | 13 +------------ 2 files changed, 5 insertions(+), 12 deletions(-) (limited to 'src/com/android/bitmap') diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java index a09daad..831f410 100644 --- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java @@ -109,6 +109,10 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, return mCurrKey; } + public final RequestKey getPreviousKey() { + return mPrevKey; + } + protected ReusableBitmap getBitmap() { return mBitmap; } diff --git a/src/com/android/bitmap/view/BitmapDrawableImageView.java b/src/com/android/bitmap/view/BitmapDrawableImageView.java index 5468f63..5d42b6c 100644 --- a/src/com/android/bitmap/view/BitmapDrawableImageView.java +++ b/src/com/android/bitmap/view/BitmapDrawableImageView.java @@ -24,7 +24,6 @@ import android.os.Build; import android.util.AttributeSet; import android.widget.ImageView; -import com.android.bitmap.RequestKey; import com.android.bitmap.drawable.BasicBitmapDrawable; /** @@ -37,7 +36,6 @@ public class BitmapDrawableImageView extends ImageView { Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; private BasicBitmapDrawable mDrawable; private boolean mAttachedToWindow; - private RequestKey mKeyAtLastUnbindDueToDetach; public BitmapDrawableImageView(final Context context) { this(context, null); @@ -73,7 +71,6 @@ public class BitmapDrawableImageView extends ImageView { super.setImageDrawable(drawable); unbindDrawable(); mDrawable = drawable; - mKeyAtLastUnbindDueToDetach = null; } private void unbindDrawable() { @@ -87,7 +84,6 @@ public class BitmapDrawableImageView extends ImageView { super.setImageResource(resId); unbindDrawable(); mDrawable = null; - mKeyAtLastUnbindDueToDetach = null; } @Override @@ -95,7 +91,6 @@ public class BitmapDrawableImageView extends ImageView { super.setImageURI(uri); unbindDrawable(); mDrawable = null; - mKeyAtLastUnbindDueToDetach = null; } @Override @@ -103,7 +98,6 @@ public class BitmapDrawableImageView extends ImageView { super.setImageDrawable(drawable); unbindDrawable(); mDrawable = null; - mKeyAtLastUnbindDueToDetach = null; } @Override @@ -111,7 +105,6 @@ public class BitmapDrawableImageView extends ImageView { super.setImageBitmap(bm); unbindDrawable(); mDrawable = null; - mKeyAtLastUnbindDueToDetach = null; } @Override @@ -119,18 +112,14 @@ public class BitmapDrawableImageView extends ImageView { super.onAttachedToWindow(); mAttachedToWindow = true; if (mDrawable != null && mDrawable.getKey() == null) { - mDrawable.bind(mKeyAtLastUnbindDueToDetach); + mDrawable.bind(mDrawable.getPreviousKey()); } - mKeyAtLastUnbindDueToDetach = null; } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mAttachedToWindow = false; - if (mDrawable != null) { - mKeyAtLastUnbindDueToDetach = mDrawable.getKey(); - } if (HAS_TRANSIENT_STATE_SUPPORTED && !hasTransientState()) { unbindDrawable(); } -- cgit v1.2.3