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 |
|
|
|
|
| 97,1% |
Uncovered Elements: 2 (69) |
Complexity: 6 |
Complexity Density: 0,1 |
|
13 |
|
public class ViewToastMsg extends LinearLayout |
14 |
|
{ |
15 |
|
|
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 |
|
|
28 |
|
private LinearLayout layHeader = null; |
29 |
|
private LinearLayout layContent = null; |
30 |
|
private TextView textHeader = null; |
31 |
|
private TextView textContent = null; |
32 |
|
|
33 |
|
|
|
|
| 94,4% |
Uncovered Elements: 2 (36) |
Complexity: 2 |
Complexity Density: 0,06 |
|
34 |
7
|
public ViewToastMsg(Context context, String sHeaderText, String sContentText)... |
35 |
|
{ |
36 |
7
|
super(context); |
37 |
|
|
38 |
7
|
pt.setTextSize(fTextSize); |
39 |
7
|
final int iTextWidth = (int)pt.measureText(sContentText); |
40 |
|
|
41 |
7
|
int iMainWidth = android.view.ViewGroup.LayoutParams.FILL_PARENT; |
42 |
7
|
if ((iTextWidth + (iDefaultPadding + iDefaultPadding)) > getMaxWidth()) |
43 |
0
|
iMainWidth = getMaxWidth(); |
44 |
|
|
45 |
7
|
icon = getResources().getDrawable(R.drawable.iconnotifyalarm); |
46 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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); |
74 |
7
|
this.addView(layHeader); |
75 |
7
|
this.addView(layContent); |
76 |
|
|
77 |
7
|
handlerUpdateAnim.removeCallbacks(handlerUpdateAnimTask); |
78 |
7
|
handlerUpdateAnim.postDelayed(handlerUpdateAnimTask, 60); |
79 |
|
} |
80 |
|
|
81 |
|
private Runnable handlerUpdateAnimTask = new Runnable() |
82 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
83 |
26957
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
7
|
private int getMaxWidth()... |
98 |
|
{ |
99 |
7
|
return iMaxWidth; |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0,05 |
|
102 |
346
|
@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 |
|
|
111 |
346
|
pt.setColor(0x99AACCAA); |
112 |
346
|
canvas.drawRoundRect(rect, 4, 4, pt); |
113 |
|
|
114 |
|
|
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 |
|
|
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 |
|
|
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 |
|
} |