diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/VanillaImageButton.java b/app/src/main/java/ch/blinkenlights/android/vanilla/VanillaImageButton.java index 09e47d59..ae3ece37 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/VanillaImageButton.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/VanillaImageButton.java @@ -28,12 +28,18 @@ import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; +import android.support.annotation.Nullable; + + public class VanillaImageButton extends ImageButton { private Context mContext; private static int mNormalTint; private static int mActiveTint; - private int mCircleColor; + /** + * The paint used to draw this buttons circle. + */ + private @Nullable Paint mCirclePaint; public VanillaImageButton(Context context) { this(context, null); @@ -51,8 +57,12 @@ public class VanillaImageButton extends ImageButton { if (attrs != null) { TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.VanillaImageButton, 0, 0); - mCircleColor = a.getColor(R.styleable.VanillaImageButton_backgroundCircleColor, 0); + final int color = a.getColor(R.styleable.VanillaImageButton_backgroundCircleColor, 0); a.recycle(); + + mCirclePaint = new Paint(); + mCirclePaint.setColor(color); + mCirclePaint.setAntiAlias(true); } updateImageTint(-1); @@ -66,16 +76,14 @@ public class VanillaImageButton extends ImageButton { @Override public void onDraw(Canvas canvas) { - if (mCircleColor != 0) { + if (mCirclePaint != null) { // Draw a circle on the background, but only // if the color is set. final int x = getWidth() / 2; final int y = getHeight() / 2; final float r = (x > y ? y : x); - Paint paint = new Paint(); - paint.setColor(mCircleColor); - paint.setAntiAlias(true); - canvas.drawCircle(x, y, r*0.80f, paint); + + canvas.drawCircle(x, y, r*0.80f, mCirclePaint); } super.onDraw(canvas); }