1 |
|
|
2 |
|
package pl.magot.vetch.widgets; |
3 |
|
|
4 |
|
|
5 |
|
import android.content.Context; |
6 |
|
import android.widget.EditText; |
7 |
|
import android.graphics.Canvas; |
8 |
|
import android.graphics.Paint; |
9 |
|
import android.graphics.Typeface; |
10 |
|
import android.util.AttributeSet; |
11 |
|
import android.graphics.*; |
12 |
|
|
13 |
|
|
|
|
| 97,2% |
Uncovered Elements: 3 (106) |
Complexity: 16 |
Complexity Density: 0,2 |
|
14 |
|
public class HintEdit extends EditText |
15 |
|
{ |
16 |
|
|
17 |
|
private static final int iColorLightFrame = 0x88888888; |
18 |
|
private static final int iColorLightBkg = 0xccffffff; |
19 |
|
private static final int iColorLightText = 0xff000000; |
20 |
|
|
21 |
|
|
22 |
|
private static final int iColorDarkFrame = 0x886688aa; |
23 |
|
private static final int iColorDarkBkg = 0xcc6688aa; |
24 |
|
private static final int iColorDarkText = 0xffffffff; |
25 |
|
|
26 |
|
|
27 |
|
private final static Typeface tfMono = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); |
28 |
|
private static final int iMarginVert = 6; |
29 |
|
private static final int iMarginVertBottom = 8; |
30 |
|
private static final int iPaddingHorz = 26; |
31 |
|
|
32 |
|
|
33 |
|
private Path pthTriangle = new Path(); |
34 |
|
private Path pthTriangleBkg = new Path(); |
35 |
|
private Paint pt = new Paint(); |
36 |
|
private RectF rect = new RectF(); |
37 |
|
private RectF rectBkg = new RectF(); |
38 |
|
private boolean bHint = false; |
39 |
|
private boolean bHintSmall = false; |
40 |
|
private boolean bLight = false; |
41 |
|
private String sHintText = ""; |
42 |
|
|
43 |
|
|
44 |
|
private float fTextSize = 32; |
45 |
|
private float fTextSizeSmall = 14; |
46 |
|
private int iSymbolWidth = 0; |
47 |
|
private int iSymbolWidthSmall = 0; |
48 |
|
private int iTextHeight = 0; |
49 |
|
private int iTextHeightSmall = 0; |
50 |
|
private int iTextAscent = 0; |
51 |
|
private int iTextAscentSmall = 0; |
52 |
|
|
53 |
|
|
54 |
|
private int iHintWidth = 0; |
55 |
|
private int iHintHeight = 0; |
56 |
|
|
57 |
|
|
58 |
|
private int iHintWidthSmall = 0; |
59 |
|
private int iHintHeightSmall = 0; |
60 |
|
|
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
62 |
5
|
public HintEdit(Context context)... |
63 |
|
{ |
64 |
5
|
super(context); |
65 |
5
|
initialize(); |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
68 |
0
|
@SuppressWarnings("all")... |
69 |
|
public HintEdit(Context context, AttributeSet attrs) |
70 |
|
{ |
71 |
0
|
super(context, attrs); |
72 |
0
|
initialize(); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 1 |
Complexity Density: 0,04 |
|
75 |
5
|
private void initialize()... |
76 |
|
{ |
77 |
5
|
pt.setUnderlineText(false); |
78 |
5
|
pt.setFakeBoldText(true); |
79 |
5
|
pt.setTypeface(tfMono); |
80 |
5
|
pt.setTextScaleX(1.3F); |
81 |
|
|
82 |
5
|
pt.setTextSize(fTextSize); |
83 |
5
|
iSymbolWidth = (int)pt.measureText("W"); |
84 |
5
|
iTextHeight = (int)(-pt.ascent() + pt.descent()); |
85 |
5
|
iTextAscent = (int)pt.ascent(); |
86 |
5
|
iHintHeight = iMarginVert + iTextHeight + iMarginVert; |
87 |
|
|
88 |
5
|
pt.setTextSize(fTextSizeSmall); |
89 |
5
|
iSymbolWidthSmall = (int)pt.measureText("W"); |
90 |
5
|
iTextHeightSmall = (int)(-pt.ascent() + pt.descent()); |
91 |
5
|
iTextAscentSmall = (int)pt.ascent(); |
92 |
5
|
iHintHeightSmall = iMarginVert + iTextHeightSmall + iMarginVert; |
93 |
|
|
94 |
|
|
95 |
5
|
final int iTriEdge = 10; |
96 |
5
|
final int iTriHeight = 12; |
97 |
|
|
98 |
|
|
99 |
5
|
pthTriangle.moveTo(0, 0); |
100 |
5
|
pthTriangle.lineTo(iTriEdge, 0); |
101 |
5
|
pthTriangle.lineTo(0, iTriHeight); |
102 |
5
|
pthTriangle.lineTo(-iTriEdge, 0); |
103 |
5
|
pthTriangle.lineTo(0, 0); |
104 |
5
|
pthTriangle.close(); |
105 |
|
|
106 |
|
|
107 |
5
|
pthTriangleBkg.moveTo(0, -2); |
108 |
5
|
pthTriangleBkg.lineTo(iTriEdge - 1, -2); |
109 |
5
|
pthTriangleBkg.lineTo(0, iTriHeight - 3); |
110 |
5
|
pthTriangleBkg.lineTo(-iTriEdge + 1, -2); |
111 |
5
|
pthTriangleBkg.lineTo(0, -2); |
112 |
5
|
pthTriangleBkg.close(); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (61) |
Complexity: 11 |
Complexity Density: 0,27 |
|
115 |
119
|
@Override... |
116 |
|
protected void onDraw(Canvas canvas) |
117 |
|
{ |
118 |
119
|
super.onDraw(canvas); |
119 |
|
|
120 |
119
|
if (bHint) |
121 |
|
{ |
122 |
41
|
final int iOffsetY = this.getScrollY(); |
123 |
|
|
124 |
41
|
pt.setUnderlineText(false); |
125 |
41
|
pt.setFakeBoldText(true); |
126 |
41
|
pt.setTypeface(tfMono); |
127 |
41
|
pt.setTextScaleX(1.3F); |
128 |
41
|
pt.setAntiAlias(true); |
129 |
|
|
130 |
|
|
131 |
41
|
int iTextWidth = 0; |
132 |
41
|
int iPosX = 0; |
133 |
41
|
int iPosY = 0; |
134 |
|
|
135 |
41
|
if (bHintSmall) |
136 |
|
{ |
137 |
14
|
iTextWidth = iSymbolWidthSmall * sHintText.length(); |
138 |
14
|
iHintWidthSmall = iPaddingHorz + iTextWidth + iPaddingHorz; |
139 |
14
|
iPosX = (this.getWidth() >> 1) - (iHintWidthSmall >> 1); |
140 |
14
|
iPosY = (this.getHeight() >> 1) - (iHintHeightSmall >> 1) + iOffsetY; |
141 |
14
|
rect.set(iPosX, iPosY, iPosX + iHintWidthSmall, iPosY + iHintHeightSmall); |
142 |
|
} else { |
143 |
27
|
iTextWidth = iSymbolWidth; |
144 |
27
|
iHintWidth = iPaddingHorz + iTextWidth + iPaddingHorz; |
145 |
27
|
iPosX = (this.getWidth() >> 1) - (iHintWidth >> 1); |
146 |
27
|
iPosY = (this.getHeight() >> 1) - (iHintHeight >> 1) + iOffsetY; |
147 |
27
|
rect.set(iPosX, iPosY, iPosX + iHintWidth, iPosY + iHintHeight); |
148 |
|
|
149 |
|
|
150 |
27
|
rect.offset(0, - iMarginVertBottom); |
151 |
|
} |
152 |
|
|
153 |
41
|
rectBkg.set(rect); |
154 |
41
|
rectBkg.inset(2, 2); |
155 |
|
|
156 |
|
|
157 |
41
|
pt.setColor(bLight?iColorLightFrame:iColorDarkFrame); |
158 |
41
|
canvas.drawRoundRect(rect, 4, 4, pt); |
159 |
|
|
160 |
41
|
pt.setColor(bLight?iColorLightBkg:iColorDarkBkg); |
161 |
41
|
canvas.drawRoundRect(rectBkg, 3, 3, pt); |
162 |
|
|
163 |
|
|
164 |
41
|
canvas.save(); |
165 |
41
|
canvas.translate(rect.centerX(), rect.bottom); |
166 |
|
|
167 |
41
|
pt.setColor(bLight?iColorLightFrame:iColorDarkFrame); |
168 |
41
|
canvas.drawPath(pthTriangle, pt); |
169 |
|
|
170 |
41
|
pt.setColor(bLight?iColorLightBkg:iColorDarkBkg); |
171 |
41
|
canvas.drawPath(pthTriangleBkg, pt); |
172 |
|
|
173 |
41
|
canvas.restore(); |
174 |
|
|
175 |
|
|
176 |
41
|
final int iTextX = (int)rect.centerX() - (iTextWidth >> 1); |
177 |
41
|
final int iTextY = (int)rect.centerY() - ((bHintSmall?iTextHeightSmall:iTextHeight) >> 1) - (bHintSmall?iTextAscentSmall:iTextAscent); |
178 |
41
|
pt.setColor(bLight?iColorLightText:iColorDarkText); |
179 |
41
|
pt.setTextSize(bHintSmall?fTextSizeSmall:fTextSize); |
180 |
41
|
canvas.drawText(sHintText, iTextX, iTextY + 1, pt); |
181 |
|
} |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
184 |
61
|
public void showSymbolHint(String sText, boolean bLight)... |
185 |
|
{ |
186 |
61
|
bHint = true; |
187 |
61
|
this.bHintSmall = (sText.length() > 1); |
188 |
61
|
this.sHintText = sText; |
189 |
61
|
this.bLight = bLight; |
190 |
61
|
invalidate(); |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
193 |
31
|
public void hideSymbolHint()... |
194 |
|
{ |
195 |
31
|
bHint = false; |
196 |
31
|
invalidate(); |
197 |
|
} |
198 |
|
|
199 |
|
} |
200 |
|
|