Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../../img/srcFileCovDistChart8.png 73% of files have more coverage
112   311   37   5,33
30   249   0,33   7
21     1,76  
3    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ViewTodayItemHeader       Line # 15 112 37 78,5% 0.78527606
  ViewTodayItemHeader.ViewType       Line # 18 0 0 - -1.0
  ViewTodayItemHeader.OnHeaderItemClick       Line # 21 0 0 - -1.0
 
No Tests
 
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   
 
15    public class ViewTodayItemHeader extends View
16    {
17    //types
 
18    public enum ViewType { Appointments, Tasks, Notes };
19   
20    //types
 
21    public interface OnHeaderItemClick
22    {
23    public void OnClick(View v, ViewTodayItemHeader.ViewType type);
24    }
25   
26    //fields
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    //fields
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    //fields
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    //methods
 
48  3 toggle public ViewTodayItemHeader(Context context)
49    {
50  3 super(context);
51  3 Init(context);
52    }
53   
 
54  0 toggle @SuppressWarnings("all")
55    public ViewTodayItemHeader(Context context, AttributeSet attrs, Map inflateParams)
56    {
57  0 super(context, attrs);
58  0 Init(context);
59    }
60   
 
61  3 toggle 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   
 
73  6 toggle public void SetType(ViewType viewType)
74    {
75  6 this.viewType = viewType;
76    }
77   
 
78  3 toggle public void SetItemClick(OnHeaderItemClick itemClick)
79    {
80  3 this.itemClick = itemClick;
81    }
82   
 
83  324 toggle @Override
84    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
85    {
86  324 setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec));
87    }
88   
 
89  1081 toggle public int TextHeight()
90    {
91  1081 return (int)(-mpt.ascent() + mpt.descent());
92    }
93   
 
94  324 toggle 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   
 
113  324 toggle 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   
 
133  0 toggle @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   
 
144  0 toggle @Override
145    public boolean onKeyUp(int keyCode, KeyEvent event)
146    {
147  0 boolean bResult = super.onKeyUp(keyCode, event);
148  0 return bResult;
149    }
150   
 
151  9 toggle public void doItemClick()
152    {
153  9 if (itemClick != null)
154  9 itemClick.OnClick(this, viewType);
155    }
156   
 
157  0 toggle 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   
 
164  0 toggle @Override
165    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
166    {
167  0 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
168  0 invalidate();
169    }
170   
 
171  757 toggle 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   
 
183  1713 toggle public static int GetTextPosX()
184    {
185  1713 return iIconLeft + (iconW + (iconW >> 1)) + iIconLeft;
186    }
187   
 
188  757 toggle @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    //draw base line
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    //draw icon border
212  757 mpt.setColor(0xFF222222);
213  757 canvas.drawCircle(iIconLeft + iconW, (getHeight() >> 1), iconH + 1, mpt);
214    //draw icon center shaded
215  757 RadialGradient radGrad = new RadialGradient(iIconLeft + iconW, (getHeight() >> 1), iconH,
216    0xFF888888, 0xFF666666, Shader.TileMode.CLAMP);
217  757 mpt.setShader(radGrad);
218    //mpt.setColor(0xFF666666);
219  757 canvas.drawCircle(iIconLeft + iconW, (getHeight() >> 1), iconH, mpt);
220  757 mpt.setShader(null);
221   
222    //set text
223  757 mpt.setLinearText(true);
224  757 mpt.setFakeBoldText(true);
225    //int iposX = iIconLeft + iconW + iIconLeft;
226  757 final int iTextPosY = TextHeight();
227   
228    //draw title text shadow
229  757 if (IsViewFocused())
230    {
231  14 mpt.setColor(iTitleTextShadowColor);
232  14 canvas.drawText(sText, iTextPosX + 1, iTextPosY + 1, mpt);
233    }
234   
235    //draw title text
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    //draw additional info text
245  757 final int iposX = getWidth() - (int)mpt.measureText(sTextInfo) - iIconLeft;
246  757 mpt.setUnderlineText(false);
247   
248    //draw info text shadow
249  757 if (IsViewFocused())
250    {
251  14 mpt.setColor(iTitleTextShadowColor);
252  14 canvas.drawText(sTextInfo, iposX + 1, iTextPosY + 1, mpt);
253    }
254   
255    //right info color
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   
 
265  3 toggle public void SetText(String value)
266    {
267  3 sText = value;
268  3 requestLayout();
269  3 invalidate();
270    }
271   
 
272  78 toggle public void SetInfoText(String value)
273    {
274  78 sTextInfo = value;
275  78 requestLayout();
276  78 invalidate();
277    }
278   
 
279  4542 toggle public boolean IsViewFocused()
280    {
281  4542 return (this.isFocused() || bTouchedDown);
282    }
283   
 
284  23 toggle @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    }