summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2013-12-08 04:34:27 -0800
committerMark Wei <markwei@google.com>2013-12-08 04:37:01 -0800
commitb6ec2afe9710112214d79b36b2233fef6a52845a (patch)
treebb2c9e882208ba47ac77017a2d59d3e58056d668
parent19a41ec7aaace2ab0b117d0baaeb544c5667b240 (diff)
downloadbitmap-b6ec2afe9710112214d79b36b2233fef6a52845a.tar.gz
Allow placeholder drawable to be sized by the client. First try to use the
bounds, then try to use the intrinsic bounds. When a key is null, set load state to FAILED instead of UNINITIALIZED. The difference is that FAILED shows the placeholder as a static image while UNINITIALIZED hides it. Fix bug in BitmapDrawableImageView where detaching from the window would set its drawable to null, throwing away state. Change-Id: I0b3f6c931d750ec4042e13bc1cbcf2d63e260168
-rw-r--r--src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java47
-rw-r--r--src/com/android/bitmap/view/BitmapDrawableImageView.java5
2 files changed, 40 insertions, 12 deletions
diff --git a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java
index 7be8b6e..8714aea 100644
--- a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java
+++ b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java
@@ -44,11 +44,19 @@ import com.android.bitmap.util.Trace;
* to draw upon state changes.
* <p>
* The actual bitmap decode work is handled by {@link DecodeTask}.
- * TODO: have this class extend from BasicBitmapDrawable
*/
public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements
Runnable, Parallaxable, DecodeAggregator.Callback {
+ public static final int LOAD_STATE_UNINITIALIZED = 0;
+ public static final int LOAD_STATE_NOT_YET_LOADED = 1;
+ public static final int LOAD_STATE_LOADING = 2;
+ public static final int LOAD_STATE_LOADED = 3;
+ public static final int LOAD_STATE_FAILED = 4;
+
+ public static final boolean DEBUG = false;
+ public static final String TAG = ExtendedBitmapDrawable.class.getSimpleName();
+
private final ExtendedOptions mOpts;
// Parallax.
@@ -56,20 +64,12 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements
private float mParallaxFraction = 1f / 2;
// State changes.
- private static final int LOAD_STATE_UNINITIALIZED = 0;
- private static final int LOAD_STATE_NOT_YET_LOADED = 1;
- private static final int LOAD_STATE_LOADING = 2;
- private static final int LOAD_STATE_LOADED = 3;
- private static final int LOAD_STATE_FAILED = 4;
private int mLoadState = LOAD_STATE_UNINITIALIZED;
private Placeholder mPlaceholder;
private Progress mProgress;
private int mProgressDelayMs;
private final Handler mHandler = new Handler();
- public static final boolean DEBUG = false;
- public static final String TAG = ExtendedBitmapDrawable.class.getSimpleName();
-
public ExtendedBitmapDrawable(final Resources res, final BitmapCache cache,
final boolean limitDensity, final ExtendedOptions opts) {
super(res, cache, limitDensity);
@@ -84,14 +84,28 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements
// Placeholder is not optional because backgroundColor is part of it.
Drawable placeholder = null;
+ int placeholderWidth = res.getDimensionPixelSize(R.dimen.placeholder_size);
+ int placeholderHeight = res.getDimensionPixelSize(R.dimen.placeholder_size);
if (opts.placeholder != null) {
ConstantState constantState = opts.placeholder.getConstantState();
if (constantState != null) {
placeholder = constantState.newDrawable(res);
+
+ Rect bounds = opts.placeholder.getBounds();
+ if (bounds.width() != 0) {
+ placeholderWidth = bounds.width();
+ } else if (placeholder.getIntrinsicWidth() != -1) {
+ placeholderWidth = placeholder.getIntrinsicWidth();
+ }
+ if (bounds.height() != 0) {
+ placeholderHeight = bounds.height();
+ } else if (placeholder.getIntrinsicHeight() != -1) {
+ placeholderHeight = placeholder.getIntrinsicHeight();
+ }
}
}
- int placeholderSize = res.getDimensionPixelSize(R.dimen.placeholder_size);
- mPlaceholder = new Placeholder(placeholder, res, placeholderSize, placeholderSize,
+
+ mPlaceholder = new Placeholder(placeholder, res, placeholderWidth, placeholderHeight,
fadeOutDurationMs, opts);
mPlaceholder.setCallback(this);
@@ -144,6 +158,10 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements
setLoadState(LOAD_STATE_UNINITIALIZED);
super.setImage(key);
+
+ if (key == null) {
+ showStaticPlaceholder();
+ }
}
@Override
@@ -303,6 +321,13 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements
}
/**
+ * Get the load state of this drawable. Return one of the LOAD_STATE constants.
+ */
+ public int getLoadState() {
+ return mLoadState;
+ }
+
+ /**
* Each attachment gets its own placeholder and progress indicator, to be shown, hidden,
* and animated based on Drawable#setVisible() changes, which are in turn driven by
* setLoadState().
diff --git a/src/com/android/bitmap/view/BitmapDrawableImageView.java b/src/com/android/bitmap/view/BitmapDrawableImageView.java
index a55b864..b776c34 100644
--- a/src/com/android/bitmap/view/BitmapDrawableImageView.java
+++ b/src/com/android/bitmap/view/BitmapDrawableImageView.java
@@ -67,7 +67,6 @@ public class BitmapDrawableImageView extends ImageView {
private void unbindDrawable() {
if (mDrawable != null) {
mDrawable.unbind();
- mDrawable = null;
}
}
@@ -75,24 +74,28 @@ public class BitmapDrawableImageView extends ImageView {
public void setImageResource(final int resId) {
super.setImageResource(resId);
unbindDrawable();
+ mDrawable = null;
}
@Override
public void setImageURI(final Uri uri) {
super.setImageURI(uri);
unbindDrawable();
+ mDrawable = null;
}
@Override
public void setImageDrawable(final Drawable drawable) {
super.setImageDrawable(drawable);
unbindDrawable();
+ mDrawable = null;
}
@Override
public void setImageBitmap(final Bitmap bm) {
super.setImageBitmap(bm);
unbindDrawable();
+ mDrawable = null;
}
@Override