1 |
|
|
2 |
|
package pl.magot.vetch.widgets; |
3 |
|
|
4 |
|
|
5 |
|
import android.app.*; |
6 |
|
import android.content.Intent; |
7 |
|
import android.os.Bundle; |
8 |
|
import android.view.*; |
9 |
|
import android.widget.Button; |
10 |
|
import android.widget.LinearLayout; |
11 |
|
import android.widget.TextView; |
12 |
|
import android.widget.LinearLayout.LayoutParams; |
13 |
|
|
14 |
|
|
|
|
| 84,9% |
Uncovered Elements: 23 (152) |
Complexity: 32 |
Complexity Density: 0,29 |
|
15 |
|
public class TimeWidget extends Activity |
16 |
|
{ |
17 |
|
|
18 |
|
private static String sStrSelect = "Select time"; |
19 |
|
private static String sStrSet = "set"; |
20 |
|
private static String sStrNone = "none"; |
21 |
|
|
22 |
|
|
23 |
|
public static final int SELECT_TIME_REQUEST = 112; |
24 |
|
public static final int iSliderViewWidth = 276; |
25 |
|
private static final int iSmallButtonWidth = 100; |
26 |
|
|
27 |
|
|
28 |
|
private LinearLayout layContent = null; |
29 |
|
private Button btnNone = null; |
30 |
|
private Button btnOK = null; |
31 |
|
|
32 |
|
|
33 |
|
private boolean bNoneButton = true; |
34 |
|
private boolean b24HourMode = false; |
35 |
|
private int iHour = -1; |
36 |
|
private int iMinutes = -1; |
37 |
|
|
38 |
|
|
39 |
|
TimeCaption labCaption = null; |
40 |
|
TimeWidgetSlider timeSliderHour = null; |
41 |
|
TimeWidgetSlider timeSliderMinutes = null; |
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 83,3% |
Uncovered Elements: 5 (30) |
Complexity: 6 |
Complexity Density: 0,3 |
|
45 |
2
|
@Override... |
46 |
|
public void onCreate(Bundle icicle) |
47 |
|
{ |
48 |
2
|
super.onCreate(icicle); |
49 |
|
|
50 |
2
|
setTitle(sStrSelect); |
51 |
|
|
52 |
|
|
53 |
2
|
bNoneButton = true; |
54 |
2
|
b24HourMode = false; |
55 |
2
|
iHour = -1; |
56 |
2
|
iMinutes = -1; |
57 |
|
|
58 |
|
|
59 |
2
|
Bundle data = this.getIntent().getExtras(); |
60 |
2
|
if (data != null) |
61 |
|
{ |
62 |
2
|
if (data.containsKey("noneButton")) |
63 |
2
|
bNoneButton = data.getBoolean("noneButton"); |
64 |
2
|
if (data.containsKey("24HourMode")) |
65 |
2
|
b24HourMode = data.getBoolean("24HourMode"); |
66 |
2
|
if (data.containsKey("Hour")) |
67 |
2
|
iHour = data.getInt("Hour"); |
68 |
2
|
if (data.containsKey("Minute")) |
69 |
2
|
iMinutes = data.getInt("Minute"); |
70 |
|
} |
71 |
|
|
72 |
2
|
setContentView(generateContentView()); |
73 |
|
|
74 |
2
|
timeSliderHour.setValue(iHour, false); |
75 |
2
|
timeSliderMinutes.setValue(iMinutes, false); |
76 |
|
|
77 |
2
|
timeSliderHour.requestFocus(); |
78 |
|
} |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
80 |
0
|
@Override... |
81 |
|
protected void onSaveInstanceState(Bundle outState) |
82 |
|
{ |
83 |
0
|
super.onSaveInstanceState(outState); |
84 |
|
|
85 |
|
|
86 |
0
|
this.finish(); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
2
|
@Override... |
90 |
|
public void onStart() |
91 |
|
{ |
92 |
2
|
super.onStart(); |
93 |
|
|
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
96 |
1
|
public static void setStrings(String strSelect, String strNone, String strSet)... |
97 |
|
{ |
98 |
1
|
sStrSelect = new String(strSelect); |
99 |
1
|
sStrNone = new String(strNone); |
100 |
1
|
sStrSet = new String(strSet); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
103 |
2
|
public static void Open(Activity parentActivity, boolean bNoneButton, boolean b24HourMode, int iHour, int iMinute)... |
104 |
|
{ |
105 |
2
|
Intent it = new Intent("android.intent.action.AnCal.ACTION_MODE_EDIT_SELECT_TIME"); |
106 |
2
|
Bundle data = new Bundle(); |
107 |
2
|
data.putInt("Hour", iHour); |
108 |
2
|
data.putInt("Minute", iMinute); |
109 |
2
|
data.putBoolean("24HourMode", b24HourMode); |
110 |
2
|
data.putBoolean("noneButton", bNoneButton); |
111 |
2
|
it.putExtras(data); |
112 |
2
|
parentActivity.startActivityForResult(it, SELECT_TIME_REQUEST); |
113 |
|
} |
114 |
|
|
|
|
| 62,5% |
Uncovered Elements: 3 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
115 |
2
|
public static int GetSelectedTimeHourOnActivityResult(int requestCode, int resultCode, Bundle extras)... |
116 |
|
{ |
117 |
2
|
if ((requestCode == TimeWidget.SELECT_TIME_REQUEST) && (resultCode == RESULT_OK)) |
118 |
2
|
if (extras.containsKey("Hour")) |
119 |
2
|
return extras.getInt("Hour"); |
120 |
0
|
return -1; |
121 |
|
} |
122 |
|
|
|
|
| 62,5% |
Uncovered Elements: 3 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
123 |
2
|
public static int GetSelectedTimeMinuteOnActivityResult(int requestCode, int resultCode, Bundle extras)... |
124 |
|
{ |
125 |
2
|
if ((requestCode == TimeWidget.SELECT_TIME_REQUEST) && (resultCode == RESULT_OK)) |
126 |
2
|
if (extras.containsKey("Minute")) |
127 |
2
|
return extras.getInt("Minute"); |
128 |
0
|
return -1; |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
131 |
14
|
public LinearLayout createLayout(int iOrientation)... |
132 |
|
{ |
133 |
14
|
LinearLayout lay = new LinearLayout(this); |
134 |
14
|
lay.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); |
135 |
14
|
lay.setOrientation(iOrientation); |
136 |
14
|
return lay; |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
139 |
4
|
public Button createButton(String sText, int iWidth, int iHeight)... |
140 |
|
{ |
141 |
4
|
Button btn = new Button(this); |
142 |
4
|
btn.setText(sText); |
143 |
4
|
btn.setLayoutParams(new LayoutParams(iWidth, iHeight)); |
144 |
4
|
return btn; |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
147 |
2
|
public TextView createLabel(String sText, int iWidth, int iHeight)... |
148 |
|
{ |
149 |
2
|
TextView label = new TextView(this); |
150 |
2
|
label.setText(sText); |
151 |
2
|
label.setLayoutParams(new LayoutParams(iWidth, iHeight)); |
152 |
2
|
return label; |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
155 |
2
|
private void getDataFromSliders()... |
156 |
|
{ |
157 |
2
|
iHour = timeSliderHour.getValue(); |
158 |
2
|
iMinutes = timeSliderMinutes.getValue(); |
159 |
|
} |
160 |
|
|
|
|
| 78,6% |
Uncovered Elements: 3 (14) |
Complexity: 2 |
Complexity Density: 0,17 |
|
161 |
2
|
public void generateBottomButtons(LinearLayout layBottomControls)... |
162 |
|
{ |
163 |
2
|
TextView labMargin = createLabel("", 8, android.view.ViewGroup.LayoutParams.FILL_PARENT); |
164 |
|
|
165 |
2
|
btnNone = createButton(sStrNone, iSmallButtonWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); |
166 |
2
|
btnNone.setBackgroundResource(android.R.drawable.btn_default_small); |
167 |
|
|
168 |
2
|
btnOK = createButton(sStrSet, iSmallButtonWidth, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); |
169 |
2
|
btnOK.setBackgroundResource(android.R.drawable.btn_default_small); |
170 |
|
|
171 |
|
|
172 |
2
|
btnNone.setOnClickListener(new Button.OnClickListener() |
173 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
174 |
0
|
public void onClick(View arg0) {... |
175 |
0
|
clearTime(); |
176 |
0
|
OnClose(); |
177 |
|
}}); |
178 |
|
|
179 |
2
|
btnOK.setOnClickListener(new Button.OnClickListener() |
180 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
181 |
2
|
public void onClick(View arg0) {... |
182 |
2
|
getDataFromSliders(); |
183 |
2
|
OnClose(); |
184 |
|
}}); |
185 |
|
|
186 |
2
|
layBottomControls.setGravity(Gravity.CENTER_HORIZONTAL); |
187 |
2
|
if (bNoneButton) |
188 |
|
{ |
189 |
0
|
layBottomControls.addView(btnNone); |
190 |
0
|
layBottomControls.addView(labMargin); |
191 |
|
} |
192 |
2
|
layBottomControls.addView(btnOK); |
193 |
|
} |
194 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
195 |
2
|
private View createLabelCaption()... |
196 |
|
{ |
197 |
2
|
labCaption = new TimeCaption(this, b24HourMode, iSliderViewWidth - 120); |
198 |
2
|
return labCaption; |
199 |
|
} |
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0,04 |
|
201 |
2
|
private View generateContentView()... |
202 |
|
{ |
203 |
2
|
LinearLayout layMain = createLayout(LinearLayout.VERTICAL); |
204 |
2
|
layMain.setPadding(8, 8, 8, 8); |
205 |
|
|
206 |
2
|
LinearLayout layTopControls = createLayout(LinearLayout.HORIZONTAL); |
207 |
2
|
LinearLayout layContentTop = createLayout(LinearLayout.HORIZONTAL); |
208 |
2
|
LinearLayout layContentBottom = createLayout(LinearLayout.HORIZONTAL); |
209 |
2
|
LinearLayout layBottomControls = createLayout(LinearLayout.HORIZONTAL); |
210 |
2
|
LinearLayout layMargin = createLayout(LinearLayout.HORIZONTAL); |
211 |
2
|
layContent = createLayout(LinearLayout.VERTICAL); |
212 |
|
|
213 |
2
|
layTopControls.addView(createLabelCaption()); |
214 |
2
|
layTopControls.setGravity(Gravity.CENTER_HORIZONTAL); |
215 |
|
|
216 |
2
|
generateBottomButtons(layBottomControls); |
217 |
|
|
218 |
2
|
layContentTop.getLayoutParams().height = 16; |
219 |
2
|
layContentBottom.getLayoutParams().height = 18; |
220 |
2
|
layMargin.getLayoutParams().height = 18; |
221 |
|
|
222 |
2
|
timeSliderHour = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_HOURS, iSliderViewWidth); |
223 |
2
|
timeSliderMinutes = new TimeWidgetSlider(this, b24HourMode, TimeWidgetSlider.STYPE_MINUTES, iSliderViewWidth); |
224 |
|
|
225 |
2
|
timeSliderHour.setTimeChangeEvent(mOnTimeChangeEvent); |
226 |
2
|
timeSliderMinutes.setTimeChangeEvent(mOnTimeChangeEvent); |
227 |
|
|
228 |
2
|
layContent.addView(timeSliderHour); |
229 |
2
|
layContent.addView(layMargin); |
230 |
2
|
layContent.addView(timeSliderMinutes); |
231 |
|
|
232 |
2
|
layMain.addView(layTopControls); |
233 |
2
|
layMain.addView(layContentTop); |
234 |
2
|
layMain.addView(layContent); |
235 |
2
|
layMain.addView(layContentBottom); |
236 |
2
|
layMain.addView(layBottomControls); |
237 |
|
|
238 |
2
|
return layMain; |
239 |
|
} |
240 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
|
241 |
2
|
public void OnClose()... |
242 |
|
{ |
243 |
2
|
Bundle data = new Bundle(); |
244 |
2
|
data.putInt("Hour", iHour); |
245 |
2
|
data.putInt("Minute", iMinutes); |
246 |
|
|
247 |
2
|
Intent intentData = new Intent(""); |
248 |
2
|
intentData.putExtras(data); |
249 |
2
|
setResult(RESULT_OK, intentData); |
250 |
|
|
251 |
2
|
this.finish(); |
252 |
|
} |
253 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
254 |
0
|
public void clearTime()... |
255 |
|
{ |
256 |
0
|
iHour = -1; |
257 |
0
|
iMinutes = -1; |
258 |
|
} |
259 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
260 |
27
|
public void updateLabelCaption()... |
261 |
|
{ |
262 |
27
|
labCaption.setTime(timeSliderHour.getValue(), timeSliderMinutes.getValue()); |
263 |
|
} |
264 |
|
|
265 |
|
private TimeWidgetSlider.OnTimeChange mOnTimeChangeEvent = new TimeWidgetSlider.OnTimeChange() |
266 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
267 |
27
|
public void OnChange(TimeWidgetSlider slider)... |
268 |
|
{ |
269 |
27
|
updateLabelCaption(); |
270 |
|
} |
271 |
|
}; |
272 |
|
|
273 |
|
} |