1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.ui; |
6 | import android.content.Context; |
7 | import android.graphics.Canvas; |
8 | import android.graphics.Color; |
9 | import android.graphics.Paint; |
10 | import android.graphics.Paint.Style; |
11 | import android.util.AttributeSet; |
12 | import android.widget.Button; |
13 | |
14 | /** |
15 | * Simple class that draws a white border around a button, purely for a UI change. |
16 | */ |
17 | public class ColorPickerMoreButton extends Button { |
18 | |
19 | // A cache for the paint used to draw the border, so it doesn't have to be created in |
20 | // every onDraw() call. |
21 | private Paint mBorderPaint; |
22 | |
23 | public ColorPickerMoreButton(Context context, AttributeSet attrs) { |
24 | super(context, attrs); |
25 | init(); |
26 | } |
27 | |
28 | public ColorPickerMoreButton(Context context, AttributeSet attrs, int defStyle) { |
29 | super(context, attrs, defStyle); |
30 | init(); |
31 | } |
32 | |
33 | /** |
34 | * Sets up the paint to use for drawing the border. |
35 | */ |
36 | public void init() { |
37 | mBorderPaint = new Paint(); |
38 | mBorderPaint.setStyle(Paint.Style.STROKE); |
39 | mBorderPaint.setColor(Color.WHITE); |
40 | // Set the width to one pixel. |
41 | mBorderPaint.setStrokeWidth(1.0f); |
42 | // And make sure the border doesn't bleed into the outside. |
43 | mBorderPaint.setAntiAlias(false); |
44 | } |
45 | |
46 | /** |
47 | * Draws the border around the edge of the button. |
48 | * |
49 | * @param canvas The canvas to draw on. |
50 | */ |
51 | @Override |
52 | protected void onDraw(Canvas canvas) { |
53 | canvas.drawRect(0.5f, 0.5f, getWidth() - 1.5f, getHeight() - 1.5f, mBorderPaint); |
54 | super.onDraw(canvas); |
55 | } |
56 | } |