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