summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2014-03-18 11:57:01 -0700
committerMark Wei <markwei@google.com>2014-03-18 14:31:41 -0700
commit5b46c679794d2f4362e8064b0291c578835d75e0 (patch)
treed0669c69673422d39d7b0563869fbd46032c68a4
parent9f42e5cd4e26c6d3d175491c524763d1aefe8643 (diff)
downloadbitmap-5b46c679794d2f4362e8064b0291c578835d75e0.tar.gz
unbind() will not keep track of the previous key unless we specify that the
unbind is temporary. This prevents race conditions that cause an old key to be bound on attach to window. Bug: 13507371 Change-Id: I5187ddd956fe28472fde1ef11360840059d15423
-rw-r--r--src/com/android/bitmap/drawable/BasicBitmapDrawable.java19
-rw-r--r--src/com/android/bitmap/view/BitmapDrawableImageView.java13
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);
}
}
}