1 |
|
|
2 |
|
package pl.magot.vetch.ancal.views; |
3 |
|
|
4 |
|
|
5 |
|
import android.content.Context; |
6 |
|
import android.graphics.Canvas; |
7 |
|
import android.graphics.Paint; |
8 |
|
import android.graphics.Rect; |
9 |
|
import android.graphics.Typeface; |
10 |
|
import android.view.*; |
11 |
|
|
12 |
|
|
|
|
| 81,6% |
Uncovered Elements: 29 (158) |
Complexity: 35 |
Complexity Density: 0,34 |
|
13 |
|
public class ViewTodayItemAppointment extends ViewTodayItem |
14 |
|
{ |
15 |
|
|
16 |
|
private final static int iColorTime = 0xFFFF8800; |
17 |
|
private final static int iColorTimeFocused = 0xFFFFCC66; |
18 |
|
private final static int iColorMark = 0xFFAA5500; |
19 |
|
private static final String sStrTime = "00:00"; |
20 |
|
private static final String sStrMinutes = ":00"; |
21 |
|
private static final String sStrUSTimeMark = "mm"; |
22 |
|
private static final String sStrUSTimeAM = "am"; |
23 |
|
private static final String sStrUSTimePM = "pm"; |
24 |
|
private final static Typeface tfMono = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); |
25 |
|
|
26 |
|
|
27 |
|
private int iSpaceWidthUSTimeMark = 0; |
28 |
|
private int iSpaceWidthTimeArea = 0; |
29 |
|
private int iSpaceWidthTime = 0; |
30 |
|
|
31 |
|
|
32 |
|
private int iHour = 0; |
33 |
|
private int iMinutes = 0; |
34 |
|
private boolean b24HourMode = false; |
35 |
|
private boolean bAlarm = false; |
36 |
|
private boolean bRepeat = false; |
37 |
|
private boolean bShowMinutesOnly = false; |
38 |
|
|
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
51
|
public ViewTodayItemAppointment(Context context)... |
41 |
|
{ |
42 |
51
|
super(context); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
45 |
51
|
public void SetItemData(String sText, boolean bAlarm, boolean bRepeat)... |
46 |
|
{ |
47 |
51
|
SetText(sText); |
48 |
51
|
this.bAlarm = bAlarm; |
49 |
51
|
this.bRepeat = bRepeat; |
50 |
|
} |
51 |
|
|
|
|
| 93,3% |
Uncovered Elements: 1 (15) |
Complexity: 4 |
Complexity Density: 0,44 |
|
52 |
51
|
public void SetItemTime(int iHour, int iMinutes, boolean bShowMinutesOnly, boolean b24HourMode, int iSpaceWidthTime, int iSpaceWidthMinutes, int iSpaceWidthUSTimeMark)... |
53 |
|
{ |
54 |
51
|
this.iHour = iHour; |
55 |
51
|
this.iMinutes = iMinutes; |
56 |
51
|
this.b24HourMode = b24HourMode; |
57 |
51
|
this.bShowMinutesOnly = bShowMinutesOnly; |
58 |
51
|
this.iSpaceWidthUSTimeMark = (b24HourMode?0:(iFrame + iSpaceWidthUSTimeMark)); |
59 |
51
|
if (bShowMinutesOnly) |
60 |
|
{ |
61 |
24
|
this.iSpaceWidthTime = iSpaceWidthMinutes; |
62 |
|
} else { |
63 |
27
|
this.iSpaceWidthTime = iSpaceWidthTime + (b24HourMode?0:(iFrame + iSpaceWidthUSTimeMark)); |
64 |
|
} |
65 |
51
|
this.iSpaceWidthTimeArea = iSpace + this.iSpaceWidthTime + iSpace; |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
68 |
2
|
public static int GetSpaceWidthTime(Paint mpt)... |
69 |
|
{ |
70 |
2
|
mpt.setTypeface(tfMono); |
71 |
2
|
mpt.setTextSize(ViewTodayItem.fTextSize); |
72 |
2
|
mpt.setFakeBoldText(true); |
73 |
2
|
return (int)mpt.measureText(sStrTime); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
76 |
2
|
public static int GetSpaceWidthMinutes(Paint mpt)... |
77 |
|
{ |
78 |
2
|
mpt.setTypeface(tfMono); |
79 |
2
|
mpt.setTextSize(ViewTodayItem.fTextSize); |
80 |
2
|
mpt.setFakeBoldText(true); |
81 |
2
|
return (int)mpt.measureText(sStrMinutes); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
84 |
2
|
public static int GetSpaceWidthUSTimeMark(Paint mpt)... |
85 |
|
{ |
86 |
2
|
mpt.setTypeface(tfMono); |
87 |
2
|
mpt.setTextSize(ViewTodayItem.fTextSize); |
88 |
2
|
mpt.setFakeBoldText(false); |
89 |
2
|
return (int)mpt.measureText(sStrUSTimeMark); |
90 |
|
} |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0,62 |
|
92 |
0
|
@Override... |
93 |
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) |
94 |
|
{ |
95 |
0
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
96 |
|
|
97 |
|
|
98 |
0
|
ViewParent parent = getParent(); |
99 |
0
|
if (parent != null) |
100 |
|
{ |
101 |
0
|
if (parent instanceof ViewDayHourItem) |
102 |
|
{ |
103 |
0
|
try |
104 |
|
{ |
105 |
0
|
ViewDayHourItem item = (ViewDayHourItem)parent; |
106 |
0
|
if (item != null) |
107 |
0
|
item.invalidate(); |
108 |
|
} catch (Exception e) { |
109 |
|
} |
110 |
|
} |
111 |
|
} |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 6 |
Complexity Density: 0,19 |
|
114 |
586
|
@Override... |
115 |
|
protected void onDraw(Canvas canvas) |
116 |
|
{ |
117 |
586
|
super.onDraw(canvas); |
118 |
|
|
119 |
586
|
mpt.setAntiAlias(true); |
120 |
586
|
mpt.setTextSize(fTextSize); |
121 |
586
|
mpt.setTypeface(tfMono); |
122 |
586
|
mpt.setFakeBoldText(true); |
123 |
586
|
mpt.setShader(null); |
124 |
586
|
mpt.setUnderlineText(false); |
125 |
|
|
126 |
586
|
final boolean bIsFocused = hasFocus(); |
127 |
586
|
final int iHeight = getHeight() - iFrame; |
128 |
586
|
final int iWidth = getWidth(); |
129 |
586
|
final int iTimePosY = iMargin - (int)mpt.ascent(); |
130 |
|
|
131 |
|
|
132 |
586
|
DrawTime(canvas, iTimePosY, iWidth, iHeight, bIsFocused); |
133 |
|
|
134 |
|
|
135 |
586
|
int iTextClipWidth = getWidth() - iSpace; |
136 |
586
|
if (bAlarm) |
137 |
288
|
iTextClipWidth -= iIconW; |
138 |
586
|
if (bRepeat) |
139 |
448
|
iTextClipWidth -= iIconW; |
140 |
|
|
141 |
586
|
final int iHeaderOffsetX = (bShowMinutesOnly?0:ViewTodayItemHeader.GetTextPosX()); |
142 |
586
|
final int iTextPosX = iHeaderOffsetX + iSpaceWidthTimeArea; |
143 |
|
|
144 |
586
|
mpt.setTypeface(null); |
145 |
586
|
DrawItemText(canvas, iTextPosX, iTimePosY, iTextClipWidth, iColorTextActive_enabled); |
146 |
|
|
147 |
|
|
148 |
586
|
int iIconX = getWidth(); |
149 |
586
|
int iIconY = (this.getHeight() >> 1) - (iIconH >> 1); |
150 |
|
|
151 |
|
|
152 |
586
|
if (bRepeat) |
153 |
|
{ |
154 |
448
|
iIconX -= iIconW; |
155 |
448
|
iconRepeat.setBounds(iIconX, iIconY, iIconX + iIconW, iIconY + iIconH); |
156 |
448
|
iconRepeat.draw(canvas); |
157 |
|
} |
158 |
|
|
159 |
586
|
if (bAlarm) |
160 |
|
{ |
161 |
288
|
iIconX -= iIconW; |
162 |
288
|
iconAlarm.setBounds(iIconX, iIconY, iIconX + iIconW, iIconY + iIconH); |
163 |
288
|
iconAlarm.draw(canvas); |
164 |
|
} |
165 |
|
} |
166 |
|
|
|
|
| 72,2% |
Uncovered Elements: 5 (18) |
Complexity: 5 |
Complexity Density: 0,5 |
|
167 |
586
|
private String GetTimeString()... |
168 |
|
{ |
169 |
586
|
if (bShowMinutesOnly) |
170 |
|
{ |
171 |
271
|
return GetMinutesString(); |
172 |
|
} else { |
173 |
315
|
if (b24HourMode) |
174 |
|
{ |
175 |
0
|
return Integer.toString(iHour) + GetMinutesString(); |
176 |
|
} else { |
177 |
315
|
int iDisplayHour = iHour; |
178 |
315
|
if (iDisplayHour == 0) |
179 |
315
|
iDisplayHour = 12; |
180 |
315
|
if (iDisplayHour > 12) |
181 |
0
|
iDisplayHour -= 12; |
182 |
315
|
return Integer.toString(iDisplayHour) + GetMinutesString(); |
183 |
|
} |
184 |
|
} |
185 |
|
} |
186 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
187 |
586
|
private String GetMinutesString()... |
188 |
|
{ |
189 |
586
|
if (iMinutes > 9) |
190 |
0
|
return ":" + Integer.toString(iMinutes); |
191 |
586
|
return ":0" + Integer.toString(iMinutes); |
192 |
|
} |
193 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
194 |
315
|
private String GetUSTimeMark()... |
195 |
|
{ |
196 |
315
|
if (iHour >= 12) |
197 |
0
|
return sStrUSTimePM; |
198 |
315
|
return sStrUSTimeAM; |
199 |
|
} |
200 |
|
|
|
|
| 87,5% |
Uncovered Elements: 4 (32) |
Complexity: 6 |
Complexity Density: 0,25 |
|
201 |
586
|
private void DrawTime(Canvas canvas, int iTimePosY, int iWidth, int iHeight, boolean bIsFocused)... |
202 |
|
{ |
203 |
586
|
mpt.setAntiAlias(true); |
204 |
586
|
mpt.setTextSize(fTextSize); |
205 |
586
|
mpt.setTypeface(tfMono); |
206 |
586
|
mpt.setFakeBoldText(true); |
207 |
586
|
mpt.setShader(null); |
208 |
586
|
mpt.setUnderlineText(false); |
209 |
|
|
210 |
|
|
211 |
586
|
final String sTime = GetTimeString(); |
212 |
586
|
final int iStrTimeWidth = (int)mpt.measureText(sTime); |
213 |
|
|
214 |
586
|
int iTimePosX = 0; |
215 |
586
|
if (bShowMinutesOnly) |
216 |
|
{ |
217 |
271
|
iTimePosX = iSpace; |
218 |
|
} else { |
219 |
315
|
iTimePosX = iSpaceWidthTimeArea - iStrTimeWidth - iSpaceWidthUSTimeMark - iSpace; |
220 |
315
|
iTimePosX += ViewTodayItemHeader.GetTextPosX(); |
221 |
|
} |
222 |
|
|
223 |
586
|
mpt.setColor(iColorTime); |
224 |
586
|
if (bIsFocused) |
225 |
0
|
mpt.setColor(iColorTimeFocused); |
226 |
|
|
227 |
586
|
canvas.drawText(sTime, iTimePosX, iTimePosY, mpt); |
228 |
|
|
229 |
|
|
230 |
586
|
int iMarkPosX = iTimePosX + iStrTimeWidth + iFrame; |
231 |
|
|
232 |
|
|
233 |
586
|
if ((!b24HourMode) && (!bShowMinutesOnly)) |
234 |
|
{ |
235 |
315
|
mpt.setFakeBoldText(false); |
236 |
315
|
mpt.setColor(iColorMark); |
237 |
315
|
if (bIsFocused) |
238 |
0
|
mpt.setColor(iColorTimeFocused); |
239 |
315
|
canvas.drawText(GetUSTimeMark(), iMarkPosX, iTimePosY, mpt); |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
|
} |