1 |
|
|
2 |
|
package pl.magot.vetch.ancal.views; |
3 |
|
|
4 |
|
|
5 |
|
import java.util.Map; |
6 |
|
import pl.magot.vetch.ancal.Utils; |
7 |
|
import android.content.*; |
8 |
|
import android.util.AttributeSet; |
9 |
|
import android.view.View; |
10 |
|
import android.view.KeyEvent; |
11 |
|
import android.view.MotionEvent; |
12 |
|
import android.graphics.*; |
13 |
|
|
14 |
|
|
|
|
| 78,5% |
Uncovered Elements: 35 (163) |
Complexity: 37 |
Complexity Density: 0,33 |
|
15 |
|
public class ViewTodayItemHeader extends View |
16 |
|
{ |
17 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
18 |
|
public enum ViewType { Appointments, Tasks, Notes }; |
19 |
|
|
20 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
21 |
|
public interface OnHeaderItemClick |
22 |
|
{ |
23 |
|
public void OnClick(View v, ViewTodayItemHeader.ViewType type); |
24 |
|
} |
25 |
|
|
26 |
|
|
27 |
|
private Paint mpt = null; |
28 |
|
private ViewType viewType = ViewType.Appointments; |
29 |
|
private String sText = ""; |
30 |
|
private String sTextInfo = ""; |
31 |
|
private OnHeaderItemClick itemClick = null; |
32 |
|
private boolean bTouchedDown = false; |
33 |
|
|
34 |
|
|
35 |
|
private final int iBottomLineSpace = 4; |
36 |
|
private static final int iconW = 4; |
37 |
|
private static final int iconH = 4; |
38 |
|
private static final int iIconLeft = 6; |
39 |
|
private final float fTextSize = 20; |
40 |
|
|
41 |
|
|
42 |
|
private final int iFocusedTextColor = 0xFF222222; |
43 |
|
private final int iTitleTextColor = 0xFF778899; |
44 |
|
private final int iTitleTextShadowColor = 0x88AAAAAA; |
45 |
|
private final int iInfoTextColor = 0xFF777777; |
46 |
|
|
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
48 |
3
|
public ViewTodayItemHeader(Context context)... |
49 |
|
{ |
50 |
3
|
super(context); |
51 |
3
|
Init(context); |
52 |
|
} |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
54 |
0
|
@SuppressWarnings("all")... |
55 |
|
public ViewTodayItemHeader(Context context, AttributeSet attrs, Map inflateParams) |
56 |
|
{ |
57 |
0
|
super(context, attrs); |
58 |
0
|
Init(context); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
61 |
3
|
private void Init(Context context)... |
62 |
|
{ |
63 |
3
|
mpt = new Paint(); |
64 |
3
|
mpt.setAntiAlias(true); |
65 |
3
|
mpt.setTextSize(fTextSize); |
66 |
3
|
mpt.setColor(0xFF000000); |
67 |
|
|
68 |
3
|
SetType(ViewType.Appointments); |
69 |
|
|
70 |
3
|
setFocusable(true); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
6
|
public void SetType(ViewType viewType)... |
74 |
|
{ |
75 |
6
|
this.viewType = viewType; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
3
|
public void SetItemClick(OnHeaderItemClick itemClick) ... |
79 |
|
{ |
80 |
3
|
this.itemClick = itemClick; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
324
|
@Override... |
84 |
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
85 |
|
{ |
86 |
324
|
setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
1081
|
public int TextHeight()... |
90 |
|
{ |
91 |
1081
|
return (int)(-mpt.ascent() + mpt.descent()); |
92 |
|
} |
93 |
|
|
|
|
| 53,8% |
Uncovered Elements: 6 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
94 |
324
|
private int measureWidth(int measureSpec)... |
95 |
|
{ |
96 |
324
|
int result = 0; |
97 |
324
|
int specMode = MeasureSpec.getMode(measureSpec); |
98 |
324
|
int specSize = MeasureSpec.getSize(measureSpec); |
99 |
|
|
100 |
324
|
if (specMode == MeasureSpec.EXACTLY) |
101 |
|
{ |
102 |
324
|
result = specSize; |
103 |
|
} else { |
104 |
0
|
result = (int) mpt.measureText(sText) + getPaddingLeft() + getPaddingRight(); |
105 |
0
|
if (specMode == MeasureSpec.AT_MOST) |
106 |
|
{ |
107 |
0
|
result = Math.min(result, specSize); |
108 |
|
} |
109 |
|
} |
110 |
324
|
return result; |
111 |
|
} |
112 |
|
|
|
|
| 73,3% |
Uncovered Elements: 4 (15) |
Complexity: 3 |
Complexity Density: 0,27 |
|
113 |
324
|
private int measureHeight(int measureSpec)... |
114 |
|
{ |
115 |
324
|
int result = 0; |
116 |
324
|
int specMode = MeasureSpec.getMode(measureSpec); |
117 |
324
|
int specSize = MeasureSpec.getSize(measureSpec); |
118 |
324
|
if (specMode == MeasureSpec.EXACTLY) |
119 |
|
{ |
120 |
0
|
result = specSize; |
121 |
|
} else { |
122 |
324
|
float iTextSize = TextHeight(); |
123 |
324
|
float iHeight = Math.max(iTextSize, iconH); |
124 |
324
|
result = getPaddingTop() + (int)iHeight + iBottomLineSpace + 1 + getPaddingBottom(); |
125 |
324
|
if (specMode == MeasureSpec.AT_MOST) |
126 |
|
{ |
127 |
0
|
result = Math.min(result, specSize); |
128 |
|
} |
129 |
|
} |
130 |
324
|
return result; |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
133 |
0
|
@Override... |
134 |
|
public boolean onKeyDown(int keyCode, KeyEvent event) |
135 |
|
{ |
136 |
0
|
boolean bResult = super.onKeyDown(keyCode, event); |
137 |
0
|
if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER) || (keyCode == KeyEvent.KEYCODE_ENTER)) |
138 |
|
{ |
139 |
0
|
doItemClick(); |
140 |
|
} |
141 |
0
|
return bResult; |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
144 |
0
|
@Override... |
145 |
|
public boolean onKeyUp(int keyCode, KeyEvent event) |
146 |
|
{ |
147 |
0
|
boolean bResult = super.onKeyUp(keyCode, event); |
148 |
0
|
return bResult; |
149 |
|
} |
150 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
151 |
9
|
public void doItemClick()... |
152 |
|
{ |
153 |
9
|
if (itemClick != null) |
154 |
9
|
itemClick.OnClick(this, viewType); |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
157 |
0
|
public void DrawTestRect(Canvas canvas)... |
158 |
|
{ |
159 |
0
|
Rect rt = new Rect(0, 0, getWidth(), getHeight()); |
160 |
0
|
mpt.setColor(0x22000000); |
161 |
0
|
canvas.drawRect(rt, mpt); |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
164 |
0
|
@Override... |
165 |
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) |
166 |
|
{ |
167 |
0
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
168 |
0
|
invalidate(); |
169 |
|
} |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
171 |
757
|
protected void DrawBackground(Canvas canvas)... |
172 |
|
{ |
173 |
757
|
if (IsViewFocused()) |
174 |
|
{ |
175 |
14
|
LinearGradient lGradBkg = new LinearGradient(0, 0, 0, getHeight(), |
176 |
|
0xFFDDDDDD, 0xFF444444, Shader.TileMode.CLAMP); |
177 |
14
|
mpt.setShader(lGradBkg); |
178 |
14
|
RectF rt = new RectF(0F, 0F, getWidth(), getHeight()); |
179 |
14
|
canvas.drawRoundRect(rt, 2, 2, mpt); |
180 |
|
} |
181 |
|
} |
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
183 |
1713
|
public static int GetTextPosX()... |
184 |
|
{ |
185 |
1713
|
return iIconLeft + (iconW + (iconW >> 1)) + iIconLeft; |
186 |
|
} |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (46) |
Complexity: 6 |
Complexity Density: 0,17 |
|
188 |
757
|
@Override... |
189 |
|
protected void onDraw(Canvas canvas) |
190 |
|
{ |
191 |
757
|
super.onDraw(canvas); |
192 |
|
|
193 |
757
|
DrawBackground(canvas); |
194 |
|
|
195 |
757
|
final int iTextPosX = GetTextPosX(); |
196 |
757
|
int iposLineY = getHeight() - 1 - getPaddingBottom(); |
197 |
|
|
198 |
757
|
mpt.setStrokeWidth(0); |
199 |
757
|
mpt.setStyle(Paint.Style.FILL); |
200 |
|
|
201 |
|
|
202 |
757
|
if (!IsViewFocused()) |
203 |
|
{ |
204 |
743
|
LinearGradient lGrad = new LinearGradient((getWidth() >> 2), 0, getWidth(), 0, |
205 |
|
0xFFFFFFFF, 0x00FFFFFF, Shader.TileMode.CLAMP); |
206 |
743
|
mpt.setShader(lGrad); |
207 |
743
|
canvas.drawLine(iTextPosX, iposLineY, getWidth(), iposLineY, mpt); |
208 |
|
} |
209 |
757
|
mpt.setShader(null); |
210 |
|
|
211 |
|
|
212 |
757
|
mpt.setColor(0xFF222222); |
213 |
757
|
canvas.drawCircle(iIconLeft + iconW, (getHeight() >> 1), iconH + 1, mpt); |
214 |
|
|
215 |
757
|
RadialGradient radGrad = new RadialGradient(iIconLeft + iconW, (getHeight() >> 1), iconH, |
216 |
|
0xFF888888, 0xFF666666, Shader.TileMode.CLAMP); |
217 |
757
|
mpt.setShader(radGrad); |
218 |
|
|
219 |
757
|
canvas.drawCircle(iIconLeft + iconW, (getHeight() >> 1), iconH, mpt); |
220 |
757
|
mpt.setShader(null); |
221 |
|
|
222 |
|
|
223 |
757
|
mpt.setLinearText(true); |
224 |
757
|
mpt.setFakeBoldText(true); |
225 |
|
|
226 |
757
|
final int iTextPosY = TextHeight(); |
227 |
|
|
228 |
|
|
229 |
757
|
if (IsViewFocused()) |
230 |
|
{ |
231 |
14
|
mpt.setColor(iTitleTextShadowColor); |
232 |
14
|
canvas.drawText(sText, iTextPosX + 1, iTextPosY + 1, mpt); |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
757
|
if (IsViewFocused()) |
237 |
|
{ |
238 |
14
|
mpt.setColor(iFocusedTextColor); |
239 |
|
} else { |
240 |
743
|
mpt.setColor(iTitleTextColor); |
241 |
|
} |
242 |
757
|
canvas.drawText(sText, iTextPosX, iTextPosY, mpt); |
243 |
|
|
244 |
|
|
245 |
757
|
final int iposX = getWidth() - (int)mpt.measureText(sTextInfo) - iIconLeft; |
246 |
757
|
mpt.setUnderlineText(false); |
247 |
|
|
248 |
|
|
249 |
757
|
if (IsViewFocused()) |
250 |
|
{ |
251 |
14
|
mpt.setColor(iTitleTextShadowColor); |
252 |
14
|
canvas.drawText(sTextInfo, iposX + 1, iTextPosY + 1, mpt); |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
757
|
if (IsViewFocused()) |
257 |
|
{ |
258 |
14
|
mpt.setColor(iFocusedTextColor); |
259 |
|
} else { |
260 |
743
|
mpt.setColor(iInfoTextColor); |
261 |
|
} |
262 |
757
|
canvas.drawText(sTextInfo, iposX, iTextPosY, mpt); |
263 |
|
} |
264 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
265 |
3
|
public void SetText(String value)... |
266 |
|
{ |
267 |
3
|
sText = value; |
268 |
3
|
requestLayout(); |
269 |
3
|
invalidate(); |
270 |
|
} |
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
272 |
78
|
public void SetInfoText(String value)... |
273 |
|
{ |
274 |
78
|
sTextInfo = value; |
275 |
78
|
requestLayout(); |
276 |
78
|
invalidate(); |
277 |
|
} |
278 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
279 |
4542
|
public boolean IsViewFocused()... |
280 |
|
{ |
281 |
4542
|
return (this.isFocused() || bTouchedDown); |
282 |
|
} |
283 |
|
|
|
|
| 81,8% |
Uncovered Elements: 4 (22) |
Complexity: 4 |
Complexity Density: 0,25 |
|
284 |
23
|
@Override... |
285 |
|
public boolean onTouchEvent(MotionEvent event) |
286 |
|
{ |
287 |
23
|
boolean bHandled = false; |
288 |
23
|
if (event.getAction() == MotionEvent.ACTION_DOWN) |
289 |
|
{ |
290 |
9
|
bHandled = true; |
291 |
9
|
bTouchedDown = true; |
292 |
9
|
invalidate(); |
293 |
9
|
Utils.startAlphaAnimIn(ViewTodayItemHeader.this); |
294 |
|
} |
295 |
23
|
if (event.getAction() == MotionEvent.ACTION_CANCEL) |
296 |
|
{ |
297 |
0
|
bHandled = true; |
298 |
0
|
bTouchedDown = false; |
299 |
0
|
invalidate(); |
300 |
|
} |
301 |
23
|
if (event.getAction() == MotionEvent.ACTION_UP) |
302 |
|
{ |
303 |
9
|
bHandled = true; |
304 |
9
|
bTouchedDown = false; |
305 |
9
|
invalidate(); |
306 |
9
|
doItemClick(); |
307 |
|
} |
308 |
23
|
return bHandled; |
309 |
|
} |
310 |
|
|
311 |
|
} |