@Override protected void onDraw(@NonNull Canvas canvas) { final int cx = getWidth() / 2, cy = canvas.getHeight() / 2; canvas.drawCircle(cx, cy, innerRadius, paint); if (isChecked()) { canvas.drawCircle(cx, cy, outerRadius, strokePaint); textRenderer.draw(canvas, cx, cy); } }
public SelectionColorButton(Context context, int innerRadius, int color) { super(context, null); this.innerRadius = innerRadius; outerRadius = (int) (innerRadius * 1.2f); width = (int) (outerRadius * 2.4f); this.color = color; setBackgroundResource(R.drawable.bg_selection_toolbar_item); setPadding(0, 0, 0, 0); // overrides default toggle button's paddings paint = new Paint(); paint.setFlags(Paint.ANTI_ALIAS_FLAG); strokePaint = new Paint(); strokePaint.setFlags(Paint.ANTI_ALIAS_FLAG); strokePaint.setStyle(Paint.Style.STROKE); strokePaint.setStrokeWidth((outerRadius - innerRadius) * 2 / 3); textRenderer = new TextCenterRenderer(getContext().getString(R.string.selection_quote)); textRenderer.onMeasure(innerRadius); setupColors(Color.WHITE); }