diff options
author | Mark Wei <markwei@google.com> | 2013-10-21 23:08:47 -0700 |
---|---|---|
committer | Mark Wei <markwei@google.com> | 2013-10-21 23:08:47 -0700 |
commit | e03daa1db89106c11d8885b94d7ac97c10bea3b3 (patch) | |
tree | 47824fd87aefbffc4efd228ebec5a23b78d650ce | |
parent | 549bb653b1ec516c905ebeed5d27104e8b11b537 (diff) | |
download | bitmap-e03daa1db89106c11d8885b94d7ac97c10bea3b3.tar.gz |
Expose sRect and mPaint to subclasses.
Change-Id: If9c994b3e5c19b66aaebe77f127c04ac9152994e
-rw-r--r-- | src/com/android/bitmap/drawable/BasicBitmapDrawable.java | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java index b6a148f..9cee3c0 100644 --- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java @@ -48,17 +48,19 @@ import java.util.concurrent.TimeUnit; */ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCallback, Drawable.Callback { + protected static Rect sRect; protected RequestKey mCurrKey; protected ReusableBitmap mBitmap; + protected final Paint mPaint = new Paint(); + private final BitmapCache mCache; private final boolean mLimitDensity; + private final float mDensity; private DecodeTask mTask; private int mDecodeWidth; - private int mDecodeHeight; - private static final String TAG = BasicBitmapDrawable.class.getSimpleName(); // based on framework CL:I015d77 private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); private static final int CORE_POOL_SIZE = CPU_COUNT + 1; @@ -67,17 +69,12 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa private static final Executor SMALL_POOL_EXECUTOR = new ThreadPoolExecutor( CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(128), new NamedThreadFactory("decode")); - private static final Executor EXECUTOR = SMALL_POOL_EXECUTOR; private static final int MAX_BITMAP_DENSITY = DisplayMetrics.DENSITY_HIGH; - private static final float VERTICAL_CENTER = 1f / 2; - private final float mDensity; - private final Paint mPaint = new Paint(); - - private final Rect mSrcRect = new Rect(); + private static final String TAG = BasicBitmapDrawable.class.getSimpleName(); private static final boolean DEBUG = DecodeTask.DEBUG; public BasicBitmapDrawable(final Resources res, final BitmapCache cache, @@ -86,6 +83,12 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa mCache = cache; mLimitDensity = limitDensity; mPaint.setFilterBitmap(true); + mPaint.setAntiAlias(true); + mPaint.setDither(true); + + if (sRect == null) { + sRect = new Rect(); + } } public RequestKey getKey() { @@ -164,7 +167,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa bounds.width(), bounds.height(), bounds.height(), Integer.MAX_VALUE, VERTICAL_CENTER, false /* absoluteFraction */, - 1, mSrcRect); + 1, sRect); final int orientation = mBitmap.getOrientation(); // calculateCroppedSrcRect() gave us the source rectangle "as if" the orientation has @@ -172,7 +175,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa // coordinates. RectUtils.rotateRectForOrientation(orientation, new Rect(0, 0, mBitmap.getLogicalWidth(), mBitmap.getLogicalHeight()), - mSrcRect); + sRect); // We may need to rotate the canvas, so we also have to rotate the bounds. final Rect rotatedBounds = new Rect(bounds); @@ -181,7 +184,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa // Rotate the canvas. canvas.save(); canvas.rotate(orientation, bounds.centerX(), bounds.centerY()); - canvas.drawBitmap(mBitmap.bmp, mSrcRect, rotatedBounds, mPaint); + canvas.drawBitmap(mBitmap.bmp, sRect, rotatedBounds, mPaint); canvas.restore(); } } |