1 |
|
|
2 |
|
package pl.magot.vetch.widgets; |
3 |
|
|
4 |
|
|
5 |
|
import java.util.*; |
6 |
|
import pl.magot.vetch.ancal.Utils; |
7 |
|
import android.content.*; |
8 |
|
import android.view.*; |
9 |
|
import android.widget.LinearLayout.LayoutParams; |
10 |
|
import android.graphics.*; |
11 |
|
|
12 |
|
|
|
|
| 86,3% |
Uncovered Elements: 19 (139) |
Complexity: 35 |
Complexity Density: 0,38 |
|
13 |
|
public class DateWidgetDayCell extends View |
14 |
|
{ |
15 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
16 |
|
public interface OnItemClick |
17 |
|
{ |
18 |
|
public void OnClick(DateWidgetDayCell item); |
19 |
|
} |
20 |
|
|
21 |
|
|
22 |
|
private final static float fTextSize = 22; |
23 |
|
private final static int iMargin = 1; |
24 |
|
private final static int iAlphaInactiveMonth = 0x88; |
25 |
|
|
26 |
|
|
27 |
|
private int iDateYear = 0; |
28 |
|
private int iDateMonth = 0; |
29 |
|
private int iDateDay = 0; |
30 |
|
|
31 |
|
|
32 |
|
private OnItemClick itemClick = null; |
33 |
|
private Paint pt = new Paint(); |
34 |
|
private RectF rect = new RectF(); |
35 |
|
private String sDate = ""; |
36 |
|
|
37 |
|
|
38 |
|
private boolean bSelected = false; |
39 |
|
private boolean bIsActiveMonth = false; |
40 |
|
private boolean bToday = false; |
41 |
|
private boolean bHoliday = false; |
42 |
|
private boolean bTouchedDown = false; |
43 |
|
|
44 |
|
|
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
46 |
252
|
public DateWidgetDayCell(Context context, int iWidth, int iHeight)... |
47 |
|
{ |
48 |
252
|
super(context); |
49 |
252
|
setFocusable(true); |
50 |
252
|
setLayoutParams(new LayoutParams(iWidth, iHeight)); |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
252
|
public boolean getSelected()... |
54 |
|
{ |
55 |
252
|
return this.bSelected; |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
58 |
1560
|
@Override... |
59 |
|
public void setSelected(boolean bEnable) |
60 |
|
{ |
61 |
1560
|
if (this.bSelected != bEnable) |
62 |
|
{ |
63 |
12
|
this.bSelected = bEnable; |
64 |
12
|
this.invalidate(); |
65 |
|
} |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
|
68 |
1554
|
public void setData(int iYear, int iMonth, int iDay, boolean bToday, boolean bHoliday, int iActiveMonth)... |
69 |
|
{ |
70 |
1554
|
iDateYear = iYear; |
71 |
1554
|
iDateMonth = iMonth; |
72 |
1554
|
iDateDay = iDay; |
73 |
|
|
74 |
1554
|
this.sDate = Integer.toString(iDateDay); |
75 |
1554
|
this.bIsActiveMonth = (iDateMonth == iActiveMonth); |
76 |
1554
|
this.bToday = bToday; |
77 |
1554
|
this.bHoliday = bHoliday; |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
252
|
public void setItemClick(OnItemClick itemClick) ... |
81 |
|
{ |
82 |
252
|
this.itemClick = itemClick; |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
4164
|
private int getTextHeight()... |
86 |
|
{ |
87 |
4164
|
return (int)(-pt.ascent() + pt.descent()); |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
90 |
0
|
@Override... |
91 |
|
public boolean onKeyDown(int keyCode, KeyEvent event) |
92 |
|
{ |
93 |
0
|
boolean bResult = super.onKeyDown(keyCode, event); |
94 |
0
|
if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER) || (keyCode == KeyEvent.KEYCODE_ENTER)) |
95 |
|
{ |
96 |
0
|
doItemClick(); |
97 |
|
} |
98 |
0
|
return bResult; |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
101 |
0
|
@Override... |
102 |
|
public boolean onKeyUp(int keyCode, KeyEvent event) |
103 |
|
{ |
104 |
0
|
boolean bResult = super.onKeyUp(keyCode, event); |
105 |
0
|
return bResult; |
106 |
|
} |
107 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
108 |
6
|
public void doItemClick()... |
109 |
|
{ |
110 |
6
|
if (itemClick != null) |
111 |
6
|
itemClick.OnClick(this); |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
114 |
0
|
@Override... |
115 |
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) |
116 |
|
{ |
117 |
0
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
118 |
0
|
invalidate(); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
121 |
6
|
public Calendar getDate()... |
122 |
|
{ |
123 |
6
|
Calendar calDate = Calendar.getInstance(); |
124 |
6
|
calDate.clear(); |
125 |
6
|
calDate.set(Calendar.YEAR, iDateYear); |
126 |
6
|
calDate.set(Calendar.MONTH, iDateMonth); |
127 |
6
|
calDate.set(Calendar.DAY_OF_MONTH, iDateDay); |
128 |
6
|
return calDate; |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
131 |
2082
|
@Override... |
132 |
|
protected void onDraw(Canvas canvas) |
133 |
|
{ |
134 |
2082
|
super.onDraw(canvas); |
135 |
|
|
136 |
|
|
137 |
2082
|
rect.set(0, 0, this.getWidth(), this.getHeight()); |
138 |
2082
|
rect.inset(1, 1); |
139 |
|
|
140 |
|
|
141 |
2082
|
final boolean bFocused = IsViewFocused(); |
142 |
|
|
143 |
2082
|
drawDayView(canvas, bFocused); |
144 |
2082
|
drawDayNumber(canvas, bFocused); |
145 |
|
} |
146 |
|
|
|
|
| 95,8% |
Uncovered Elements: 1 (24) |
Complexity: 7 |
Complexity Density: 0,5 |
|
147 |
2082
|
private void drawDayView(Canvas canvas, boolean bFocused)... |
148 |
|
{ |
149 |
2082
|
if (bSelected || bFocused) |
150 |
|
{ |
151 |
24
|
LinearGradient lGradBkg = null; |
152 |
|
|
153 |
24
|
if (bFocused) |
154 |
|
{ |
155 |
8
|
lGradBkg = new LinearGradient(rect.left, 0, rect.right, 0, |
156 |
|
dayStyle.iColorBkgFocusDark, dayStyle.iColorBkgFocusLight, Shader.TileMode.CLAMP); |
157 |
|
} |
158 |
|
|
159 |
24
|
if (bSelected) |
160 |
|
{ |
161 |
16
|
lGradBkg = new LinearGradient(rect.left, 0, rect.right, 0, |
162 |
|
dayStyle.iColorBkgSelectedDark, dayStyle.iColorBkgSelectedLight, Shader.TileMode.CLAMP); |
163 |
|
} |
164 |
|
|
165 |
24
|
if (lGradBkg != null) |
166 |
|
{ |
167 |
24
|
pt.setShader(lGradBkg); |
168 |
24
|
canvas.drawRect(rect, pt); |
169 |
|
} |
170 |
|
|
171 |
24
|
pt.setShader(null); |
172 |
|
|
173 |
|
} else { |
174 |
|
|
175 |
2058
|
pt.setColor(dayStyle.getColorBkg(bHoliday, bToday)); |
176 |
2058
|
if (!bIsActiveMonth) |
177 |
568
|
pt.setAlpha(iAlphaInactiveMonth); |
178 |
2058
|
canvas.drawRect(rect, pt); |
179 |
|
} |
180 |
|
} |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 7 |
Complexity Density: 0,32 |
|
182 |
2082
|
public void drawDayNumber(Canvas canvas, boolean bFocused)... |
183 |
|
{ |
184 |
|
|
185 |
2082
|
pt.setTypeface(null); |
186 |
2082
|
pt.setAntiAlias(true); |
187 |
2082
|
pt.setShader(null); |
188 |
2082
|
pt.setFakeBoldText(true); |
189 |
2082
|
pt.setTextSize(fTextSize); |
190 |
|
|
191 |
2082
|
pt.setUnderlineText(false); |
192 |
2082
|
if (bToday) |
193 |
12
|
pt.setUnderlineText(true); |
194 |
|
|
195 |
2082
|
int iTextPosX = (int)rect.right - (int)pt.measureText(sDate); |
196 |
2082
|
int iTextPosY = (int)rect.bottom + (int)(-pt.ascent()) - getTextHeight(); |
197 |
|
|
198 |
2082
|
iTextPosX -= ((int)rect.width() >> 1) - ((int)pt.measureText(sDate) >> 1); |
199 |
2082
|
iTextPosY -= ((int)rect.height() >> 1) - (getTextHeight() >> 1); |
200 |
|
|
201 |
|
|
202 |
2082
|
if (bSelected || bFocused) |
203 |
|
{ |
204 |
24
|
if (bSelected) |
205 |
16
|
pt.setColor(dayStyle.iColorTextSelected); |
206 |
24
|
if (bFocused) |
207 |
8
|
pt.setColor(dayStyle.iColorTextFocused); |
208 |
|
} else { |
209 |
2058
|
pt.setColor(dayStyle.getColorText(bHoliday, bToday)); |
210 |
|
} |
211 |
|
|
212 |
2082
|
if (!bIsActiveMonth) |
213 |
568
|
pt.setAlpha(iAlphaInactiveMonth); |
214 |
|
|
215 |
2082
|
canvas.drawText(sDate, iTextPosX, iTextPosY + iMargin, pt); |
216 |
|
|
217 |
2082
|
pt.setUnderlineText(false); |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
220 |
2082
|
public boolean IsViewFocused()... |
221 |
|
{ |
222 |
2082
|
return (this.isFocused() || bTouchedDown); |
223 |
|
} |
224 |
|
|
|
|
| 81,8% |
Uncovered Elements: 4 (22) |
Complexity: 4 |
Complexity Density: 0,25 |
|
225 |
17
|
@Override... |
226 |
|
public boolean onTouchEvent(MotionEvent event) |
227 |
|
{ |
228 |
17
|
boolean bHandled = false; |
229 |
17
|
if (event.getAction() == MotionEvent.ACTION_DOWN) |
230 |
|
{ |
231 |
6
|
bHandled = true; |
232 |
6
|
bTouchedDown = true; |
233 |
6
|
invalidate(); |
234 |
6
|
Utils.startAlphaAnimIn(DateWidgetDayCell.this); |
235 |
|
} |
236 |
17
|
if (event.getAction() == MotionEvent.ACTION_CANCEL) |
237 |
|
{ |
238 |
0
|
bHandled = true; |
239 |
0
|
bTouchedDown = false; |
240 |
0
|
invalidate(); |
241 |
|
} |
242 |
17
|
if (event.getAction() == MotionEvent.ACTION_UP) |
243 |
|
{ |
244 |
6
|
bHandled = true; |
245 |
6
|
bTouchedDown = false; |
246 |
6
|
invalidate(); |
247 |
6
|
doItemClick(); |
248 |
|
} |
249 |
17
|
return bHandled; |
250 |
|
} |
251 |
|
|
252 |
|
} |