1 |
|
|
2 |
|
package pl.magot.vetch.ancal.views; |
3 |
|
|
4 |
|
|
5 |
|
import java.util.Map; |
6 |
|
import pl.magot.vetch.ancal.R; |
7 |
|
import pl.magot.vetch.ancal.Utils; |
8 |
|
import android.content.*; |
9 |
|
import android.util.AttributeSet; |
10 |
|
import android.view.MotionEvent; |
11 |
|
import android.view.View; |
12 |
|
import android.view.KeyEvent; |
13 |
|
import android.graphics.*; |
14 |
|
import android.graphics.drawable.Drawable; |
15 |
|
|
16 |
|
|
|
|
| 72,2% |
Uncovered Elements: 44 (158) |
Complexity: 39 |
Complexity Density: 0,38 |
|
17 |
|
public class ViewTodayItem extends View |
18 |
|
{ |
19 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
20 |
|
public interface OnItemClick |
21 |
|
{ |
22 |
|
public void OnClick(ViewTodayItem item); |
23 |
|
} |
24 |
|
|
25 |
|
|
26 |
|
protected static final int iIconW = 22; |
27 |
|
protected static final int iIconH = 22; |
28 |
|
protected static final int iMargin = 1; |
29 |
|
protected static final int iSpace = 4; |
30 |
|
protected static final int iFrame = 2; |
31 |
|
protected static final float fTextSize = 20; |
32 |
|
protected final static int iColorTextActive_enabled = 0xFFEEEEEE; |
33 |
|
protected final static int iColorTextActive_disabled = 0xFF999999; |
34 |
|
|
35 |
|
private long lRowId = -1; |
36 |
|
protected Paint mpt = null; |
37 |
|
private Rect rectClipText = new Rect(); |
38 |
|
private String sText = ""; |
39 |
|
protected OnItemClick itemClick = null; |
40 |
|
private boolean bTouchedDown = false; |
41 |
|
protected static Drawable iconAlarm = null; |
42 |
|
protected static Drawable iconRepeat = null; |
43 |
|
protected static Drawable iconDone = null; |
44 |
|
protected static Drawable iconUnDone = null; |
45 |
|
|
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
47 |
88
|
public ViewTodayItem(Context context)... |
48 |
|
{ |
49 |
88
|
super(context); |
50 |
88
|
Init(context); |
51 |
|
} |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
53 |
0
|
@SuppressWarnings("all")... |
54 |
|
public ViewTodayItem(Context context, AttributeSet attrs, Map inflateParams) |
55 |
|
{ |
56 |
0
|
super(context, attrs); |
57 |
0
|
Init(context); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 5 |
Complexity Density: 0,42 |
|
60 |
88
|
private void Init(Context context)... |
61 |
|
{ |
62 |
88
|
mpt = new Paint(); |
63 |
88
|
mpt.setAntiAlias(true); |
64 |
88
|
mpt.setTextSize(fTextSize); |
65 |
88
|
setFocusable(true); |
66 |
|
|
67 |
88
|
if (iconAlarm == null) |
68 |
1
|
iconAlarm = getResources().getDrawable(R.drawable.iconitemalarm); |
69 |
88
|
if (iconRepeat == null) |
70 |
1
|
iconRepeat = getResources().getDrawable(R.drawable.iconitemrepeat); |
71 |
88
|
if (iconDone == null) |
72 |
1
|
iconDone = getResources().getDrawable(R.drawable.iconitemdone); |
73 |
88
|
if (iconUnDone == null) |
74 |
1
|
iconUnDone = getResources().getDrawable(R.drawable.iconitemundone); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
88
|
public void SetItemClick(OnItemClick itemClick) ... |
78 |
|
{ |
79 |
88
|
this.itemClick = itemClick; |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
352
|
@Override... |
83 |
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
84 |
|
{ |
85 |
352
|
setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
352
|
public int TextHeight()... |
89 |
|
{ |
90 |
352
|
return (int)(-mpt.ascent() + mpt.descent()); |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
93 |
0
|
public static int GetMinItemHeight(int iPaddingTop, int iPaddingBottom)... |
94 |
|
{ |
95 |
0
|
Paint pt = new Paint(); |
96 |
0
|
pt.setAntiAlias(true); |
97 |
0
|
pt.setTextSize(fTextSize); |
98 |
0
|
float iHeight = (int)(-pt.ascent() + pt.descent()); |
99 |
0
|
return iPaddingTop + iMargin + (int)iHeight + iMargin + iMargin + iPaddingBottom; |
100 |
|
} |
101 |
|
|
|
|
| 53,8% |
Uncovered Elements: 6 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
102 |
352
|
private int measureWidth(int measureSpec)... |
103 |
|
{ |
104 |
352
|
int result = 0; |
105 |
352
|
int specMode = MeasureSpec.getMode(measureSpec); |
106 |
352
|
int specSize = MeasureSpec.getSize(measureSpec); |
107 |
|
|
108 |
352
|
if (specMode == MeasureSpec.EXACTLY) |
109 |
|
{ |
110 |
352
|
result = specSize; |
111 |
|
} else { |
112 |
0
|
result = (int) mpt.measureText(sText) + getPaddingLeft() + getPaddingRight(); |
113 |
0
|
if (specMode == MeasureSpec.AT_MOST) |
114 |
|
{ |
115 |
0
|
result = Math.min(result, specSize); |
116 |
|
} |
117 |
|
} |
118 |
352
|
return result; |
119 |
|
} |
120 |
|
|
|
|
| 71,4% |
Uncovered Elements: 4 (14) |
Complexity: 3 |
Complexity Density: 0,3 |
|
121 |
352
|
private int measureHeight(int measureSpec)... |
122 |
|
{ |
123 |
352
|
int result = 0; |
124 |
352
|
int specMode = MeasureSpec.getMode(measureSpec); |
125 |
352
|
int specSize = MeasureSpec.getSize(measureSpec); |
126 |
352
|
if (specMode == MeasureSpec.EXACTLY) |
127 |
|
{ |
128 |
0
|
result = specSize; |
129 |
|
} else { |
130 |
352
|
float iHeight = TextHeight(); |
131 |
352
|
result = getPaddingTop() + iMargin + (int)iHeight + iMargin + iMargin + getPaddingBottom(); |
132 |
352
|
if (specMode == MeasureSpec.AT_MOST) |
133 |
|
{ |
134 |
0
|
result = Math.min(result, specSize); |
135 |
|
} |
136 |
|
} |
137 |
352
|
return result; |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
140 |
0
|
@Override... |
141 |
|
public boolean onKeyDown(int keyCode, KeyEvent event) |
142 |
|
{ |
143 |
0
|
boolean bResult = super.onKeyDown(keyCode, event); |
144 |
0
|
if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER) || (keyCode == KeyEvent.KEYCODE_ENTER)) |
145 |
|
{ |
146 |
0
|
doItemClick(); |
147 |
|
} |
148 |
0
|
return bResult; |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
151 |
0
|
@Override... |
152 |
|
public boolean onKeyUp(int keyCode, KeyEvent event) |
153 |
|
{ |
154 |
0
|
boolean bResult = super.onKeyUp(keyCode, event); |
155 |
0
|
return bResult; |
156 |
|
} |
157 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
158 |
7
|
public void doItemClick()... |
159 |
|
{ |
160 |
7
|
if (itemClick != null) |
161 |
7
|
itemClick.OnClick(this); |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
164 |
0
|
public void DrawTestRect(Canvas canvas)... |
165 |
|
{ |
166 |
0
|
Rect rt = new Rect(0, 0, getWidth(), getHeight()); |
167 |
0
|
mpt.setColor(0x22000000); |
168 |
0
|
canvas.drawRect(rt, mpt); |
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
171 |
0
|
@Override... |
172 |
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) |
173 |
|
{ |
174 |
0
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
175 |
0
|
invalidate(); |
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
912
|
@Override... |
179 |
|
protected void onDraw(Canvas canvas) |
180 |
|
{ |
181 |
912
|
super.onDraw(canvas); |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
88
|
public void SetText(String value)... |
185 |
|
{ |
186 |
88
|
sText = value.replace("\n", " "); |
187 |
|
} |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
88
|
public void SetRowId(long lRowId)... |
190 |
|
{ |
191 |
88
|
this.lRowId = lRowId; |
192 |
|
} |
193 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
194 |
7
|
public long GetRowId()... |
195 |
|
{ |
196 |
7
|
return lRowId; |
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
199 |
0
|
public void Update()... |
200 |
|
{ |
201 |
0
|
requestLayout(); |
202 |
0
|
invalidate(); |
203 |
|
} |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 4 |
Complexity Density: 0,16 |
|
205 |
912
|
public void DrawItemText(Canvas canvas, int iposX, int iposY, int iWidth, int iActiveTextColor)... |
206 |
|
{ |
207 |
912
|
mpt.setFakeBoldText(false); |
208 |
|
|
209 |
|
|
210 |
912
|
if (IsViewFocused()) |
211 |
|
{ |
212 |
9
|
int iHeight = getHeight(); |
213 |
9
|
mpt.setShader(null); |
214 |
9
|
LinearGradient lGradBkg = new LinearGradient(0, 0, 0, iHeight, |
215 |
|
0xFFDDDDDD, 0xFF444444, Shader.TileMode.CLAMP); |
216 |
|
|
217 |
9
|
mpt.setShader(lGradBkg); |
218 |
9
|
RectF rt = new RectF(iposX, 0, iWidth, iHeight); |
219 |
9
|
canvas.drawRoundRect(rt, 2, 2, mpt); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
912
|
int iTextColor = 0; |
224 |
912
|
int iTextColorEnd = 0; |
225 |
|
|
226 |
|
|
227 |
912
|
if (IsViewFocused()) |
228 |
|
{ |
229 |
|
|
230 |
9
|
iTextColor = 0xFF888888; |
231 |
9
|
iTextColorEnd = iTextColor & 0x00FFFFFF; |
232 |
9
|
LinearGradient lGrad = new LinearGradient(iWidth - 16, 0, iWidth - 6, 0, |
233 |
|
iTextColor, iTextColorEnd, Shader.TileMode.CLAMP); |
234 |
9
|
mpt.setShader(lGrad); |
235 |
|
|
236 |
9
|
canvas.drawText(sText, iposX + 1, iposY + 1, mpt); |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
912
|
iTextColor = (IsViewFocused())?0xFF222222:iActiveTextColor; |
241 |
912
|
iTextColorEnd = iTextColor & 0x00FFFFFF; |
242 |
912
|
LinearGradient lGrad = new LinearGradient(iWidth - 16, 0, iWidth - 6, 0, |
243 |
|
iTextColor, iTextColorEnd, Shader.TileMode.CLAMP); |
244 |
912
|
mpt.setShader(lGrad); |
245 |
|
|
246 |
|
|
247 |
912
|
rectClipText.set(0, 0, iWidth, getHeight()); |
248 |
912
|
canvas.save(); |
249 |
912
|
canvas.clipRect(rectClipText); |
250 |
912
|
canvas.drawText(sText, iposX + 2, iposY, mpt); |
251 |
912
|
canvas.restore(); |
252 |
|
} |
253 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
254 |
2736
|
public boolean IsViewFocused()... |
255 |
|
{ |
256 |
2736
|
return (this.isFocused() || bTouchedDown); |
257 |
|
} |
258 |
|
|
|
|
| 81,8% |
Uncovered Elements: 4 (22) |
Complexity: 4 |
Complexity Density: 0,25 |
|
259 |
19
|
@Override... |
260 |
|
public boolean onTouchEvent(MotionEvent event) |
261 |
|
{ |
262 |
19
|
boolean bHandled = false; |
263 |
19
|
if (event.getAction() == MotionEvent.ACTION_DOWN) |
264 |
|
{ |
265 |
7
|
bHandled = true; |
266 |
7
|
bTouchedDown = true; |
267 |
7
|
invalidate(); |
268 |
7
|
Utils.startAlphaAnimIn(ViewTodayItem.this); |
269 |
|
} |
270 |
19
|
if (event.getAction() == MotionEvent.ACTION_CANCEL) |
271 |
|
{ |
272 |
0
|
bHandled = true; |
273 |
0
|
bTouchedDown = false; |
274 |
0
|
invalidate(); |
275 |
|
} |
276 |
19
|
if (event.getAction() == MotionEvent.ACTION_UP) |
277 |
|
{ |
278 |
7
|
bHandled = true; |
279 |
7
|
bTouchedDown = false; |
280 |
7
|
invalidate(); |
281 |
7
|
doItemClick(); |
282 |
|
} |
283 |
19
|
return bHandled; |
284 |
|
} |
285 |
|
|
286 |
|
} |