1 |
|
|
2 |
|
package pl.magot.vetch.ancal.activities; |
3 |
|
|
4 |
|
|
5 |
|
import java.util.*; |
6 |
|
|
7 |
|
import pl.magot.vetch.ancal.*; |
8 |
|
import pl.magot.vetch.widgets.DateWidget; |
9 |
|
import android.app.*; |
10 |
|
import android.content.Intent; |
11 |
|
import android.os.Bundle; |
12 |
|
import android.widget.*; |
13 |
|
import android.view.*; |
14 |
|
import android.widget.Button; |
15 |
|
import android.widget.ImageButton; |
16 |
|
import android.widget.LinearLayout; |
17 |
|
|
18 |
|
|
|
|
| 92,6% |
Uncovered Elements: 15 (202) |
Complexity: 53 |
Complexity Density: 0,4 |
|
19 |
|
public class ActivityAppointmentRepeat extends Activity |
20 |
|
{ |
21 |
|
|
22 |
|
private static final int SELECT_REPEAT_REQUEST = 201; |
23 |
|
|
24 |
|
private static final String DATAKEY_TYPE = "RepeatType"; |
25 |
|
private static final String DATAKEY_EVERY = "Every"; |
26 |
|
private static final String DATAKEY_ENDONDATE = "EndOnDate"; |
27 |
|
|
28 |
|
|
29 |
|
public Prefs prefs = null; |
30 |
|
public Utils utils = null; |
31 |
|
|
32 |
|
|
33 |
|
private int iRepeatType = -1; |
34 |
|
private int iRepeatEvery = 0; |
35 |
|
private Calendar calRepeatEnd = Calendar.getInstance(); |
36 |
|
|
37 |
|
|
38 |
|
private LinearLayout llayAppointmentRepeatEvery = null; |
39 |
|
private LinearLayout llayAppointmentRepeatEndOnDateLabel = null; |
40 |
|
private LinearLayout llayAppointmentRepeatEndOnDate = null; |
41 |
|
|
42 |
|
|
43 |
|
private TextView labRepeatEveryValue = null; |
44 |
|
private Button btnEndOnDate = null; |
45 |
|
private Button btnRepeatDone = null; |
46 |
|
|
47 |
|
|
48 |
|
private Button btnRepeatTypeNone = null; |
49 |
|
private Button btnRepeatTypeDaily = null; |
50 |
|
private Button btnRepeatTypeWeekly = null; |
51 |
|
private Button btnRepeatTypeMonthly = null; |
52 |
|
private Button btnRepeatTypeYearly = null; |
53 |
|
|
54 |
|
|
55 |
|
private ImageButton btnRepeatEveryDown = null; |
56 |
|
private ImageButton btnRepeatEveryUp = null; |
57 |
|
|
58 |
|
|
|
|
| 69,2% |
Uncovered Elements: 4 (13) |
Complexity: 2 |
Complexity Density: 0,18 |
|
59 |
4
|
@Override... |
60 |
|
public void onCreate(Bundle icicle) |
61 |
|
{ |
62 |
4
|
super.onCreate(icicle); |
63 |
4
|
setContentView(R.layout.appointmentrepeat); |
64 |
|
|
65 |
4
|
GetExtrasData(); |
66 |
|
|
67 |
|
|
68 |
4
|
if (icicle != null) |
69 |
|
{ |
70 |
0
|
iRepeatType = icicle.getInt("repeat"); |
71 |
0
|
iRepeatEvery = icicle.getInt("every"); |
72 |
0
|
calRepeatEnd.setTimeInMillis(icicle.getLong("dateEndOn")); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
4
|
prefs = new Prefs(this); |
77 |
4
|
utils = new Utils(this); |
78 |
|
|
79 |
|
|
80 |
4
|
InitViews(); |
81 |
4
|
InitState(); |
82 |
|
} |
83 |
|
|
|
|
| 85,7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0,6 |
|
84 |
4
|
public void GetExtrasData()... |
85 |
|
{ |
86 |
4
|
Bundle bundle = getIntent().getExtras(); |
87 |
4
|
if ((bundle != null) && (bundle.containsKey("EditRepeat"))) |
88 |
|
{ |
89 |
4
|
iRepeatType = bundle.getInt(DATAKEY_TYPE); |
90 |
4
|
iRepeatEvery = bundle.getInt(DATAKEY_EVERY); |
91 |
4
|
calRepeatEnd.setTimeInMillis(bundle.getLong(DATAKEY_ENDONDATE)); |
92 |
|
} |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
95 |
2
|
@Override... |
96 |
|
protected void onSaveInstanceState(Bundle outState) |
97 |
|
{ |
98 |
2
|
super.onSaveInstanceState(outState); |
99 |
|
|
100 |
2
|
outState.putInt("repeat", iRepeatType); |
101 |
2
|
outState.putInt("every", iRepeatEvery); |
102 |
2
|
outState.putLong("dateEndOn", calRepeatEnd.getTimeInMillis()); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
4
|
@Override... |
106 |
|
public void onStart() |
107 |
|
{ |
108 |
4
|
super.onStart(); |
109 |
|
|
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
6
|
@Override... |
113 |
|
public void onResume() |
114 |
|
{ |
115 |
6
|
super.onResume(); |
116 |
|
|
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
6
|
@Override... |
120 |
|
public void onPause() |
121 |
|
{ |
122 |
6
|
super.onPause(); |
123 |
|
|
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0,05 |
|
126 |
4
|
private void InitViews()... |
127 |
|
{ |
128 |
4
|
llayAppointmentRepeatEvery = (LinearLayout)findViewById(R.id.llayAppointmentRepeatEvery); |
129 |
4
|
llayAppointmentRepeatEndOnDate = (LinearLayout)findViewById(R.id.llayAppointmentRepeatEndOnDate); |
130 |
4
|
llayAppointmentRepeatEndOnDateLabel = (LinearLayout)findViewById(R.id.llayAppointmentRepeatEndOnDateLabel); |
131 |
|
|
132 |
|
|
133 |
4
|
btnRepeatTypeNone = (Button)findViewById(R.id.btnRepeatTypeNone); |
134 |
4
|
btnRepeatTypeNone.setOnClickListener(new View.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
0
|
public void onClick(View v) {... |
136 |
0
|
SetRepeatType(0); |
137 |
|
} |
138 |
|
}); |
139 |
|
|
140 |
4
|
btnRepeatTypeDaily = (Button)findViewById(R.id.btnRepeatTypeDaily); |
141 |
4
|
btnRepeatTypeDaily.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
2
|
public void onClick(View v) {... |
143 |
2
|
SetRepeatType(1); |
144 |
|
} |
145 |
|
}); |
146 |
|
|
147 |
4
|
btnRepeatTypeWeekly = (Button)findViewById(R.id.btnRepeatTypeWeekly); |
148 |
4
|
btnRepeatTypeWeekly.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
2
|
public void onClick(View v) {... |
150 |
2
|
SetRepeatType(2); |
151 |
|
} |
152 |
|
}); |
153 |
|
|
154 |
4
|
btnRepeatTypeMonthly = (Button)findViewById(R.id.btnRepeatTypeMonthly); |
155 |
4
|
btnRepeatTypeMonthly.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
2
|
public void onClick(View v) {... |
157 |
2
|
SetRepeatType(3); |
158 |
|
} |
159 |
|
}); |
160 |
|
|
161 |
4
|
btnRepeatTypeYearly = (Button)findViewById(R.id.btnRepeatTypeYearly); |
162 |
4
|
btnRepeatTypeYearly.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
2
|
public void onClick(View v) {... |
164 |
2
|
SetRepeatType(4); |
165 |
|
} |
166 |
|
}); |
167 |
|
|
168 |
4
|
btnEndOnDate = (Button)findViewById(R.id.btnAppointmentEndOnDate); |
169 |
|
|
170 |
4
|
btnRepeatDone = (Button)findViewById(R.id.btnRepeatDone); |
171 |
4
|
btnRepeatDone.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
4
|
public void onClick(View v) {... |
173 |
4
|
EditDone(); |
174 |
|
} |
175 |
|
}); |
176 |
|
|
177 |
4
|
btnEndOnDate.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
2
|
public void onClick(View v) {... |
179 |
|
|
180 |
2
|
DateWidget.Open(ActivityAppointmentRepeat.this, true, calRepeatEnd, prefs.iFirstDayOfWeek); |
181 |
|
|
182 |
|
} |
183 |
|
}); |
184 |
|
|
185 |
4
|
labRepeatEveryValue = (TextView)findViewById(R.id.labRepeatEveryValue); |
186 |
|
|
187 |
4
|
btnRepeatEveryDown = (ImageButton)findViewById(R.id.btnRepeatEveryDown); |
188 |
4
|
btnRepeatEveryDown.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
189 |
16
|
public void onClick(View v) {... |
190 |
16
|
iRepeatEvery--; |
191 |
16
|
if (iRepeatEvery < 1) |
192 |
2
|
iRepeatEvery = 1; |
193 |
16
|
UpdateEveryValueView(); |
194 |
|
} |
195 |
|
}); |
196 |
|
|
197 |
4
|
btnRepeatEveryUp = (ImageButton)findViewById(R.id.btnRepeatEveryUp); |
198 |
4
|
btnRepeatEveryUp.setOnClickListener(new View.OnClickListener() { |
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
199 |
21
|
public void onClick(View v) {... |
200 |
21
|
iRepeatEvery++; |
201 |
21
|
if (iRepeatEvery > 30) |
202 |
0
|
iRepeatEvery = 30; |
203 |
21
|
UpdateEveryValueView(); |
204 |
|
} |
205 |
|
}); |
206 |
|
} |
207 |
|
|
|
|
| 94,6% |
Uncovered Elements: 2 (37) |
Complexity: 9 |
Complexity Density: 0,39 |
|
208 |
12
|
public void SetRepeatType(int iRepeatType)... |
209 |
|
{ |
210 |
|
|
211 |
12
|
this.iRepeatType = iRepeatType; |
212 |
|
|
213 |
12
|
btnRepeatTypeNone.setEnabled((iRepeatType != 0)); |
214 |
12
|
btnRepeatTypeDaily.setEnabled((iRepeatType != 1)); |
215 |
12
|
btnRepeatTypeWeekly.setEnabled((iRepeatType != 2)); |
216 |
12
|
btnRepeatTypeMonthly.setEnabled((iRepeatType != 3)); |
217 |
12
|
btnRepeatTypeYearly.setEnabled((iRepeatType != 4)); |
218 |
|
|
219 |
12
|
Button btn = null; |
220 |
12
|
if (iRepeatType == 0) |
221 |
4
|
btn = btnRepeatTypeNone; |
222 |
|
|
223 |
12
|
if (iRepeatType == 1) |
224 |
2
|
btn = btnRepeatTypeDaily; |
225 |
|
|
226 |
12
|
if (iRepeatType == 2) |
227 |
2
|
btn = btnRepeatTypeWeekly; |
228 |
|
|
229 |
12
|
if (iRepeatType == 3) |
230 |
2
|
btn = btnRepeatTypeMonthly; |
231 |
|
|
232 |
12
|
if (iRepeatType == 4) |
233 |
2
|
btn = btnRepeatTypeYearly; |
234 |
|
|
235 |
12
|
if ((btn != null) && (!btn.isFocused())) |
236 |
12
|
btn.requestFocus(); |
237 |
|
|
238 |
12
|
SetActivityTitle(""); |
239 |
12
|
if (btn != null) |
240 |
12
|
SetActivityTitle(btn.getText().toString()); |
241 |
|
|
242 |
12
|
UpdateRepeatViewsState(iRepeatType); |
243 |
|
} |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
245 |
28
|
public void SetActivityTitle(String sSubTitle)... |
246 |
|
{ |
247 |
28
|
String sTitle = utils.GetResStr(R.string.titleDefaultRepeat); |
248 |
28
|
if (sSubTitle.length() > 0) |
249 |
12
|
sTitle += ": " + sSubTitle; |
250 |
28
|
setTitle(sTitle); |
251 |
|
} |
252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
253 |
4
|
private void InitState()... |
254 |
|
{ |
255 |
4
|
SetActivityTitle(""); |
256 |
|
|
257 |
4
|
SetRepeatType(iRepeatType); |
258 |
|
|
259 |
4
|
UpdateEveryValueView(); |
260 |
4
|
UpdateEndOnDateView(); |
261 |
|
} |
262 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
263 |
41
|
private void UpdateEveryValueView()... |
264 |
|
{ |
265 |
41
|
labRepeatEveryValue.setText(Integer.toString(iRepeatEvery)); |
266 |
|
} |
267 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
268 |
12
|
private void UpdateRepeatViewsState(int iRepeatType)... |
269 |
|
{ |
270 |
|
|
271 |
12
|
if (iRepeatType == 0) |
272 |
|
{ |
273 |
4
|
llayAppointmentRepeatEvery.setVisibility(View.GONE); |
274 |
4
|
llayAppointmentRepeatEndOnDate.setVisibility(View.GONE); |
275 |
4
|
llayAppointmentRepeatEndOnDateLabel.setVisibility(View.GONE); |
276 |
|
} else { |
277 |
|
|
278 |
8
|
if (iRepeatType == 4) |
279 |
|
{ |
280 |
2
|
llayAppointmentRepeatEvery.setVisibility(View.GONE); |
281 |
|
} else { |
282 |
6
|
llayAppointmentRepeatEvery.setVisibility(View.VISIBLE); |
283 |
6
|
llayAppointmentRepeatEndOnDate.setVisibility(View.VISIBLE); |
284 |
6
|
llayAppointmentRepeatEndOnDateLabel.setVisibility(View.VISIBLE); |
285 |
|
} |
286 |
|
} |
287 |
|
} |
288 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
289 |
6
|
private void UpdateEndOnDateView()... |
290 |
|
{ |
291 |
6
|
if (calRepeatEnd.getTimeInMillis() != 0) |
292 |
|
{ |
293 |
2
|
btnEndOnDate.setText(AnCalDateUtils.formatMediumDate(this, calRepeatEnd)); |
294 |
|
} else { |
295 |
4
|
btnEndOnDate.setText(utils.GetResStr(R.string.labNoEndDate)); |
296 |
|
} |
297 |
|
} |
298 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
299 |
4
|
public static int getExtraRepeatType(Bundle extras)... |
300 |
|
{ |
301 |
4
|
return extras.getInt(DATAKEY_TYPE); |
302 |
|
} |
303 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
304 |
4
|
public static int getExtraRepeatEvery(Bundle extras)... |
305 |
|
{ |
306 |
4
|
return extras.getInt(DATAKEY_EVERY); |
307 |
|
} |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
309 |
4
|
public static long getExtraRepeatEndOnDate(Bundle extras)... |
310 |
|
{ |
311 |
4
|
return extras.getLong(DATAKEY_ENDONDATE); |
312 |
|
} |
313 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
314 |
4
|
public static void OpenRepeatForEdit(CommonActivity parent, Bundle extras, int iRepeatType, int iEvery, long lEndOnDate)... |
315 |
|
{ |
316 |
4
|
extras.clear(); |
317 |
4
|
extras.putBoolean("EditRepeat", true); |
318 |
4
|
extras.putInt(DATAKEY_TYPE, iRepeatType); |
319 |
4
|
extras.putInt(DATAKEY_EVERY, iEvery); |
320 |
4
|
extras.putLong(DATAKEY_ENDONDATE, lEndOnDate); |
321 |
4
|
parent.OpenActivity(SELECT_REPEAT_REQUEST, "android.intent.action.AnCal.ACTION_MODE_EDIT_APPOINTMENTREPEAT"); |
322 |
|
} |
323 |
|
|
|
|
| 87,5% |
Uncovered Elements: 1 (8) |
Complexity: 5 |
Complexity Density: 1,25 |
|
324 |
13
|
public static boolean GetActivityResult(int requestCode, int resultCode, Bundle extras)... |
325 |
|
{ |
326 |
13
|
if ((requestCode == SELECT_REPEAT_REQUEST) && (resultCode == RESULT_OK)) |
327 |
|
{ |
328 |
4
|
if ((extras != null) && (extras.containsKey("EditRepeat"))) |
329 |
|
{ |
330 |
4
|
return true; |
331 |
|
} |
332 |
|
} |
333 |
9
|
return false; |
334 |
|
} |
335 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
|
336 |
4
|
private void EditDone()... |
337 |
|
{ |
338 |
4
|
Bundle bundleResult = new Bundle(); |
339 |
4
|
bundleResult.putBoolean("EditRepeat", true); |
340 |
4
|
bundleResult.putInt(DATAKEY_TYPE, iRepeatType); |
341 |
4
|
bundleResult.putInt(DATAKEY_EVERY, iRepeatEvery); |
342 |
4
|
bundleResult.putLong(DATAKEY_ENDONDATE, calRepeatEnd.getTimeInMillis()); |
343 |
|
|
344 |
4
|
Intent intentData = new Intent(""); |
345 |
4
|
intentData.putExtras(bundleResult); |
346 |
4
|
this.setResult(RESULT_OK, intentData); |
347 |
|
|
348 |
4
|
finish(); |
349 |
|
} |
350 |
|
|
|
|
| 76,9% |
Uncovered Elements: 3 (13) |
Complexity: 4 |
Complexity Density: 0,57 |
|
351 |
2
|
@Override... |
352 |
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) |
353 |
|
{ |
354 |
2
|
super.onActivityResult(requestCode, resultCode, data); |
355 |
|
|
356 |
2
|
Bundle extras = CommonActivity.getIntentExtras(data); |
357 |
2
|
if (extras != null) |
358 |
|
{ |
359 |
|
|
360 |
2
|
if (requestCode == DateWidget.SELECT_DATE_REQUEST) |
361 |
|
{ |
362 |
2
|
final long lDate = DateWidget.GetSelectedDateOnActivityResult(requestCode, resultCode, extras, calRepeatEnd); |
363 |
2
|
if (lDate != -1) |
364 |
|
{ |
365 |
2
|
UpdateEndOnDateView(); |
366 |
|
} |
367 |
|
} |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
|
} |