1 |
|
|
2 |
|
package pl.magot.vetch.ancal.views; |
3 |
|
|
4 |
|
|
5 |
|
import android.content.*; |
6 |
|
import android.graphics.*; |
7 |
|
import android.view.MotionEvent; |
8 |
|
import android.view.View; |
9 |
|
import android.widget.*; |
10 |
|
import pl.magot.vetch.ancal.*; |
11 |
|
|
|
|
| 55,9% |
Uncovered Elements: 139 (315) |
Complexity: 69 |
Complexity Density: 0,32 |
|
12 |
|
public class ViewDayHourItem extends LinearLayout |
13 |
|
{ |
14 |
|
|
|
|
| 45,5% |
Uncovered Elements: 6 (11) |
Complexity: 4 |
Complexity Density: 0,57 |
|
15 |
|
public class InvisibleView extends View |
16 |
|
{ |
17 |
|
|
18 |
|
private final int iFrame = 2; |
19 |
|
|
20 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
21 |
1
|
public InvisibleView(Context context)... |
22 |
|
{ |
23 |
1
|
super(context); |
24 |
1
|
setFocusable(false); |
25 |
1
|
LinearLayout.LayoutParams layParams = |
26 |
|
new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); |
27 |
1
|
this.setLayoutParams(layParams); |
28 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
29 |
0
|
@Override... |
30 |
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
31 |
|
{ |
32 |
0
|
setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); |
33 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
0
|
private int measureWidth(int measureSpec)... |
35 |
|
{ |
36 |
0
|
return MeasureSpec.getSize(measureSpec); |
37 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0
|
private int measureHeight(int measureSpec)... |
39 |
|
{ |
40 |
0
|
return iFrame + iItemTextHeight + iFrame + iFrame; |
41 |
|
} |
42 |
|
} |
43 |
|
|
44 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
45 |
|
public interface OnItemClick |
46 |
|
{ |
47 |
|
public void OnClick(ViewDayHourItem item); |
48 |
|
} |
49 |
|
|
50 |
|
|
51 |
|
private static final String sStrHour = "00"; |
52 |
|
private static final String sStrTime = "00:00"; |
53 |
|
private static final String sStrUSTimeMark = "mm"; |
54 |
|
private static final String sStrUSTimeAM = "am"; |
55 |
|
private static final String sStrUSTimePM = "pm"; |
56 |
|
|
57 |
|
|
58 |
|
private static final int iSpace = 4; |
59 |
|
private static final int iFrame = 2; |
60 |
|
private static final Typeface tfMono = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); |
61 |
|
private static final float fTextSize = 20; |
62 |
|
|
63 |
|
|
64 |
|
private boolean b24HourMode = false; |
65 |
|
private int iHour = 0; |
66 |
|
private int iCurrentHour = -1; |
67 |
|
protected OnItemClick itemClick = null; |
68 |
|
|
69 |
|
|
70 |
|
private int iSpaceWidthUSTimeMark = 0; |
71 |
|
private int iSpaceWidthHourWithUSTimeMark = 0; |
72 |
|
private int iSpaceWidthTimeWithUSTimeMark = 0; |
73 |
|
private int iSpaceWidthHourArea = 0; |
74 |
|
private int iSpaceWidthTimeArea = 0; |
75 |
|
private int iItemTextHeight = 0; |
76 |
|
|
77 |
|
|
78 |
|
private final static int iColorTime = 0xFFFF8800; |
79 |
|
private final static int iColorMark = 0xFFAA5500; |
80 |
|
private final static int iColorTimeFocused = 0xFFFFCC66; |
81 |
|
private final static int iColorTimeTouch = 0xFF222222; |
82 |
|
private final int iTouchSliderColor = 0xBBFF8800; |
83 |
|
private final int iTouchPatternColor = 0xFF995500; |
84 |
|
|
85 |
|
|
86 |
|
protected Paint mpt = null; |
87 |
|
|
88 |
|
|
89 |
|
private static InvisibleView invView = null; |
90 |
|
private boolean bTouchedDown = false; |
91 |
|
private RectF rtTouchRect = new RectF(); |
92 |
|
private RectF rtTimeTouchRect = new RectF(); |
93 |
|
private RectF rtTouchSliderRect = new RectF(); |
94 |
|
private RectF rectSliderArrow = new RectF(); |
95 |
|
private int iTouchPosX = 0; |
96 |
|
private int iLastTimeMinutes = 0; |
97 |
|
|
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0,15 |
|
99 |
24
|
public ViewDayHourItem(Context context, int iHour, int iItemTextHeight)... |
100 |
|
{ |
101 |
24
|
super(context); |
102 |
|
|
103 |
24
|
this.iHour = iHour; |
104 |
24
|
this.iItemTextHeight = iItemTextHeight; |
105 |
|
|
106 |
24
|
mpt = new Paint(); |
107 |
24
|
mpt.setAntiAlias(true); |
108 |
24
|
mpt.setTextSize(fTextSize); |
109 |
|
|
110 |
24
|
setWillNotDraw(false); |
111 |
|
|
112 |
24
|
setOrientation(LinearLayout.VERTICAL); |
113 |
24
|
LayoutParams lparams = new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); |
114 |
24
|
setLayoutParams(lparams); |
115 |
|
|
116 |
|
|
117 |
24
|
if (invView == null) |
118 |
|
{ |
119 |
1
|
invView = new InvisibleView(context); |
120 |
1
|
invView.setVisibility(View.INVISIBLE); |
121 |
|
} |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
600
|
public void SetItemClick(OnItemClick itemClick) ... |
125 |
|
{ |
126 |
600
|
this.itemClick = itemClick; |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
129 |
624
|
public void SetItemData(boolean b24HourMode, int iSpaceWidthHour, int iSpaceWidthTime, int iSpaceWidthUSTimeMark)... |
130 |
|
{ |
131 |
624
|
this.b24HourMode = b24HourMode; |
132 |
624
|
UpdateTimeFormat(b24HourMode, iSpaceWidthHour, iSpaceWidthTime, iSpaceWidthUSTimeMark); |
133 |
624
|
UpdateHeight(); |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
600
|
public void SetCurrentHour(int iCurrentHour)... |
137 |
|
{ |
138 |
600
|
this.iCurrentHour = iCurrentHour; |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0,67 |
|
141 |
648
|
public void UpdateTimeFormat(boolean b24HourMode, int iSpaceWidthHour, int iSpaceWidthTime, int iSpaceWidthUSTimeMark)... |
142 |
|
{ |
143 |
648
|
this.iSpaceWidthUSTimeMark = (b24HourMode?0:iSpaceWidthUSTimeMark); |
144 |
648
|
this.iSpaceWidthHourWithUSTimeMark = iSpaceWidthHour + (b24HourMode?0:(iSpaceWidthUSTimeMark + iFrame)); |
145 |
648
|
this.iSpaceWidthTimeWithUSTimeMark = iSpaceWidthTime + (b24HourMode?0:(iSpaceWidthUSTimeMark + iFrame)); |
146 |
648
|
this.iSpaceWidthHourArea = iSpace + iSpaceWidthHourWithUSTimeMark + iSpace; |
147 |
648
|
this.iSpaceWidthTimeArea = iSpace + iSpaceWidthTimeWithUSTimeMark + iSpace; |
148 |
648
|
setPadding(iSpaceWidthHourArea, iFrame + iFrame, iFrame, iFrame + iFrame); |
149 |
|
} |
150 |
|
|
151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0
|
public int GetHour()... |
153 |
|
{ |
154 |
0
|
return iHour; |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0
|
public int GetMinutes()... |
158 |
|
{ |
159 |
0
|
return iLastTimeMinutes; |
160 |
|
} |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
162 |
1
|
public static int GetTextHeight(Paint mpt)... |
163 |
|
{ |
164 |
1
|
mpt.setTypeface(null); |
165 |
1
|
mpt.setTextSize(fTextSize); |
166 |
1
|
mpt.setFakeBoldText(true); |
167 |
1
|
return (int)(-mpt.ascent() + mpt.descent()); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
170 |
1
|
public static int GetSpaceWidthHour(Paint mpt)... |
171 |
|
{ |
172 |
1
|
mpt.setTypeface(tfMono); |
173 |
1
|
mpt.setTextSize(fTextSize); |
174 |
1
|
mpt.setFakeBoldText(true); |
175 |
1
|
return (int)mpt.measureText(sStrHour); |
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
178 |
1
|
public static int GetSpaceWidthTime(Paint mpt)... |
179 |
|
{ |
180 |
1
|
mpt.setTypeface(tfMono); |
181 |
1
|
mpt.setTextSize(fTextSize); |
182 |
1
|
mpt.setFakeBoldText(true); |
183 |
1
|
return (int)mpt.measureText(sStrTime); |
184 |
|
} |
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
186 |
1
|
public static int GetSpaceWidthUSTimeMark(Paint mpt)... |
187 |
|
{ |
188 |
1
|
mpt.setTypeface(tfMono); |
189 |
1
|
mpt.setTextSize(fTextSize); |
190 |
1
|
mpt.setFakeBoldText(false); |
191 |
1
|
return (int)mpt.measureText(sStrUSTimeMark); |
192 |
|
} |
193 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
194 |
3692
|
private int GetMinHeight()... |
195 |
|
{ |
196 |
3692
|
return getPaddingTop() + iFrame + iItemTextHeight + iFrame + getPaddingBottom() - 1; |
197 |
|
} |
198 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0,8 |
|
199 |
1224
|
public void UpdateHeight()... |
200 |
|
{ |
201 |
1224
|
this.getLayoutParams().height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
202 |
1224
|
if (getChildCount() == 0) |
203 |
|
{ |
204 |
1203
|
if ((iHour >= 6) && (iHour <= 22)) |
205 |
|
{ |
206 |
860
|
this.getLayoutParams().height = GetMinHeight(); |
207 |
|
} else { |
208 |
343
|
this.getLayoutParams().height = 0; |
209 |
|
} |
210 |
|
} |
211 |
|
} |
212 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
213 |
3493
|
public boolean IsMinimized()... |
214 |
|
{ |
215 |
3493
|
return getHeight() == 0; |
216 |
|
} |
217 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
218 |
0
|
@Override... |
219 |
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) |
220 |
|
{ |
221 |
0
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
222 |
0
|
invalidate(); |
223 |
|
} |
224 |
|
|
|
|
| 82,6% |
Uncovered Elements: 4 (23) |
Complexity: 3 |
Complexity Density: 0,16 |
|
225 |
3493
|
@Override... |
226 |
|
protected void onDraw(Canvas canvas) |
227 |
|
{ |
228 |
3493
|
super.onDraw(canvas); |
229 |
|
|
230 |
3493
|
mpt.setAntiAlias(true); |
231 |
3493
|
mpt.setTextSize(fTextSize); |
232 |
3493
|
mpt.setTypeface(tfMono); |
233 |
3493
|
mpt.setFakeBoldText(true); |
234 |
3493
|
mpt.setShader(null); |
235 |
3493
|
mpt.setUnderlineText(false); |
236 |
|
|
237 |
3493
|
final boolean bIsFocused = hasFocus(); |
238 |
3493
|
final int iHeight = getHeight() - iFrame; |
239 |
3493
|
final int iWidth = getWidth(); |
240 |
3493
|
final int iTimePosY = (- (int)mpt.ascent()) + iFrame + iFrame + 1; |
241 |
|
|
242 |
3493
|
if (!IsMinimized()) |
243 |
|
{ |
244 |
2828
|
GetTouchRectangle(); |
245 |
|
|
246 |
2828
|
DrawBackground(canvas, iWidth, iHeight, bIsFocused); |
247 |
|
|
248 |
2828
|
DrawTime(canvas, iTimePosY, iWidth, iHeight, bIsFocused); |
249 |
|
|
250 |
2828
|
if (bTouchedDown) |
251 |
|
{ |
252 |
0
|
GetTouchSliderRectangle(); |
253 |
0
|
DrawTouchSlider(canvas); |
254 |
0
|
DrawTouchBar(canvas); |
255 |
|
} |
256 |
|
} |
257 |
|
} |
258 |
|
|
|
|
| 72,7% |
Uncovered Elements: 3 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
259 |
2828
|
private void DrawBackground(Canvas canvas, int iWidth, int iHeight, boolean bIsFocused)... |
260 |
|
{ |
261 |
2828
|
mpt.setTypeface(null); |
262 |
2828
|
mpt.setShader(null); |
263 |
|
|
264 |
|
|
265 |
2828
|
if (bTouchedDown) |
266 |
|
{ |
267 |
0
|
mpt.setColor(iColorTime); |
268 |
0
|
canvas.drawRoundRect(rtTouchRect, 3, 3, mpt); |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
2828
|
LinearGradient lGrad = new LinearGradient((getWidth() >> 2), 0, getWidth(), 0, |
273 |
|
0xFFFFFFFF, 0x00FFFFFF, Shader.TileMode.CLAMP); |
274 |
2828
|
mpt.setShader(lGrad); |
275 |
2828
|
canvas.drawLine(0, 0, getWidth(), 0, mpt); |
276 |
|
|
277 |
2828
|
mpt.setShader(null); |
278 |
|
} |
279 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 4 |
Complexity Density: 0,5 |
|
280 |
2828
|
private String GetHourString()... |
281 |
|
{ |
282 |
2828
|
if (b24HourMode) |
283 |
|
{ |
284 |
170
|
return Integer.toString(iHour); |
285 |
|
} else { |
286 |
2658
|
int iDisplayHour = iHour; |
287 |
2658
|
if (iDisplayHour == 0) |
288 |
116
|
iDisplayHour = 12; |
289 |
2658
|
if (iDisplayHour > 12) |
290 |
1082
|
iDisplayHour -= 12; |
291 |
2658
|
return Integer.toString(iDisplayHour); |
292 |
|
} |
293 |
|
} |
294 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
295 |
0
|
private String GetMinutesString()... |
296 |
|
{ |
297 |
0
|
if (iLastTimeMinutes > 9) |
298 |
0
|
return ":" + Integer.toString(iLastTimeMinutes); |
299 |
0
|
return ":0" + Integer.toString(iLastTimeMinutes); |
300 |
|
} |
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
302 |
2658
|
private String GetUSTimeMark()... |
303 |
|
{ |
304 |
2658
|
if (iHour >= 12) |
305 |
1325
|
return sStrUSTimePM; |
306 |
1333
|
return sStrUSTimeAM; |
307 |
|
} |
308 |
|
|
|
|
| 73,2% |
Uncovered Elements: 11 (41) |
Complexity: 7 |
Complexity Density: 0,24 |
|
309 |
2828
|
private void DrawTime(Canvas canvas, int iTimePosY, int iWidth, int iHeight, boolean bIsFocused)... |
310 |
|
{ |
311 |
2828
|
mpt.setAntiAlias(true); |
312 |
2828
|
mpt.setTextSize(fTextSize); |
313 |
2828
|
mpt.setTypeface(tfMono); |
314 |
2828
|
mpt.setFakeBoldText(true); |
315 |
2828
|
mpt.setShader(null); |
316 |
|
|
317 |
2828
|
mpt.setUnderlineText(false); |
318 |
2828
|
if (iCurrentHour == iHour) |
319 |
133
|
mpt.setUnderlineText(true); |
320 |
|
|
321 |
|
|
322 |
2828
|
final String sHour = GetHourString(); |
323 |
2828
|
final int iStrHourWidth = (int)mpt.measureText(sHour); |
324 |
2828
|
final int iTimePosX = iSpaceWidthHourArea - iStrHourWidth - iFrame - iSpaceWidthUSTimeMark - iSpace; |
325 |
2828
|
mpt.setColor((bTouchedDown)?iColorTimeTouch:iColorTime); |
326 |
2828
|
if (bIsFocused) |
327 |
0
|
mpt.setColor(iColorTimeFocused); |
328 |
2828
|
canvas.drawText(sHour, iTimePosX, iTimePosY, mpt); |
329 |
|
|
330 |
|
|
331 |
2828
|
int iMarkPosX = iTimePosX + iStrHourWidth + iFrame; |
332 |
2828
|
if (bTouchedDown) |
333 |
|
{ |
334 |
0
|
final String sMinutes = GetMinutesString(); |
335 |
0
|
final int iStrMinutesWidth = (int)mpt.measureText(sMinutes); |
336 |
0
|
final int iMinutesPosX = iTimePosX + iStrHourWidth; |
337 |
0
|
iMarkPosX = iMinutesPosX + iStrMinutesWidth + iFrame; |
338 |
0
|
canvas.drawText(sMinutes, iMinutesPosX, iTimePosY, mpt); |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
2828
|
if (!b24HourMode) |
343 |
|
{ |
344 |
2658
|
mpt.setFakeBoldText(false); |
345 |
2658
|
mpt.setColor(iColorMark); |
346 |
2658
|
if (bIsFocused) |
347 |
0
|
mpt.setColor(iColorTimeFocused); |
348 |
2658
|
canvas.drawText(GetUSTimeMark(), iMarkPosX, iTimePosY, mpt); |
349 |
|
} |
350 |
|
|
351 |
2828
|
mpt.setUnderlineText(false); |
352 |
|
} |
353 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 2 |
Complexity Density: 0,12 |
|
354 |
0
|
private void DrawTouchSlider(Canvas canvas)... |
355 |
|
{ |
356 |
|
|
357 |
0
|
mpt.setShader(null); |
358 |
0
|
mpt.setColor(iColorTimeTouch); |
359 |
0
|
canvas.drawRoundRect(rtTouchSliderRect, 3, 3, mpt); |
360 |
|
|
361 |
|
|
362 |
0
|
mpt.setColor(iTouchPatternColor); |
363 |
0
|
mpt.setStrokeWidth(4); |
364 |
0
|
mpt.setStrokeCap(Paint.Cap.ROUND); |
365 |
|
|
366 |
0
|
rectSliderArrow.set(rtTouchSliderRect); |
367 |
0
|
final int iArrowWidth = 6; |
368 |
0
|
final int iArrowSpace = 8; |
369 |
0
|
final int iArrowCount = (int)(rtTouchSliderRect.width() / (iArrowWidth + iArrowSpace)); |
370 |
|
|
371 |
0
|
final int iMargin = (int)rtTouchSliderRect.width() - (iArrowCount * (iArrowWidth + iArrowSpace)); |
372 |
0
|
rectSliderArrow.left += iMargin; |
373 |
|
|
374 |
0
|
for (int i = 0; i < iArrowCount; i++) |
375 |
|
{ |
376 |
0
|
DrawTouchSliderArrow(canvas, rectSliderArrow, iArrowWidth); |
377 |
0
|
rectSliderArrow.left += iArrowWidth + iArrowSpace; |
378 |
|
} |
379 |
|
|
380 |
0
|
mpt.setStrokeWidth(0); |
381 |
|
} |
382 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
383 |
0
|
private void DrawTouchSliderArrow(Canvas canvas, RectF rect, int iArrowWidth)... |
384 |
|
{ |
385 |
0
|
int istartX = (int)(rect.left); |
386 |
0
|
int istopX = (int)(rect.left + iArrowWidth); |
387 |
0
|
int iCenter = (int)(rect.top + (rect.height() / 2)); |
388 |
0
|
canvas.drawLine(istartX, rect.top + 5, istopX, iCenter, mpt); |
389 |
0
|
canvas.drawLine(istartX, rect.bottom - 5, istopX, iCenter, mpt); |
390 |
|
} |
391 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
392 |
0
|
private void DrawTouchBar(Canvas canvas)... |
393 |
|
{ |
394 |
|
|
395 |
0
|
mpt.setShader(null); |
396 |
0
|
mpt.setColor(iTouchSliderColor); |
397 |
|
|
398 |
|
|
399 |
0
|
float fMaxRight = rtTouchSliderRect.right; |
400 |
0
|
rtTouchSliderRect.right = iTouchPosX; |
401 |
0
|
if (rtTouchSliderRect.right > fMaxRight) |
402 |
0
|
rtTouchSliderRect.right = fMaxRight; |
403 |
0
|
if (rtTouchSliderRect.right < rtTouchSliderRect.left) |
404 |
0
|
rtTouchSliderRect.right = rtTouchSliderRect.left; |
405 |
|
|
406 |
0
|
canvas.drawRoundRect(rtTouchSliderRect, 2, 2, mpt); |
407 |
|
} |
408 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 6 |
Complexity Density: 0,4 |
|
409 |
0
|
public int CalculateTimeMinutes()... |
410 |
|
{ |
411 |
0
|
RectF rectSlider = GetTouchSliderRectangle(); |
412 |
0
|
if (iTouchPosX > 0) |
413 |
|
{ |
414 |
0
|
if ((iTouchPosX > rectSlider.left) && (iTouchPosX < rectSlider.right)) |
415 |
|
{ |
416 |
0
|
float fRange = rectSlider.right - rectSlider.left; |
417 |
0
|
float fPos = iTouchPosX - rectSlider.left; |
418 |
0
|
float fStep = (fRange / 60); |
419 |
0
|
int iMinutes = (int)(fPos / fStep); |
420 |
0
|
if (iMinutes < 0) |
421 |
0
|
iMinutes = 0; |
422 |
0
|
if (iMinutes > 59) |
423 |
0
|
iMinutes = 59; |
424 |
|
|
425 |
0
|
int iModulo = iMinutes % 5; |
426 |
0
|
iMinutes = iMinutes - iModulo; |
427 |
|
|
428 |
0
|
return iMinutes; |
429 |
|
} |
430 |
|
} |
431 |
0
|
return 0; |
432 |
|
} |
433 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
434 |
0
|
public void doItemClick()... |
435 |
|
{ |
436 |
0
|
if (itemClick != null) |
437 |
0
|
itemClick.OnClick(this); |
438 |
|
} |
439 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
440 |
2828
|
private RectF GetTouchRectangle()... |
441 |
|
{ |
442 |
2828
|
rtTouchRect.set(0, 3, getWidth() - 1, GetMinHeight() - 2); |
443 |
2828
|
return rtTouchRect; |
444 |
|
} |
445 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
446 |
4
|
private RectF GetTimeTouchRectangle()... |
447 |
|
{ |
448 |
4
|
rtTimeTouchRect.set(iFrame, 2, iSpaceWidthTimeArea - iFrame, GetMinHeight() - 2); |
449 |
4
|
return rtTimeTouchRect; |
450 |
|
} |
451 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
452 |
0
|
private RectF GetTouchSliderRectangle()... |
453 |
|
{ |
454 |
0
|
rtTouchSliderRect.set(GetTouchRectangle()); |
455 |
0
|
rtTouchSliderRect.inset(2, 2); |
456 |
0
|
rtTouchSliderRect.left = iSpaceWidthTimeArea + iSpace + iSpace; |
457 |
0
|
rtTouchSliderRect.right = rtTouchSliderRect.right - iSpace - iSpace - iSpace; |
458 |
0
|
return rtTouchSliderRect; |
459 |
|
} |
460 |
|
|
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
461 |
4
|
private boolean TouchInTimeArea(MotionEvent event)... |
462 |
|
{ |
463 |
4
|
RectF rect = GetTimeTouchRectangle(); |
464 |
4
|
if (rect.contains(event.getX(), event.getY())) |
465 |
0
|
return true; |
466 |
4
|
return false; |
467 |
|
} |
468 |
|
|
|
|
| 31,6% |
Uncovered Elements: 26 (38) |
Complexity: 6 |
Complexity Density: 0,21 |
|
469 |
4
|
@Override... |
470 |
|
public boolean onTouchEvent(MotionEvent event) |
471 |
|
{ |
472 |
4
|
boolean bHandled = false; |
473 |
4
|
if (event.getAction() == MotionEvent.ACTION_DOWN) |
474 |
|
{ |
475 |
4
|
if (TouchInTimeArea(event)) |
476 |
|
{ |
477 |
0
|
bHandled = true; |
478 |
0
|
bTouchedDown = true; |
479 |
0
|
iLastTimeMinutes = 0; |
480 |
0
|
iTouchPosX = 0; |
481 |
0
|
EnableInnerViewSpace(true); |
482 |
0
|
invalidate(); |
483 |
0
|
Utils.startAlphaAnimIn(ViewDayHourItem.this); |
484 |
|
} |
485 |
|
} |
486 |
4
|
if (event.getAction() == MotionEvent.ACTION_CANCEL) |
487 |
|
{ |
488 |
0
|
bHandled = true; |
489 |
0
|
bTouchedDown = false; |
490 |
0
|
iTouchPosX = 0; |
491 |
0
|
EnableInnerViewSpace(false); |
492 |
0
|
invalidate(); |
493 |
|
} |
494 |
4
|
if (event.getAction() == MotionEvent.ACTION_UP) |
495 |
|
{ |
496 |
0
|
bHandled = true; |
497 |
0
|
bTouchedDown = false; |
498 |
0
|
EnableInnerViewSpace(false); |
499 |
0
|
invalidate(); |
500 |
0
|
doItemClick(); |
501 |
|
} |
502 |
4
|
if (event.getAction() == MotionEvent.ACTION_MOVE) |
503 |
|
{ |
504 |
0
|
bHandled = true; |
505 |
0
|
iTouchPosX = (int)event.getX(); |
506 |
0
|
iLastTimeMinutes = CalculateTimeMinutes(); |
507 |
0
|
invalidate(); |
508 |
|
} |
509 |
4
|
return bHandled; |
510 |
|
} |
511 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
512 |
0
|
private void EnableInnerViewSpace(boolean bEnable)... |
513 |
|
{ |
514 |
0
|
if (bEnable) |
515 |
|
{ |
516 |
0
|
this.addView(invView, 0); |
517 |
|
} else { |
518 |
0
|
this.removeView(invView); |
519 |
|
} |
520 |
|
} |
521 |
|
|
522 |
|
} |