summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2014-02-20 18:24:19 -0800
committerMark Wei <markwei@google.com>2014-02-21 10:39:24 -0800
commit1a340d4fca7babcb67d6cfa754f58c1a756dfca0 (patch)
tree455152d13c4214a9c9c0d6f085bfc18dc813aceb
parentd7654f820a99358a7d2b2afb9b3a174690e213f6 (diff)
downloadandroid_frameworks_opt_bitmap-1a340d4fca7babcb67d6cfa754f58c1a756dfca0.tar.gz
android_frameworks_opt_bitmap-1a340d4fca7babcb67d6cfa754f58c1a756dfca0.tar.bz2
android_frameworks_opt_bitmap-1a340d4fca7babcb67d6cfa754f58c1a756dfca0.zip
Rebind on attach to window if previously unbinded on detach from window.
Change-Id: I67d83689de85e14a5b20b644e2dbcc533ac544dd
-rw-r--r--src/com/android/bitmap/view/BitmapDrawableImageView.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/com/android/bitmap/view/BitmapDrawableImageView.java b/src/com/android/bitmap/view/BitmapDrawableImageView.java
index 642cd5e..5468f63 100644
--- a/src/com/android/bitmap/view/BitmapDrawableImageView.java
+++ b/src/com/android/bitmap/view/BitmapDrawableImageView.java
@@ -24,6 +24,7 @@ import android.os.Build;
import android.util.AttributeSet;
import android.widget.ImageView;
+import com.android.bitmap.RequestKey;
import com.android.bitmap.drawable.BasicBitmapDrawable;
/**
@@ -32,10 +33,11 @@ import com.android.bitmap.drawable.BasicBitmapDrawable;
* window.
*/
public class BitmapDrawableImageView extends ImageView {
- private static final boolean hasTransientStateSupported =
+ private static final boolean HAS_TRANSIENT_STATE_SUPPORTED =
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);
@@ -71,6 +73,7 @@ public class BitmapDrawableImageView extends ImageView {
super.setImageDrawable(drawable);
unbindDrawable();
mDrawable = drawable;
+ mKeyAtLastUnbindDueToDetach = null;
}
private void unbindDrawable() {
@@ -84,6 +87,7 @@ public class BitmapDrawableImageView extends ImageView {
super.setImageResource(resId);
unbindDrawable();
mDrawable = null;
+ mKeyAtLastUnbindDueToDetach = null;
}
@Override
@@ -91,6 +95,7 @@ public class BitmapDrawableImageView extends ImageView {
super.setImageURI(uri);
unbindDrawable();
mDrawable = null;
+ mKeyAtLastUnbindDueToDetach = null;
}
@Override
@@ -98,6 +103,7 @@ public class BitmapDrawableImageView extends ImageView {
super.setImageDrawable(drawable);
unbindDrawable();
mDrawable = null;
+ mKeyAtLastUnbindDueToDetach = null;
}
@Override
@@ -105,19 +111,27 @@ public class BitmapDrawableImageView extends ImageView {
super.setImageBitmap(bm);
unbindDrawable();
mDrawable = null;
+ mKeyAtLastUnbindDueToDetach = null;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mAttachedToWindow = true;
+ if (mDrawable != null && mDrawable.getKey() == null) {
+ mDrawable.bind(mKeyAtLastUnbindDueToDetach);
+ }
+ mKeyAtLastUnbindDueToDetach = null;
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mAttachedToWindow = false;
- if (hasTransientStateSupported && !hasTransientState()) {
+ if (mDrawable != null) {
+ mKeyAtLastUnbindDueToDetach = mDrawable.getKey();
+ }
+ if (HAS_TRANSIENT_STATE_SUPPORTED && !hasTransientState()) {
unbindDrawable();
}
}