diff options
author | Mark Wei <markwei@google.com> | 2014-07-14 16:56:54 -0700 |
---|---|---|
committer | Mark Wei <markwei@google.com> | 2014-07-14 16:56:54 -0700 |
commit | c5644927c0e7e121049b063046296ee8a59a4b37 (patch) | |
tree | d78a248b0a908e71dd5516cd435a27acd004afe2 /src/com/android/bitmap/drawable | |
parent | 5c102db5a1a16a2adcc7728693a6e65a981f91ae (diff) | |
download | bitmap-c5644927c0e7e121049b063046296ee8a59a4b37.tar.gz |
Import latest bitmap library changes.
Change-Id: Ic3a79a1154fb1329bf4c163ea6aeb32f8bd3857d
Diffstat (limited to 'src/com/android/bitmap/drawable')
4 files changed, 81 insertions, 19 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java index ffea5c8..5de0840 100644 --- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java @@ -203,7 +203,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, } if (key == null) { - invalidateSelf(); + onDecodeFailed(); Trace.endSection(); return; } @@ -241,6 +241,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, */ protected void loadFileDescriptorFactory() { if (mCurrKey == null || mDecodeWidth == 0 || mDecodeHeight == 0) { + onDecodeFailed(); return; } @@ -258,16 +259,30 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, final FileDescriptorFactory factory) { if (mCreateFileDescriptorFactoryTask == null) { // Cancelled. + onDecodeFailed(); return; } mCreateFileDescriptorFactoryTask = null; + if (factory == null) { + // Failed. + onDecodeFailed(); + return; + } + if (key.equals(mCurrKey)) { decode(factory); } } /** + * Called when the decode process is cancelled at any time. + */ + protected void onDecodeFailed() { + invalidateSelf(); + } + + /** * Should only be overriden, not called. */ protected void decode(final FileDescriptorFactory factory) { diff --git a/src/com/android/bitmap/drawable/CircularBitmapDrawable.java b/src/com/android/bitmap/drawable/CircularBitmapDrawable.java index 942cbfb..cb8ede7 100644 --- a/src/com/android/bitmap/drawable/CircularBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/CircularBitmapDrawable.java @@ -98,11 +98,21 @@ public class CircularBitmapDrawable extends ExtendedBitmapDrawable { @Override protected void onDrawPlaceholderOrProgress(final Canvas canvas, final TileDrawable drawable) { - BitmapDrawable placeholder = (BitmapDrawable) drawable.getInnerDrawable(); - Bitmap bitmap = placeholder.getBitmap(); - float alpha = placeholder.getPaint().getAlpha() / 255f; - sRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); - onDrawCircularBitmap(bitmap, canvas, sRect, getBounds(), alpha); + Rect bounds = getBounds(); + if (drawable.getInnerDrawable() instanceof BitmapDrawable) { + BitmapDrawable placeholder = + (BitmapDrawable) drawable.getInnerDrawable(); + Bitmap bitmap = placeholder.getBitmap(); + float alpha = placeholder.getPaint().getAlpha() / 255f; + sRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); + onDrawCircularBitmap(bitmap, canvas, sRect, bounds, alpha); + } else { + super.onDrawPlaceholderOrProgress(canvas, drawable); + } + + // Then draw the border. + canvas.drawCircle(bounds.centerX(), bounds.centerY(), + bounds.width() / 2f - mBorderWidth / 2, mBorderPaint); } /** diff --git a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java index 0e01142..ab81e6f 100644 --- a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java @@ -55,7 +55,7 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements public static final int LOAD_STATE_FAILED = 4; public static final boolean DEBUG = false; - public static final String TAG = ExtendedBitmapDrawable.class.getSimpleName(); + private static final String TAG = ExtendedBitmapDrawable.class.getSimpleName(); private final Resources mResources; private final ExtendedOptions mOpts; @@ -102,18 +102,20 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements ConstantState constantState = mOpts.placeholder.getConstantState(); if (constantState != null) { placeholder = constantState.newDrawable(mResources); + } else { + placeholder = mOpts.placeholder; + } - Rect bounds = mOpts.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(); - } + Rect bounds = mOpts.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(); } } @@ -198,7 +200,11 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements @Override protected void setBitmap(ReusableBitmap bmp) { - setLoadState((bmp != null) ? LOAD_STATE_LOADED : LOAD_STATE_FAILED); + if (bmp != null) { + setLoadState(LOAD_STATE_LOADED); + } else { + onDecodeFailed(); + } super.setBitmap(bmp); } @@ -217,6 +223,13 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements super.loadFileDescriptorFactory(); } + @Override + protected void onDecodeFailed() { + super.onDecodeFailed(); + + setLoadState(LOAD_STATE_FAILED); + } + protected boolean shouldExecuteStateChange() { // TODO: AttachmentDrawable should override this method to match prev and curr request keys. return /* opts.stateChanges */ true; diff --git a/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java b/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java index e23642d..953bfd0 100644 --- a/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java @@ -24,6 +24,7 @@ import android.graphics.Paint.Style; import android.graphics.Path; import android.graphics.Rect; import android.graphics.RectF; +import android.util.Log; import com.android.bitmap.BitmapCache; @@ -39,6 +40,7 @@ import com.android.bitmap.BitmapCache; * {@link #CORNER_STYLE_FLAP} corners have a colored flap drawn within the bounds. */ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable { + private static final String TAG = StyledCornersBitmapDrawable.class.getSimpleName(); public static final int CORNER_STYLE_SHARP = 0; public static final int CORNER_STYLE_ROUND = 1; @@ -66,6 +68,7 @@ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable { private int mScrimColor; private float mBorderWidth; private boolean mIsCompatibilityMode; + private boolean mEatInvalidates; /** * Create a new StyledCornersBitmapDrawable. @@ -224,6 +227,8 @@ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable { return; } + pauseInvalidate(); + // Clip to path. if (!mIsCompatibilityMode) { canvas.save(); @@ -276,6 +281,17 @@ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable { // Draw border around path. canvas.drawPath(mClipPath, mBorderPaint); + + resumeInvalidate(); + } + + @Override + public void invalidateSelf() { + if (!mEatInvalidates) { + super.invalidateSelf(); + } else { + Log.d(TAG, "Skipping invalidate."); + } } protected void drawFakeCornersForCompatibilityMode(final Canvas canvas) { @@ -362,6 +378,14 @@ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable { } } + private void pauseInvalidate() { + mEatInvalidates = true; + } + + private void resumeInvalidate() { + mEatInvalidates = false; + } + private void recalculatePath() { Rect bounds = getBounds(); |