summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2014-01-21 14:58:19 -0800
committerMark Wei <markwei@google.com>2014-01-21 14:58:19 -0800
commit8aa2d8601f6a97af4a329cfc3bfd5fb5fb5bcbf8 (patch)
tree1bc50f826cbd6850088b302bcf04d922c8027513
parent3633bda5a285f442a52c4d6e0ab637e74f8cf175 (diff)
downloadbitmap-8aa2d8601f6a97af4a329cfc3bfd5fb5fb5bcbf8.tar.gz
Check both ReusableBitmap and ReusableBitmap#bmp for null to avoid NPE.
Bug: 12617030 Change-Id: I5882be1f02413dd55f44bf09b68257e9690abb6c
-rw-r--r--src/com/android/bitmap/drawable/BasicBitmapDrawable.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
index 8fe1ff4..684d322 100644
--- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
+++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
@@ -204,7 +204,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback,
* Should only be overriden, not called.
*/
protected void setBitmap(ReusableBitmap bmp) {
- if (mBitmap != null && mBitmap != bmp) {
+ if (hasBitmap()) {
mBitmap.releaseReference();
}
mBitmap = bmp;
@@ -293,7 +293,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback,
return;
}
- if (mBitmap != null && mBitmap.bmp != null) {
+ if (hasBitmap()) {
BitmapUtils.calculateCroppedSrcRect(
mBitmap.getLogicalWidth(), mBitmap.getLogicalHeight(),
bounds.width(), bounds.height(),
@@ -321,12 +321,18 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback,
}
}
+ protected boolean hasBitmap() {
+ return mBitmap != null && mBitmap.bmp != null;
+ }
+
/**
* Override this method to customize how to draw the bitmap to the canvas for the given bounds.
* The bitmap to be drawn can be found at {@link #getBitmap()}.
*/
protected void onDrawBitmap(final Canvas canvas, final Rect src, final Rect dst) {
- canvas.drawBitmap(mBitmap.bmp, src, dst, mPaint);
+ if (hasBitmap()) {
+ canvas.drawBitmap(mBitmap.bmp, src, dst, mPaint);
+ }
}
@Override
@@ -346,7 +352,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback,
@Override
public int getOpacity() {
- return (mBitmap != null && (mBitmap.bmp.hasAlpha() || mPaint.getAlpha() < 255)) ?
+ return (hasBitmap() && (mBitmap.bmp.hasAlpha() || mPaint.getAlpha() < 255)) ?
PixelFormat.TRANSLUCENT : PixelFormat.OPAQUE;
}