[go: nahoru, domu]

Skip to content

Commit

Permalink
Replace fields holding bitmap dimensions with local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hdodenhof committed Mar 13, 2020
1 parent 7ad4632 commit 3d10e24
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public class CircleImageView extends ImageView {

private Bitmap mBitmap;
private BitmapShader mBitmapShader;
private int mBitmapWidth;
private int mBitmapHeight;

private float mDrawableRadius;
private float mBorderRadius;
Expand Down Expand Up @@ -397,9 +395,6 @@ private void setup() {
mCircleBackgroundPaint.setAntiAlias(true);
mCircleBackgroundPaint.setColor(mCircleBackgroundColor);

mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();

mBorderRect.set(calculateBounds());
mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2.0f, (mBorderRect.width() - mBorderWidth) / 2.0f);

Expand Down Expand Up @@ -434,12 +429,15 @@ private void updateShaderMatrix() {

mShaderMatrix.set(null);

if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
scale = mDrawableRect.height() / (float) mBitmapHeight;
dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
int bitmapHeight = mBitmap.getHeight();
int bitmapWidth = mBitmap.getWidth();

if (bitmapWidth * mDrawableRect.height() > mDrawableRect.width() * bitmapHeight) {
scale = mDrawableRect.height() / (float) bitmapHeight;
dx = (mDrawableRect.width() - bitmapWidth * scale) * 0.5f;
} else {
scale = mDrawableRect.width() / (float) mBitmapWidth;
dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
scale = mDrawableRect.width() / (float) bitmapWidth;
dy = (mDrawableRect.height() - bitmapHeight * scale) * 0.5f;
}

mShaderMatrix.setScale(scale, scale);
Expand Down

0 comments on commit 3d10e24

Please sign in to comment.