Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
61   138   6   15,25
4   105   0,1   4
4     1,5  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ViewToastMsg       Line # 13 61 6 97,1% 0.9710145
 
No Tests
 
1   
2    package pl.magot.vetch.ancal.views;
3   
4   
5    import pl.magot.vetch.ancal.*;
6    import android.content.Context;
7    import android.widget.*;
8    import android.graphics.*;
9    import android.graphics.drawable.*;
10    import android.os.*;
11   
12   
 
13    public class ViewToastMsg extends LinearLayout
14    {
15    //fields
16    private static final int iMaxWidth = 260;
17    private static final int iDefaultPadding = 6;
18    private static final int iIconW = 19;
19    private static final int iIconH = 19;
20    private static final float fTextSize = 16;
21    private Drawable icon = null;
22    private RectF rect = new RectF();
23    private Paint pt = new Paint();
24    private Handler handlerUpdateAnim = new Handler();
25    private int iIconAlphaValue = 255;
26   
27    //fields
28    private LinearLayout layHeader = null;
29    private LinearLayout layContent = null;
30    private TextView textHeader = null;
31    private TextView textContent = null;
32   
33    //methods
 
34  7 toggle public ViewToastMsg(Context context, String sHeaderText, String sContentText)
35    {
36  7 super(context);
37    //get text size
38  7 pt.setTextSize(fTextSize);
39  7 final int iTextWidth = (int)pt.measureText(sContentText);
40    //set max text contener width
41  7 int iMainWidth = android.view.ViewGroup.LayoutParams.FILL_PARENT;
42  7 if ((iTextWidth + (iDefaultPadding + iDefaultPadding)) > getMaxWidth())
43  0 iMainWidth = getMaxWidth();
44    //get icon
45  7 icon = getResources().getDrawable(R.drawable.iconnotifyalarm);
46    //header
47  7 layHeader = new LinearLayout(context);
48  7 layHeader.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
49  7 layHeader.setOrientation(LinearLayout.HORIZONTAL);
50    //header text
51  7 textHeader = new TextView(context);
52  7 textHeader.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
53  7 textHeader.setText(sHeaderText);
54  7 textHeader.setSingleLine();
55  7 textHeader.setTextSize(fTextSize);
56  7 textHeader.setPadding(iIconW + 4, 0, 0, iDefaultPadding);
57  7 layHeader.addView(textHeader);
58    //content
59  7 layContent = new LinearLayout(context);
60  7 layContent.setLayoutParams(new LayoutParams(iMainWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
61  7 layContent.setOrientation(LinearLayout.HORIZONTAL);
62    //content text
63  7 textContent = new TextView(context);
64  7 textContent.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
65  7 textContent.setText(sContentText);
66  7 textContent.setTextSize(fTextSize);
67  7 textContent.setTextColor(0xFFFFFFFF);
68  7 layContent.addView(textContent);
69    //update layout
70  7 this.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
71  7 this.setOrientation(LinearLayout.VERTICAL);
72  7 this.setPadding(iDefaultPadding, iDefaultPadding, iDefaultPadding, iDefaultPadding);
73  7 this.setBackgroundColor(0x00000000); //sets drawable surface !!!
74  7 this.addView(layHeader);
75  7 this.addView(layContent);
76    //start anim
77  7 handlerUpdateAnim.removeCallbacks(handlerUpdateAnimTask);
78  7 handlerUpdateAnim.postDelayed(handlerUpdateAnimTask, 60);
79    }
80   
81    private Runnable handlerUpdateAnimTask = new Runnable()
82    {
 
83  26957 toggle public void run()
84    {
85  26957 try
86    {
87  26957 iIconAlphaValue -= 20;
88  26957 if (iIconAlphaValue < 0)
89  2072 iIconAlphaValue = 255;
90  26957 textHeader.invalidate();
91    } finally {
92  26957 handlerUpdateAnim.postDelayed(this, 60);
93    }
94    }
95    };
96   
 
97  7 toggle private int getMaxWidth()
98    {
99  7 return iMaxWidth;
100    }
101   
 
102  346 toggle @Override
103    protected void onDraw(Canvas canvas)
104    {
105  346 super.onDraw(canvas);
106   
107  346 pt.setAntiAlias(true);
108  346 rect.set(0, 0, this.getWidth(), this.getHeight());
109   
110    //draw outer frame
111  346 pt.setColor(0x99AACCAA);
112  346 canvas.drawRoundRect(rect, 4, 4, pt);
113   
114    //draw inner background
115  346 pt.setColor(0x77000000);
116  346 rect.inset(2, 2);
117  346 canvas.drawRoundRect(rect, 3, 3, pt);
118   
119  346 final int iLineLeft = 2;
120  346 final int iLineTop = textHeader.getBottom() + 3;
121  346 final int iLineWidth = getWidth() - (2 + 2);
122   
123    //draw base line
124  346 LinearGradient lGrad = new LinearGradient((iLineWidth >> 2), 0, iLineWidth, 0,
125    0xFFFFFFFF, 0x00FFFFFF, Shader.TileMode.CLAMP);
126  346 pt.setShader(lGrad);
127  346 canvas.drawLine(iLineLeft, iLineTop, iLineWidth, iLineTop, pt);
128  346 pt.setShader(null);
129   
130    //draw icon
131  346 final int iIconX = iDefaultPadding;
132  346 final int iIconY = textHeader.getTop() + ((textHeader.getHeight() >> 1) - (iIconH >> 1)) + 2;
133  346 icon.setBounds(iIconX, iIconY, iIconX + iIconW, iIconY + iIconH);
134  346 icon.setAlpha(iIconAlphaValue);
135  346 icon.draw(canvas);
136    }
137   
138    }