1 |
|
|
2 |
|
package pl.magot.vetch.widgets; |
3 |
|
|
4 |
|
|
5 |
|
import android.content.Context; |
6 |
|
import android.graphics.Canvas; |
7 |
|
import android.graphics.Paint; |
8 |
|
import android.graphics.RectF; |
9 |
|
import android.widget.Button; |
10 |
|
|
11 |
|
|
|
|
| 97,2% |
Uncovered Elements: 1 (36) |
Complexity: 8 |
Complexity Density: 0,32 |
|
12 |
|
public class SymbolButton extends Button |
13 |
|
{ |
14 |
|
|
15 |
|
private static final int iColor = 0xffaaaaaa; |
16 |
|
private static final int iColorActive = 0xff442200; |
17 |
|
|
18 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
19 |
|
public enum symbol { none, arrowLeft, arrowRight }; |
20 |
|
|
21 |
|
|
22 |
|
private Paint pt = new Paint(); |
23 |
|
private RectF rect = new RectF(); |
24 |
|
private RectF rectDraw = new RectF(); |
25 |
|
private symbol symbolType = symbol.none; |
26 |
|
|
27 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
28 |
12
|
public SymbolButton(Context context, symbol symbolType)... |
29 |
|
{ |
30 |
12
|
super(context); |
31 |
12
|
this.symbolType = symbolType; |
32 |
|
} |
33 |
|
|
|
|
| 94,4% |
Uncovered Elements: 1 (18) |
Complexity: 4 |
Complexity Density: 0,29 |
|
34 |
123
|
@Override... |
35 |
|
public void onDraw(Canvas canvas) |
36 |
|
{ |
37 |
123
|
super.onDraw(canvas); |
38 |
|
|
39 |
123
|
pt.setAntiAlias(true); |
40 |
123
|
pt.setStrokeCap(Paint.Cap.ROUND); |
41 |
|
|
42 |
123
|
rectDraw.set(0, 0, getWidth(), getHeight()); |
43 |
123
|
rectDraw.left += 6; |
44 |
123
|
rectDraw.right -= 6; |
45 |
123
|
rectDraw.top += 4; |
46 |
123
|
rectDraw.bottom -= 8; |
47 |
|
|
48 |
123
|
if (symbolType != symbol.none) |
49 |
|
{ |
50 |
123
|
pt.setStrokeWidth(5); |
51 |
|
|
52 |
123
|
pt.setColor(iColor); |
53 |
123
|
if (this.isPressed() || this.isFocused()) |
54 |
30
|
pt.setColor(iColorActive); |
55 |
|
|
56 |
123
|
drawArrow(canvas); |
57 |
|
} |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
60 |
123
|
private void drawArrow(Canvas canvas)... |
61 |
|
{ |
62 |
123
|
rect.set(rectDraw); |
63 |
123
|
rect.inset(15, 5); |
64 |
123
|
canvas.drawLine(rect.left, rect.centerY(), rect.right, rect.centerY(), pt); |
65 |
123
|
if (symbolType == symbol.arrowRight) |
66 |
|
{ |
67 |
70
|
canvas.drawLine(rect.right, rect.centerY(), rect.right - 6, rect.top, pt); |
68 |
70
|
canvas.drawLine(rect.right, rect.centerY(), rect.right - 6, rect.bottom, pt); |
69 |
|
} |
70 |
123
|
if (symbolType == symbol.arrowLeft) |
71 |
|
{ |
72 |
53
|
canvas.drawLine(rect.left, rect.centerY(), rect.left + 6, rect.top, pt); |
73 |
53
|
canvas.drawLine(rect.left, rect.centerY(), rect.left + 6, rect.bottom, pt); |
74 |
|
} |
75 |
|
} |
76 |
|
|
77 |
|
} |