summaryrefslogtreecommitdiff
path: root/src/com/android/bitmap/view
diff options
context:
space:
mode:
authorOleksandr Kyreiev <shoora@google.com>2014-12-18 17:54:56 +0100
committerOleksandr Kyreiev <shoora@google.com>2014-12-18 17:54:56 +0100
commita8b1e1f5cad36086e89c052007473609c379ccbd (patch)
tree2938160ebeb973ba402a64b880311cfd994b8ab0 /src/com/android/bitmap/view
parent4309c1f708f469a5ab3ac52b6b22cc6ede1d50ff (diff)
downloadbitmap-a8b1e1f5cad36086e89c052007473609c379ccbd.tar.gz
Import latest changes.
Change-Id: I27973b3441d3738a85481de9c774da0ac08afd7c
Diffstat (limited to 'src/com/android/bitmap/view')
-rw-r--r--src/com/android/bitmap/view/BitmapDrawableImageView.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/com/android/bitmap/view/BitmapDrawableImageView.java b/src/com/android/bitmap/view/BitmapDrawableImageView.java
index 9a88f3f..5cbc58d 100644
--- a/src/com/android/bitmap/view/BitmapDrawableImageView.java
+++ b/src/com/android/bitmap/view/BitmapDrawableImageView.java
@@ -30,6 +30,11 @@ import com.android.bitmap.drawable.BasicBitmapDrawable;
* A helpful ImageView replacement that can generally be used in lieu of ImageView.
* BitmapDrawableImageView has logic to unbind its BasicBitmapDrawable when it is detached from the
* window.
+ *
+ * If you are using this with RecyclerView,
+ * or any use-case where {@link android.view.View#onDetachedFromWindow} is
+ * not a good signal for unbind,
+ * makes sure you {@link #setShouldUnbindOnDetachFromWindow} to false.
*/
public class BitmapDrawableImageView extends ImageView {
private static final boolean HAS_TRANSIENT_STATE_SUPPORTED =
@@ -38,6 +43,7 @@ public class BitmapDrawableImageView extends ImageView {
private static final boolean PERMANENT = !TEMPORARY;
private BasicBitmapDrawable mDrawable;
+ private boolean mShouldUnbindOnDetachFromWindow = true;
private boolean mAttachedToWindow;
public BitmapDrawableImageView(final Context context) {
@@ -53,6 +59,14 @@ public class BitmapDrawableImageView extends ImageView {
super(context, attrs, defStyle);
}
+ public boolean shouldUnbindOnDetachFromWindow() {
+ return mShouldUnbindOnDetachFromWindow;
+ }
+
+ public void setShouldUnbindOnDetachFromWindow(boolean shouldUnbindOnDetachFromWindow) {
+ mShouldUnbindOnDetachFromWindow = shouldUnbindOnDetachFromWindow;
+ }
+
/**
* Get the source drawable for this BitmapDrawableImageView.
* @return The source drawable casted to the given type, or null if the type does not match.
@@ -72,11 +86,13 @@ public class BitmapDrawableImageView extends ImageView {
*/
public <E extends BasicBitmapDrawable> void setTypedDrawable(E drawable) {
super.setImageDrawable(drawable);
- unbindDrawable();
+ if (drawable != mDrawable) {
+ unbindDrawable();
+ }
mDrawable = drawable;
}
- private void unbindDrawable() {
+ public void unbindDrawable() {
unbindDrawable(PERMANENT);
}
@@ -119,7 +135,7 @@ public class BitmapDrawableImageView extends ImageView {
super.onAttachedToWindow();
mAttachedToWindow = true;
if (mDrawable != null && mDrawable.getKey() == null
- && mDrawable.getPreviousKey() != null) {
+ && mDrawable.getPreviousKey() != null && mShouldUnbindOnDetachFromWindow) {
mDrawable.bind(mDrawable.getPreviousKey());
}
}
@@ -128,7 +144,8 @@ public class BitmapDrawableImageView extends ImageView {
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mAttachedToWindow = false;
- if (HAS_TRANSIENT_STATE_SUPPORTED && !hasTransientState()) {
+ if (HAS_TRANSIENT_STATE_SUPPORTED && !hasTransientState()
+ && mShouldUnbindOnDetachFromWindow) {
unbindDrawable(TEMPORARY);
}
}
@@ -136,7 +153,7 @@ public class BitmapDrawableImageView extends ImageView {
@Override
public void setHasTransientState(boolean hasTransientState) {
super.setHasTransientState(hasTransientState);
- if (!hasTransientState && !mAttachedToWindow) {
+ if (!hasTransientState && !mAttachedToWindow && mShouldUnbindOnDetachFromWindow) {
unbindDrawable(TEMPORARY);
}
}