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
104   286   39   4,73
32   238   0,38   11
22     1,77  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ViewTodayItem       Line # 17 104 39 72,2% 0.721519
  ViewTodayItem.OnItemClick       Line # 20 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.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   
 
17    public class ViewTodayItem extends View
18    {
19    //types
 
20    public interface OnItemClick
21    {
22    public void OnClick(ViewTodayItem item);
23    }
24   
25    //fields
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    //methods
 
47  88 toggle public ViewTodayItem(Context context)
48    {
49  88 super(context);
50  88 Init(context);
51    }
52   
 
53  0 toggle @SuppressWarnings("all")
54    public ViewTodayItem(Context context, AttributeSet attrs, Map inflateParams)
55    {
56  0 super(context, attrs);
57  0 Init(context);
58    }
59   
 
60  88 toggle 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    //get icons
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   
 
77  88 toggle public void SetItemClick(OnItemClick itemClick)
78    {
79  88 this.itemClick = itemClick;
80    }
81   
 
82  352 toggle @Override
83    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
84    {
85  352 setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec));
86    }
87   
 
88  352 toggle public int TextHeight()
89    {
90  352 return (int)(-mpt.ascent() + mpt.descent());
91    }
92   
 
93  0 toggle 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   
 
102  352 toggle 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   
 
121  352 toggle 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   
 
140  0 toggle @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   
 
151  0 toggle @Override
152    public boolean onKeyUp(int keyCode, KeyEvent event)
153    {
154  0 boolean bResult = super.onKeyUp(keyCode, event);
155  0 return bResult;
156    }
157   
 
158  7 toggle public void doItemClick()
159    {
160  7 if (itemClick != null)
161  7 itemClick.OnClick(this);
162    }
163   
 
164  0 toggle 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   
 
171  0 toggle @Override
172    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
173    {
174  0 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
175  0 invalidate();
176    }
177   
 
178  912 toggle @Override
179    protected void onDraw(Canvas canvas)
180    {
181  912 super.onDraw(canvas);
182    }
183   
 
184  88 toggle public void SetText(String value)
185    {
186  88 sText = value.replace("\n", " ");
187    }
188   
 
189  88 toggle public void SetRowId(long lRowId)
190    {
191  88 this.lRowId = lRowId;
192    }
193   
 
194  7 toggle public long GetRowId()
195    {
196  7 return lRowId;
197    }
198   
 
199  0 toggle public void Update()
200    {
201  0 requestLayout();
202  0 invalidate();
203    }
204   
 
205  912 toggle public void DrawItemText(Canvas canvas, int iposX, int iposY, int iWidth, int iActiveTextColor)
206    {
207  912 mpt.setFakeBoldText(false);
208   
209    //text background
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    //init colors
223  912 int iTextColor = 0;
224  912 int iTextColorEnd = 0;
225   
226    //draw text shadow
227  912 if (IsViewFocused())
228    {
229    //set gradient text shader
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    //set gradient text shader
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    //draw text
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   
 
254  2736 toggle public boolean IsViewFocused()
255    {
256  2736 return (this.isFocused() || bTouchedDown);
257    }
258   
 
259  19 toggle @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    }