]> Pileus Git - ~andy/freeotp/blob - src/org/fedorahosted/freeotp/CircleProgressBar.java
Clean up some formatting issues
[~andy/freeotp] / src / org / fedorahosted / freeotp / CircleProgressBar.java
1 /*
2  * FreeOTP
3  *
4  * Authors: Nathaniel McCallum <npmccallum@redhat.com>
5  *
6  * Copyright (C) 2013  Nathaniel McCallum, Red Hat
7  * see file 'COPYING' for use and warranty information
8  *
9  * This program is free software you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 package org.fedorahosted.freeotp;
24
25 import android.content.Context;
26 import android.graphics.Canvas;
27 import android.graphics.Paint;
28 import android.graphics.Paint.Style;
29 import android.graphics.Rect;
30 import android.graphics.RectF;
31 import android.util.AttributeSet;
32 import android.widget.ProgressBar;
33
34 public class CircleProgressBar extends ProgressBar {
35         private Paint paint;
36         private RectF rectf;
37         private Rect rect;
38
39         public CircleProgressBar(Context context, AttributeSet attrs, int defStyle) {
40                 super(context, attrs, defStyle);
41                 setup();
42         }
43
44         public CircleProgressBar(Context context, AttributeSet attrs) {
45                 super(context, attrs);
46                 setup();
47         }
48
49         public CircleProgressBar(Context context) {
50                 super(context);
51                 setup();
52         }
53
54         private void setup() {
55                 paint = new Paint();
56         rectf = new RectF();
57         rect = new Rect();
58
59         paint.setColor(0x33333300);
60         paint.setAlpha(0x99);
61         paint.setAntiAlias(true);
62         paint.setStyle(Style.FILL_AND_STROKE);
63         }
64
65         @Override
66         protected synchronized void onDraw(Canvas canvas) {
67                 getDrawingRect(rect);
68                 rect.left += getPaddingLeft() + 2;
69                 rect.top += getPaddingTop() + 2;
70                 rect.right -= getPaddingRight() + 2;
71                 rect.bottom -= getPaddingBottom() + 2;
72
73                 rectf.set(rect);
74                 canvas.drawArc(rectf, -90, getProgress() * 360 / getMax(), true, paint);
75         }
76 }