summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2014-03-02 16:52:56 -0800
committerMark Wei <markwei@google.com>2014-03-02 16:52:56 -0800
commitad97cd0e0753930ec68f189e6be1023dc0f62f75 (patch)
tree3663c786f44546123f6321543170b5b37c41b4ea
parent1a340d4fca7babcb67d6cfa754f58c1a756dfca0 (diff)
downloadbitmap-ad97cd0e0753930ec68f189e6be1023dc0f62f75.tar.gz
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
-rw-r--r--src/com/android/bitmap/drawable/BasicBitmapDrawable.java4
-rw-r--r--src/com/android/bitmap/view/BitmapDrawableImageView.java13
2 files changed, 5 insertions, 12 deletions
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();
}