1 |
|
|
2 |
|
package pl.magot.vetch.widgets; |
3 |
|
|
4 |
|
|
5 |
|
import java.util.*; |
6 |
|
import android.content.*; |
7 |
|
import android.view.*; |
8 |
|
import android.widget.LinearLayout.LayoutParams; |
9 |
|
import android.graphics.*; |
10 |
|
|
11 |
|
|
|
|
| 83,5% |
Uncovered Elements: 70 (423) |
Complexity: 88 |
Complexity Density: 0,31 |
|
12 |
|
public class TimeWidgetSlider extends View |
13 |
|
{ |
14 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
15 |
|
public interface OnTimeChange |
16 |
|
{ |
17 |
|
public void OnChange(TimeWidgetSlider slider); |
18 |
|
} |
19 |
|
|
20 |
|
|
|
|
| 76,2% |
Uncovered Elements: 10 (42) |
Complexity: 10 |
Complexity Density: 0,38 |
|
21 |
|
private class ValueBox |
22 |
|
{ |
23 |
|
|
24 |
|
public int iValue = 0; |
25 |
|
@SuppressWarnings("unused") |
26 |
|
public int iLeftOffset = 0; |
27 |
|
@SuppressWarnings("unused") |
28 |
|
public int iWidth = 0; |
29 |
|
public String strValue = null; |
30 |
|
public int iStrWidth = 0; |
31 |
|
public int iStrWidthSmall = 0; |
32 |
|
|
33 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
34 |
72
|
public ValueBox(int iValue, int iLeftOffset, int iWidth, Paint pt)... |
35 |
|
{ |
36 |
72
|
this.iValue = iValue; |
37 |
72
|
this.iLeftOffset = iLeftOffset; |
38 |
72
|
this.iWidth = iWidth; |
39 |
72
|
strValue = getValueStr(); |
40 |
72
|
calcValueStrWidths(pt); |
41 |
|
} |
|
|
| 81,8% |
Uncovered Elements: 4 (22) |
Complexity: 6 |
Complexity Density: 0,5 |
|
42 |
72
|
private String getValueStr()... |
43 |
|
{ |
44 |
72
|
if (iSliderType == STYPE_MINUTES) |
45 |
24
|
return Integer.toString(iValue * 5); |
46 |
48
|
if (iSliderType == STYPE_HOURS) |
47 |
|
{ |
48 |
48
|
if (b24HourMode) |
49 |
|
{ |
50 |
0
|
return Integer.toString(iValue); |
51 |
|
} else { |
52 |
48
|
int iDisplayHour = iValue; |
53 |
48
|
if (iDisplayHour == 0) |
54 |
2
|
iDisplayHour = 12; |
55 |
48
|
if (iDisplayHour > 12) |
56 |
22
|
iDisplayHour -= 12; |
57 |
48
|
return Integer.toString(iDisplayHour); |
58 |
|
} |
59 |
|
} |
60 |
0
|
return ""; |
61 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
62 |
72
|
public void calcValueStrWidths(Paint pt)... |
63 |
|
{ |
64 |
72
|
pt.setFakeBoldText(true); |
65 |
72
|
pt.setTypeface(tfMono); |
66 |
|
|
67 |
72
|
pt.setTextSize(fTextSize); |
68 |
72
|
iStrWidth = (int)pt.measureText(strValue); |
69 |
|
|
70 |
72
|
pt.setTextSize(fTextSizeSmall); |
71 |
72
|
iStrWidthSmall = (int)pt.measureText(strValue); |
72 |
|
} |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
73 |
0
|
@SuppressWarnings("unused")... |
74 |
|
public boolean isPM() |
75 |
|
{ |
76 |
0
|
if (iValue >= 12) |
77 |
0
|
return true; |
78 |
0
|
return false; |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
private ArrayList<ValueBox> vecValues = new ArrayList<ValueBox>(); |
84 |
|
|
85 |
|
|
86 |
|
private final static int iColorBkg = 0xff777777; |
87 |
|
private final static int iColorLightBkg = 0xffcccccc; |
88 |
|
private final static int iColorSliderBkg = 0xff444444; |
89 |
|
private final static int iColorButtonArrows = 0xff444444; |
90 |
|
private final static int iColorSliderCenterBox = 0xffffffff; |
91 |
|
private final static int iColorValueBoxText = 0xff666666; |
92 |
|
private final static int iColorValueBoxBkg = 0xffbbbbbb; |
93 |
|
private final static int iColorValueBoxTextSelected = 0xff222222; |
94 |
|
|
95 |
|
|
96 |
|
private final static Typeface tfMono = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); |
97 |
|
private final static float fTextSize = 28; |
98 |
|
private final static float fTextSizeSmall = 22; |
99 |
|
private final static int iFocusBorder = 3; |
100 |
|
private final static int iSliderSpace = 4; |
101 |
|
private final static int iSliderBorder = 4; |
102 |
|
private final static int iBoxBorder = 4; |
103 |
|
private final static int iSliderButtonWidth = 40; |
104 |
|
|
105 |
|
|
106 |
|
protected OnTimeChange mOnTimeChange = null; |
107 |
|
|
108 |
|
|
109 |
|
private Paint pt = new Paint(); |
110 |
|
private RectF rectFocus = new RectF(); |
111 |
|
private RectF rect = new RectF(); |
112 |
|
private RectF rectBar = new RectF(); |
113 |
|
private RectF rectBox = new RectF(); |
114 |
|
private RectF rectCenterBox = new RectF(); |
115 |
|
private RectF rectButtonLeft = new RectF(); |
116 |
|
private RectF rectButtonRight = new RectF(); |
117 |
|
private RectF rectSlider = new RectF(); |
118 |
|
|
119 |
|
|
120 |
|
private boolean b24HourMode = false; |
121 |
|
private int iSliderType = 0; |
122 |
|
private boolean bNoValue = false; |
123 |
|
private int iCurrentValue = -1; |
124 |
|
|
125 |
|
|
126 |
|
private boolean bTouchedDownSlider = false; |
127 |
|
private boolean bTouchedDownBtnLeft = false; |
128 |
|
private boolean bTouchedDownBtnRight = false; |
129 |
|
private int iTouchedSliderPosX = 0; |
130 |
|
|
131 |
|
|
132 |
|
public final static int STYPE_HOURS = 1; |
133 |
|
public final static int STYPE_MINUTES = 2; |
134 |
|
|
135 |
|
|
136 |
|
private int iBoxWidth = 0; |
137 |
|
private BlurMaskFilter filterBlur = new BlurMaskFilter(0.5F, BlurMaskFilter.Blur.NORMAL); |
138 |
|
|
139 |
|
|
140 |
|
private int iAnimPosX = 0; |
141 |
|
private int iAnimDelta = 0; |
142 |
|
private long mLastTime = 0; |
143 |
|
private final static int iAnimStep = 12; |
144 |
|
|
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
|
146 |
4
|
public TimeWidgetSlider(Context context, boolean b24HourMode, int iSliderType, int iWidth)... |
147 |
|
{ |
148 |
4
|
super(context); |
149 |
4
|
this.b24HourMode = b24HourMode; |
150 |
4
|
this.iSliderType = iSliderType; |
151 |
4
|
setFocusable(true); |
152 |
|
|
153 |
4
|
final int iHeight = getTotalHeight(); |
154 |
4
|
setLayoutParams(new LayoutParams(iWidth, iHeight)); |
155 |
|
|
156 |
|
|
157 |
4
|
iBoxWidth = getBoxWidth(); |
158 |
4
|
initRectangles(iWidth, iHeight); |
159 |
|
|
160 |
4
|
generateValues(); |
161 |
4
|
setValue(getValue(), false); |
162 |
|
} |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
4
|
public void setTimeChangeEvent(OnTimeChange timeChange) ... |
165 |
|
{ |
166 |
4
|
this.mOnTimeChange = timeChange; |
167 |
|
} |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
169 |
31
|
public void doTimeChanged()... |
170 |
|
{ |
171 |
31
|
if (mOnTimeChange != null) |
172 |
27
|
mOnTimeChange.OnChange(this); |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
175 |
4
|
private int getBoxWidth()... |
176 |
|
{ |
177 |
4
|
pt.setTypeface(tfMono); |
178 |
4
|
pt.setTextSize(fTextSize); |
179 |
4
|
pt.setFakeBoldText(true); |
180 |
4
|
return iBoxBorder + (int)pt.measureText("00") + iBoxBorder; |
181 |
|
} |
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0,06 |
|
183 |
4
|
private void initRectangles(int iWidth, int iHeight)... |
184 |
|
{ |
185 |
4
|
rectFocus.set(0, 0, iWidth, iHeight); |
186 |
|
|
187 |
4
|
rect.set(rectFocus); |
188 |
4
|
rect.inset(0, iFocusBorder); |
189 |
|
|
190 |
4
|
rectBar.set(iFocusBorder, |
191 |
|
iFocusBorder + iSliderBorder + iSliderSpace, |
192 |
|
iWidth - iFocusBorder, |
193 |
|
iHeight - iSliderSpace - iSliderBorder - iFocusBorder); |
194 |
|
|
195 |
4
|
rectButtonLeft.set(rect); |
196 |
4
|
rectButtonLeft.right = iSliderButtonWidth; |
197 |
4
|
rectButtonRight.set(rect); |
198 |
4
|
rectButtonRight.left = rectButtonRight.right - iSliderButtonWidth; |
199 |
|
|
200 |
4
|
rectSlider.set(rectBar); |
201 |
4
|
rectSlider.left = rectButtonLeft.right; |
202 |
4
|
rectSlider.right = rectButtonRight.left; |
203 |
|
|
204 |
4
|
rectCenterBox.set(rectSlider); |
205 |
4
|
rectCenterBox.top -= iSliderSpace; |
206 |
4
|
rectCenterBox.bottom += iSliderSpace; |
207 |
4
|
rectCenterBox.left += ((int)rectCenterBox.width() >> 1) - (iBoxWidth >> 1); |
208 |
4
|
rectCenterBox.right = rectCenterBox.left + iBoxWidth; |
209 |
|
} |
210 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
211 |
0
|
public void clearValue()... |
212 |
|
{ |
213 |
0
|
this.bNoValue = true; |
214 |
0
|
this.invalidate(); |
215 |
0
|
doTimeChanged(); |
216 |
|
} |
217 |
|
|
|
|
| 94,4% |
Uncovered Elements: 2 (36) |
Complexity: 8 |
Complexity Density: 0,36 |
|
218 |
31
|
public void setValue(int iValue, boolean bAnimate)... |
219 |
|
{ |
220 |
31
|
this.bNoValue = false; |
221 |
31
|
int iMax = 0; |
222 |
31
|
if (iSliderType == STYPE_HOURS) |
223 |
14
|
iMax = (vecValues.size() - 1); |
224 |
31
|
if (iSliderType == STYPE_MINUTES) |
225 |
17
|
iMax = (vecValues.size() - 1) * 5; |
226 |
|
|
227 |
31
|
this.iAnimDelta = (iCurrentValue - iValue); |
228 |
|
|
229 |
31
|
if (iValue < 0) |
230 |
|
{ |
231 |
5
|
iValue = iMax; |
232 |
|
} |
233 |
31
|
if (iValue > iMax) |
234 |
|
{ |
235 |
0
|
iValue = 0; |
236 |
|
} |
237 |
|
|
238 |
31
|
this.iCurrentValue = iValue; |
239 |
|
|
240 |
31
|
this.iAnimPosX = 0; |
241 |
31
|
if (iAnimDelta > 0) |
242 |
10
|
this.iAnimPosX = 0; |
243 |
31
|
if (iAnimDelta < 0) |
244 |
17
|
this.iAnimPosX = iBoxWidth; |
245 |
|
|
246 |
31
|
if (!bAnimate) |
247 |
|
{ |
248 |
8
|
this.iAnimPosX = 0; |
249 |
8
|
this.iAnimDelta = 0; |
250 |
|
} |
251 |
|
|
252 |
31
|
this.invalidate(); |
253 |
31
|
doTimeChanged(); |
254 |
|
} |
255 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
256 |
85
|
public int getValue()... |
257 |
|
{ |
258 |
85
|
return this.iCurrentValue; |
259 |
|
} |
260 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
261 |
15952
|
private int getTextHeight()... |
262 |
|
{ |
263 |
15952
|
return (int)(-pt.ascent() + pt.descent()); |
264 |
|
} |
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
266 |
4
|
private int getTotalHeight()... |
267 |
|
{ |
268 |
4
|
pt.setTextSize(fTextSize); |
269 |
4
|
return iSliderBorder + iSliderSpace + iBoxBorder + getTextHeight() + iBoxBorder + iSliderSpace + iSliderBorder; |
270 |
|
} |
271 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0,45 |
|
272 |
0
|
@Override... |
273 |
|
public boolean onKeyDown(int keyCode, KeyEvent event) |
274 |
|
{ |
275 |
0
|
boolean bResult = super.onKeyDown(keyCode, event); |
276 |
0
|
if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER) || (keyCode == KeyEvent.KEYCODE_ENTER)) |
277 |
|
{ |
278 |
|
} |
279 |
0
|
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) |
280 |
|
{ |
281 |
0
|
bTouchedDownBtnLeft = true; |
282 |
0
|
doClickSliderButton(); |
283 |
0
|
clearTouchButtonsFlags(); |
284 |
|
} |
285 |
0
|
if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) |
286 |
|
{ |
287 |
0
|
bTouchedDownBtnRight = true; |
288 |
0
|
doClickSliderButton(); |
289 |
0
|
clearTouchButtonsFlags(); |
290 |
|
} |
291 |
0
|
return bResult; |
292 |
|
} |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
294 |
0
|
@Override... |
295 |
|
public boolean onKeyUp(int keyCode, KeyEvent event) |
296 |
|
{ |
297 |
0
|
boolean bResult = super.onKeyUp(keyCode, event); |
298 |
0
|
return bResult; |
299 |
|
} |
300 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
301 |
4
|
private void generateValues()... |
302 |
|
{ |
303 |
4
|
vecValues.clear(); |
304 |
4
|
if (iSliderType == STYPE_HOURS) |
305 |
|
{ |
306 |
2
|
generateValuesRange(24); |
307 |
|
} |
308 |
4
|
if (iSliderType == STYPE_MINUTES) |
309 |
|
{ |
310 |
2
|
generateValuesRange(12); |
311 |
|
} |
312 |
|
} |
313 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
314 |
4
|
private void generateValuesRange(int iRange)... |
315 |
|
{ |
316 |
4
|
int iLeftOffset = 0; |
317 |
76
|
for (int iValue = 0; iValue < iRange; iValue++) |
318 |
|
{ |
319 |
72
|
ValueBox value = new ValueBox(iValue, iLeftOffset, iBoxWidth, pt); |
320 |
72
|
vecValues.add(value); |
321 |
72
|
iLeftOffset += iBoxWidth; |
322 |
|
} |
323 |
|
} |
324 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 7 |
Complexity Density: 0,54 |
|
325 |
886
|
private void updateAnimationState()... |
326 |
|
{ |
327 |
|
|
328 |
886
|
if ((System.currentTimeMillis() - mLastTime) < 30) |
329 |
456
|
return; |
330 |
430
|
mLastTime = System.currentTimeMillis(); |
331 |
|
|
332 |
|
|
333 |
430
|
if (iAnimDelta < 0) |
334 |
|
{ |
335 |
68
|
iAnimPosX -= iAnimStep; |
336 |
68
|
if (iAnimPosX < 0) |
337 |
17
|
iAnimDelta = 0; |
338 |
|
} |
339 |
|
|
340 |
430
|
if (iAnimDelta > 0) |
341 |
|
{ |
342 |
23
|
iAnimPosX += iAnimStep; |
343 |
23
|
if (iAnimPosX > iBoxWidth) |
344 |
5
|
iAnimDelta = 0; |
345 |
|
} |
346 |
|
|
347 |
430
|
if (iAnimDelta == 0) |
348 |
|
{ |
349 |
361
|
iAnimPosX = 0; |
350 |
|
} |
351 |
|
} |
352 |
|
|
|
|
| 91,7% |
Uncovered Elements: 1 (12) |
Complexity: 2 |
Complexity Density: 0,2 |
|
353 |
886
|
@Override... |
354 |
|
protected void onDraw(Canvas canvas) |
355 |
|
{ |
356 |
886
|
super.onDraw(canvas); |
357 |
|
|
358 |
886
|
updateAnimationState(); |
359 |
|
|
360 |
886
|
drawBackground(canvas); |
361 |
|
|
362 |
886
|
if (!bNoValue) |
363 |
|
{ |
364 |
886
|
drawSliderBars(canvas); |
365 |
|
} |
366 |
|
|
367 |
886
|
drawFrames(canvas); |
368 |
|
|
369 |
886
|
drawSliderButtons(canvas); |
370 |
886
|
drawArrowLeft(canvas); |
371 |
886
|
drawArrowRight(canvas); |
372 |
|
|
373 |
|
|
374 |
886
|
this.invalidate(); |
375 |
|
} |
376 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (49) |
Complexity: 7 |
Complexity Density: 0,19 |
|
377 |
886
|
private void drawSliderBars(Canvas canvas)... |
378 |
|
{ |
379 |
886
|
canvas.save(); |
380 |
886
|
canvas.clipRect(rectSlider); |
381 |
|
|
382 |
886
|
int index = iCurrentValue; |
383 |
886
|
if (iSliderType == STYPE_HOURS) |
384 |
443
|
index = iCurrentValue; |
385 |
886
|
if (iSliderType == STYPE_MINUTES) |
386 |
443
|
index = iCurrentValue / 5; |
387 |
|
|
388 |
|
|
389 |
886
|
final ValueBox value = vecValues.get(index); |
390 |
886
|
rectBox.set(rectSlider); |
391 |
886
|
rectBox.left = rectCenterBox.left + iAnimPosX; |
392 |
886
|
rectBox.right = rectBox.left + iBoxWidth; |
393 |
886
|
drawValueBox(canvas, rectBox, value); |
394 |
|
|
395 |
|
|
396 |
886
|
int iLeftIndex = index - 1; |
397 |
886
|
rectBox.set(rectSlider); |
398 |
886
|
rectBox.left = rectCenterBox.left - iBoxWidth + iAnimPosX; |
399 |
886
|
rectBox.right = rectBox.left + iBoxWidth; |
400 |
4430
|
for (int i = 0; i < 4; i++) |
401 |
|
{ |
402 |
3544
|
if (iLeftIndex < 0) |
403 |
302
|
iLeftIndex = vecValues.size() - 1; |
404 |
3544
|
final ValueBox valueLeft = vecValues.get(iLeftIndex); |
405 |
3544
|
drawValueBox(canvas, rectBox, valueLeft); |
406 |
3544
|
rectBox.left -= iBoxWidth; |
407 |
3544
|
rectBox.right = rectBox.left + iBoxWidth; |
408 |
3544
|
iLeftIndex--; |
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
886
|
int iRightIndex = index + 1; |
413 |
886
|
rectBox.set(rectSlider); |
414 |
886
|
rectBox.left = rectCenterBox.right + iAnimPosX; |
415 |
886
|
rectBox.right = rectBox.left + iBoxWidth; |
416 |
4430
|
for (int i = 0; i < 4; i++) |
417 |
|
{ |
418 |
3544
|
if (iRightIndex > (vecValues.size() - 1)) |
419 |
93
|
iRightIndex = 0; |
420 |
3544
|
final ValueBox valueRight = vecValues.get(iRightIndex); |
421 |
3544
|
drawValueBox(canvas, rectBox, valueRight); |
422 |
3544
|
rectBox.left += iBoxWidth; |
423 |
3544
|
rectBox.right = rectBox.left + iBoxWidth; |
424 |
3544
|
iRightIndex++; |
425 |
|
} |
426 |
|
|
427 |
886
|
canvas.restore(); |
428 |
|
} |
429 |
|
|
|
|
| 76,2% |
Uncovered Elements: 5 (21) |
Complexity: 4 |
Complexity Density: 0,27 |
|
430 |
886
|
private void drawBackground(Canvas canvas)... |
431 |
|
{ |
432 |
886
|
pt.setShader(null); |
433 |
886
|
pt.setAntiAlias(true); |
434 |
|
|
435 |
|
|
436 |
886
|
if (this.isFocused()) |
437 |
|
{ |
438 |
0
|
pt.setColor(0xffff8800); |
439 |
0
|
canvas.drawRoundRect(rectFocus, 2, 2, pt); |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
886
|
pt.setColor(iColorBkg); |
444 |
886
|
final int iRoundCorner = this.isFocused()?0:2; |
445 |
886
|
canvas.drawRoundRect(rect, iRoundCorner, iRoundCorner, pt); |
446 |
|
|
447 |
|
|
448 |
886
|
pt.setColor(iColorSliderBkg); |
449 |
886
|
canvas.drawRect(rectSlider, pt); |
450 |
|
|
451 |
|
|
452 |
886
|
pt.setColor(iColorValueBoxBkg); |
453 |
886
|
canvas.drawRect(rectSlider.left, rectSlider.top + 1, rectSlider.right, rectSlider.bottom -1, pt); |
454 |
|
|
455 |
|
|
456 |
886
|
if (!bNoValue) |
457 |
|
{ |
458 |
886
|
pt.setColor(iColorSliderCenterBox); |
459 |
886
|
canvas.drawRoundRect(rectCenterBox, 2, 2, pt); |
460 |
|
} |
461 |
|
} |
462 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
463 |
7974
|
private boolean isCurrentBoxSelected(RectF rect)... |
464 |
|
{ |
465 |
7974
|
if ((rect.left >= rectCenterBox.left) && (rect.right <= rectCenterBox.right)) |
466 |
745
|
return true; |
467 |
7229
|
return false; |
468 |
|
} |
469 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 5 |
Complexity Density: 0,25 |
|
470 |
7974
|
private void drawValueBox(Canvas canvas, RectF rect, ValueBox value)... |
471 |
|
{ |
472 |
7974
|
final boolean bSelected = isCurrentBoxSelected(rect); |
473 |
|
|
474 |
|
|
475 |
7974
|
pt.setShader(null); |
476 |
7974
|
pt.setAntiAlias(true); |
477 |
7974
|
pt.setFakeBoldText(true); |
478 |
7974
|
pt.setTypeface(tfMono); |
479 |
7974
|
pt.setUnderlineText(false); |
480 |
|
|
481 |
7974
|
pt.setTextSize(fTextSizeSmall); |
482 |
7974
|
if (bSelected) |
483 |
745
|
pt.setTextSize(fTextSize); |
484 |
|
|
485 |
7974
|
if (iAnimPosX != 0) |
486 |
1341
|
pt.setMaskFilter(filterBlur); |
487 |
|
|
488 |
7974
|
final int iNumberWidth = (bSelected)?value.iStrWidth:value.iStrWidthSmall; |
489 |
|
|
490 |
7974
|
int iTextPosX = (int)rect.right - iNumberWidth; |
491 |
7974
|
int iTextPosY = (int)rect.bottom + (int)(-pt.ascent()) - getTextHeight(); |
492 |
|
|
493 |
7974
|
iTextPosX -= ((int)rect.width() >> 1) - (iNumberWidth >> 1); |
494 |
7974
|
iTextPosY -= ((int)rect.height() >> 1) - (getTextHeight() >> 1); |
495 |
|
|
496 |
7974
|
iTextPosY += 1; |
497 |
|
|
498 |
7974
|
pt.setColor((bSelected)?iColorValueBoxTextSelected:iColorValueBoxText); |
499 |
7974
|
canvas.drawText(value.strValue, iTextPosX, iTextPosY, pt); |
500 |
|
|
501 |
7974
|
pt.setMaskFilter(null); |
502 |
|
} |
503 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0,3 |
|
504 |
886
|
private void drawSliderButtons(Canvas canvas)... |
505 |
|
{ |
506 |
886
|
pt.setShader(null); |
507 |
886
|
pt.setAntiAlias(true); |
508 |
886
|
pt.setFakeBoldText(true); |
509 |
886
|
pt.setTypeface(tfMono); |
510 |
886
|
pt.setTextSize(fTextSize); |
511 |
886
|
pt.setUnderlineText(false); |
512 |
|
|
513 |
886
|
pt.setColor((bTouchedDownBtnLeft)?iColorLightBkg:iColorBkg); |
514 |
886
|
canvas.drawRoundRect(rectButtonLeft, 2, 2, pt); |
515 |
|
|
516 |
886
|
pt.setColor((bTouchedDownBtnRight)?iColorLightBkg:iColorBkg); |
517 |
886
|
canvas.drawRoundRect(rectButtonRight, 2, 2, pt); |
518 |
|
} |
519 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
|
520 |
886
|
private void drawFrames(Canvas canvas)... |
521 |
|
{ |
522 |
886
|
pt.setColor(iColorSliderBkg); |
523 |
886
|
pt.setStrokeWidth(0); |
524 |
886
|
pt.setAntiAlias(false); |
525 |
|
|
526 |
|
|
527 |
886
|
canvas.drawLine(rectSlider.left, rectSlider.top, rectSlider.left, rectSlider.bottom, pt); |
528 |
886
|
canvas.drawLine(rectSlider.right - 1, rectSlider.top, rectSlider.right - 1, rectSlider.bottom, pt); |
529 |
|
|
530 |
|
|
531 |
886
|
canvas.drawLine(rectCenterBox.left - 1, rectSlider.top, rectCenterBox.left - 1, rectSlider.bottom, pt); |
532 |
886
|
canvas.drawLine(rectCenterBox.right, rectSlider.top, rectCenterBox.right, rectSlider.bottom, pt); |
533 |
|
} |
534 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0,09 |
|
535 |
886
|
private void drawArrowLeft(Canvas canvas)... |
536 |
|
{ |
537 |
886
|
final int iH = 8; |
538 |
886
|
final int iH2 = 4; |
539 |
886
|
final int iV = 14; |
540 |
886
|
final int iX = (int)rectButtonLeft.centerX(); |
541 |
886
|
final int iY = (int)rectButtonLeft.centerY(); |
542 |
886
|
pt.setAntiAlias(true); |
543 |
886
|
pt.setStrokeCap(Paint.Cap.ROUND); |
544 |
886
|
pt.setStrokeWidth(6); |
545 |
886
|
pt.setColor(iColorButtonArrows); |
546 |
886
|
canvas.drawLine(iX - iH, iY, iX + iH2, rectButtonLeft.top + iV, pt); |
547 |
886
|
canvas.drawLine(iX - iH, iY, iX + iH2, rectButtonLeft.bottom - iV, pt); |
548 |
|
} |
549 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0,09 |
|
550 |
886
|
private void drawArrowRight(Canvas canvas)... |
551 |
|
{ |
552 |
886
|
final int iH = 8; |
553 |
886
|
final int iH2 = 4; |
554 |
886
|
final int iV = 14; |
555 |
886
|
final int iX = (int)rectButtonRight.centerX(); |
556 |
886
|
final int iY = (int)rectButtonRight.centerY(); |
557 |
886
|
pt.setAntiAlias(true); |
558 |
886
|
pt.setStrokeCap(Paint.Cap.ROUND); |
559 |
886
|
pt.setStrokeWidth(6); |
560 |
886
|
pt.setColor(iColorButtonArrows); |
561 |
886
|
canvas.drawLine(iX - iH2, rectButtonRight.top + iV, iX + iH, iY, pt); |
562 |
886
|
canvas.drawLine(iX - iH2, rectButtonRight.bottom - iV, iX + iH, iY, pt); |
563 |
|
} |
564 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
565 |
0
|
@Override... |
566 |
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) |
567 |
|
{ |
568 |
0
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
569 |
0
|
invalidate(); |
570 |
|
} |
571 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0,45 |
|
572 |
23
|
private void doClickSliderButton()... |
573 |
|
{ |
574 |
23
|
int iStep = 0; |
575 |
23
|
if (iSliderType == STYPE_MINUTES) |
576 |
13
|
iStep = 5; |
577 |
23
|
if (iSliderType == STYPE_HOURS) |
578 |
10
|
iStep = 1; |
579 |
23
|
if (bTouchedDownBtnLeft) |
580 |
|
{ |
581 |
6
|
int iValue = getValue() - iStep; |
582 |
6
|
setValue(iValue, true); |
583 |
|
} |
584 |
23
|
if (bTouchedDownBtnRight) |
585 |
|
{ |
586 |
17
|
int iValue = getValue() + iStep; |
587 |
17
|
setValue(iValue, true); |
588 |
|
} |
589 |
|
} |
590 |
|
|
|
|
| 83,3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0,38 |
|
591 |
23
|
private boolean touchInSliderButtonsArea(MotionEvent event)... |
592 |
|
{ |
593 |
23
|
clearTouchButtonsFlags(); |
594 |
23
|
if (rectButtonLeft.contains(event.getX(), event.getY())) |
595 |
|
{ |
596 |
6
|
bTouchedDownBtnLeft = true; |
597 |
6
|
return true; |
598 |
|
} |
599 |
17
|
if (rectButtonRight.contains(event.getX(), event.getY())) |
600 |
|
{ |
601 |
17
|
bTouchedDownBtnRight = true; |
602 |
17
|
return true; |
603 |
|
} |
604 |
0
|
return false; |
605 |
|
} |
606 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
607 |
46
|
private void clearTouchButtonsFlags()... |
608 |
|
{ |
609 |
46
|
bTouchedDownBtnLeft = false; |
610 |
46
|
bTouchedDownBtnRight = false; |
611 |
|
} |
612 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
613 |
23
|
private void clearTouchSliderFlags()... |
614 |
|
{ |
615 |
23
|
bTouchedDownSlider = false; |
616 |
|
} |
617 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
618 |
0
|
private boolean touchInSliderArea(MotionEvent event)... |
619 |
|
{ |
620 |
0
|
clearTouchSliderFlags(); |
621 |
0
|
if (rectSlider.contains(event.getX(), event.getY())) |
622 |
|
{ |
623 |
0
|
bTouchedDownSlider = true; |
624 |
0
|
iTouchedSliderPosX = (int)event.getX(); |
625 |
0
|
return true; |
626 |
|
} |
627 |
0
|
return false; |
628 |
|
} |
629 |
|
|
|
|
| 10,5% |
Uncovered Elements: 17 (19) |
Complexity: 5 |
Complexity Density: 0,45 |
|
630 |
25
|
private void touchSliderMoved(MotionEvent event)... |
631 |
|
{ |
632 |
25
|
if (bTouchedDownSlider) |
633 |
|
{ |
634 |
0
|
final int iDelta = (iTouchedSliderPosX - (int)event.getX()); |
635 |
|
|
636 |
0
|
if (Math.abs(iDelta) >= (iBoxWidth * 0.7)) |
637 |
|
{ |
638 |
|
|
639 |
0
|
if (iDelta > 0) |
640 |
0
|
bTouchedDownBtnRight = true; |
641 |
|
|
642 |
0
|
if (iDelta < 0) |
643 |
0
|
bTouchedDownBtnLeft = true; |
644 |
|
|
645 |
0
|
iTouchedSliderPosX = (int)event.getX(); |
646 |
0
|
invalidate(); |
647 |
0
|
doClickSliderButton(); |
648 |
0
|
clearTouchButtonsFlags(); |
649 |
|
} |
650 |
|
} |
651 |
|
} |
652 |
|
|
|
|
| 81,2% |
Uncovered Elements: 6 (32) |
Complexity: 7 |
Complexity Density: 0,32 |
|
653 |
71
|
@Override... |
654 |
|
public boolean onTouchEvent(MotionEvent event) |
655 |
|
{ |
656 |
71
|
boolean bHandled = false; |
657 |
71
|
if (event.getAction() == MotionEvent.ACTION_DOWN) |
658 |
|
{ |
659 |
23
|
if (touchInSliderButtonsArea(event) || touchInSliderArea(event)) |
660 |
|
{ |
661 |
23
|
bHandled = true; |
662 |
23
|
invalidate(); |
663 |
|
} |
664 |
|
} |
665 |
71
|
if (event.getAction() == MotionEvent.ACTION_CANCEL) |
666 |
|
{ |
667 |
0
|
clearTouchButtonsFlags(); |
668 |
0
|
clearTouchSliderFlags(); |
669 |
0
|
bHandled = true; |
670 |
0
|
invalidate(); |
671 |
|
} |
672 |
71
|
if (event.getAction() == MotionEvent.ACTION_UP) |
673 |
|
{ |
674 |
23
|
bHandled = true; |
675 |
23
|
invalidate(); |
676 |
23
|
doClickSliderButton(); |
677 |
23
|
clearTouchButtonsFlags(); |
678 |
23
|
clearTouchSliderFlags(); |
679 |
23
|
invalidate(); |
680 |
|
} |
681 |
71
|
if (event.getAction() == MotionEvent.ACTION_MOVE) |
682 |
|
{ |
683 |
25
|
touchSliderMoved(event); |
684 |
25
|
bHandled = true; |
685 |
25
|
invalidate(); |
686 |
|
} |
687 |
71
|
return bHandled; |
688 |
|
} |
689 |
|
|
690 |
|
} |