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
133   371   53   4,59
40   286   0,4   29
29     1,83  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ActivityAppointmentRepeat       Line # 19 133 53 92,6% 0.92574257
 
No Tests
 
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   
 
19    public class ActivityAppointmentRepeat extends Activity
20    {
21    //fields
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    //fields
29    public Prefs prefs = null;
30    public Utils utils = null;
31   
32    //repeat data
33    private int iRepeatType = -1;
34    private int iRepeatEvery = 0;
35    private Calendar calRepeatEnd = Calendar.getInstance();
36   
37    //layouts
38    private LinearLayout llayAppointmentRepeatEvery = null;
39    private LinearLayout llayAppointmentRepeatEndOnDateLabel = null;
40    private LinearLayout llayAppointmentRepeatEndOnDate = null;
41   
42    //views
43    private TextView labRepeatEveryValue = null;
44    private Button btnEndOnDate = null;
45    private Button btnRepeatDone = null;
46   
47    //repeat buttons
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    //every value buttons
55    private ImageButton btnRepeatEveryDown = null;
56    private ImageButton btnRepeatEveryUp = null;
57   
58    //methods
 
59  4 toggle @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    //restore data from freeze state
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    //initialize base objects
76  4 prefs = new Prefs(this);
77  4 utils = new Utils(this);
78   
79    //initialize views
80  4 InitViews();
81  4 InitState();
82    }
83   
 
84  4 toggle 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   
 
95  2 toggle @Override
96    protected void onSaveInstanceState(Bundle outState)
97    {
98  2 super.onSaveInstanceState(outState);
99    //save controls state
100  2 outState.putInt("repeat", iRepeatType);
101  2 outState.putInt("every", iRepeatEvery);
102  2 outState.putLong("dateEndOn", calRepeatEnd.getTimeInMillis());
103    }
104   
 
105  4 toggle @Override
106    public void onStart()
107    {
108  4 super.onStart();
109   
110    }
111   
 
112  6 toggle @Override
113    public void onResume()
114    {
115  6 super.onResume();
116   
117    }
118   
 
119  6 toggle @Override
120    public void onPause()
121    {
122  6 super.onPause();
123   
124    }
125   
 
126  4 toggle 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    //repeat buttons
133  4 btnRepeatTypeNone = (Button)findViewById(R.id.btnRepeatTypeNone);
134  4 btnRepeatTypeNone.setOnClickListener(new View.OnClickListener() {
 
135  0 toggle 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() {
 
142  2 toggle 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() {
 
149  2 toggle 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() {
 
156  2 toggle 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() {
 
163  2 toggle 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() {
 
172  4 toggle public void onClick(View v) {
173  4 EditDone();
174    }
175    });
176   
177  4 btnEndOnDate.setOnClickListener(new View.OnClickListener() {
 
178  2 toggle 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() {
 
189  16 toggle 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() {
 
199  21 toggle public void onClick(View v) {
200  21 iRepeatEvery++;
201  21 if (iRepeatEvery > 30)
202  0 iRepeatEvery = 30;
203  21 UpdateEveryValueView();
204    }
205    });
206    }
207   
 
208  12 toggle public void SetRepeatType(int iRepeatType)
209    {
210    //update global value
211  12 this.iRepeatType = iRepeatType;
212    //enable buttons
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    // 0: None
219  12 Button btn = null;
220  12 if (iRepeatType == 0)
221  4 btn = btnRepeatTypeNone;
222    // 1: Daily
223  12 if (iRepeatType == 1)
224  2 btn = btnRepeatTypeDaily;
225    // 2: Weekly
226  12 if (iRepeatType == 2)
227  2 btn = btnRepeatTypeWeekly;
228    // 3: Monthly
229  12 if (iRepeatType == 3)
230  2 btn = btnRepeatTypeMonthly;
231    // 4: Yearly
232  12 if (iRepeatType == 4)
233  2 btn = btnRepeatTypeYearly;
234    //set focus
235  12 if ((btn != null) && (!btn.isFocused()))
236  12 btn.requestFocus();
237    //update title info
238  12 SetActivityTitle("");
239  12 if (btn != null)
240  12 SetActivityTitle(btn.getText().toString());
241    //update controls state
242  12 UpdateRepeatViewsState(iRepeatType);
243    }
244   
 
245  28 toggle 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   
 
253  4 toggle private void InitState()
254    {
255  4 SetActivityTitle("");
256   
257  4 SetRepeatType(iRepeatType);
258   
259  4 UpdateEveryValueView();
260  4 UpdateEndOnDateView();
261    }
262   
 
263  41 toggle private void UpdateEveryValueView()
264    {
265  41 labRepeatEveryValue.setText(Integer.toString(iRepeatEvery));
266    }
267   
 
268  12 toggle private void UpdateRepeatViewsState(int iRepeatType)
269    {
270    //change visibility of repeat views
271  12 if (iRepeatType == 0) //none
272    {
273  4 llayAppointmentRepeatEvery.setVisibility(View.GONE);
274  4 llayAppointmentRepeatEndOnDate.setVisibility(View.GONE);
275  4 llayAppointmentRepeatEndOnDateLabel.setVisibility(View.GONE);
276    } else {
277    //yearly
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   
 
289  6 toggle 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   
 
299  4 toggle public static int getExtraRepeatType(Bundle extras)
300    {
301  4 return extras.getInt(DATAKEY_TYPE);
302    }
303   
 
304  4 toggle public static int getExtraRepeatEvery(Bundle extras)
305    {
306  4 return extras.getInt(DATAKEY_EVERY);
307    }
308   
 
309  4 toggle public static long getExtraRepeatEndOnDate(Bundle extras)
310    {
311  4 return extras.getLong(DATAKEY_ENDONDATE);
312    }
313   
 
314  4 toggle 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   
 
324  13 toggle 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   
 
336  4 toggle 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   
 
351  2 toggle @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    //check for date widget edit request code
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    }