Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../../img/srcFileCovDistChart9.png 40% of files have more coverage
175   444   63   6,25
64   340   0,36   28
28     2,25  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ActivityAppointment       Line # 23 175 63 87,6% 0.8764045
 
No Tests
 
1    /**
2    * 15-12-2007
3    * @author Piotr
4    */
5    package pl.magot.vetch.ancal.activities;
6   
7   
8    import java.util.*;
9    import pl.magot.vetch.widgets.*;
10    import pl.magot.vetch.ancal.AnCalDateUtils;
11    import pl.magot.vetch.ancal.CommonActivity;
12    import pl.magot.vetch.ancal.R;
13    import pl.magot.vetch.ancal.RepeatData;
14    import pl.magot.vetch.ancal.database.DataRowAppointment;
15    import pl.magot.vetch.ancal.database.DataTable;
16    import android.content.Intent;
17    import android.os.Bundle;
18    import android.widget.*;
19    import android.view.*;
20   
21   
22    //New appointment activity
 
23    public class ActivityAppointment extends CommonActivity
24    {
25    //fields
26    private Calendar dateStart = null;
27    private DataRowAppointment dataRow = null;
28    private DataTable dataTable = null;
29   
30    //views
31    private TouchEdit edSubject = null;
32    private Button btnStartDate = null;
33    private Button btnStartTime = null;
34    private CheckBox chkAllDay = null;
35    private CheckBox chkAlarm = null;
36    private Button btnRepeatSelect = null;
37   
38    private ImageButton btnDelete = null;
39    private ImageButton btnSave = null;
40   
41    //repeat data
42    private int iRepeatType = -1;
43    private int iRepeatEvery = 0;
44    private Calendar dateEndOn = null;
45   
46    //methods
 
47  9 toggle @Override
48    public void onCreate(Bundle icicle)
49    {
50  9 super.onCreate(icicle);
51  9 setContentView(R.layout.appointment);
52   
53    //initialize objects
54  9 dataRow = new DataRowAppointment(userdb);
55  9 dataTable = new DataTable(dataRow);
56   
57    //check startup mode and open data
58  9 if (GetStartMode() == StartMode.EDIT)
59  3 if (!OpenDataForEdit(dataTable))
60  0 finish();
61   
62    //initialize views
63  9 InitViews();
64  9 InitState();
65    }
66   
 
67  9 toggle @Override
68    public void onStart()
69    {
70  9 super.onStart();
71   
72    }
73   
 
74  21 toggle @Override
75    public void onResume()
76    {
77  21 super.onResume();
78   
79    }
80   
 
81  21 toggle @Override
82    public void onPause()
83    {
84  21 super.onPause();
85   
86    }
87   
 
88  9 toggle private void InitViews()
89    {
90  9 edSubject = (TouchEdit)findViewById(R.id.edAppointmentSubject);
91  9 edSubject.setOnOpenKeyboard(new TouchEdit.OnOpenKeyboard()
92    {
 
93  5 toggle public void OnOpenKeyboardEvent()
94    {
95  5 KeyboardWidget.Open(ActivityAppointment.this, edSubject.getText().toString());
96    }
97    });
98   
99  9 btnStartDate = (Button)findViewById(R.id.btnAppointmentStartDate);
100  9 btnStartTime = (Button)findViewById(R.id.btnAppointmentStartTime);
101  9 chkAllDay = (CheckBox)findViewById(R.id.chkAppointmentAllDay);
102  9 chkAlarm = (CheckBox)findViewById(R.id.chkAppointmentAlarm);
103   
104  9 btnRepeatSelect = (Button)findViewById(R.id.btnRepeatSelect);
105  9 btnRepeatSelect.setOnClickListener(new View.OnClickListener() {
 
106  4 toggle public void onClick(View v) {
107  4 OpenRepeatDialog();
108    }
109    });
110   
111  9 btnSave = (ImageButton)findViewById(R.id.btnAppointmentSave);
112  9 btnSave.setOnClickListener(new View.OnClickListener() {
 
113  8 toggle public void onClick(View v) {
114  8 SaveData();
115    }
116    });
117   
118  9 btnDelete = (ImageButton)findViewById(R.id.btnAppointmentDelete);
119  9 btnDelete.setOnClickListener(new View.OnClickListener() {
 
120  1 toggle public void onClick(View v) {
121  1 DeleteData();
122    }
123    });
124   
125  9 btnStartDate.setOnClickListener(new View.OnClickListener() {
 
126  2 toggle public void onClick(View v) {
127   
128  2 DateWidget.Open(ActivityAppointment.this, false, dateStart, prefs.iFirstDayOfWeek);
129   
130    }
131    });
132   
133  9 btnStartTime.setOnClickListener(new View.OnClickListener() {
 
134  2 toggle public void onClick(View v) {
135   
136  2 TimeWidget.Open(ActivityAppointment.this, false, prefs.b24HourMode,
137    dateStart.get(Calendar.HOUR_OF_DAY), dateStart.get(Calendar.MINUTE));
138   
139    }
140    });
141   
142  9 chkAllDay.setOnClickListener(new View.OnClickListener() {
 
143  4 toggle public void onClick(View v) {
144  4 UpdateStartDateTimeView();
145    }
146    });
147   
148    }
149   
 
150  6 toggle private void SetStartDateByAgendaView(Calendar calDate)
151    {
152  6 if (getIntent() != null)
153    {
154  6 Bundle extras = getIntent().getExtras();
155  6 if (extras != null)
156    {
157  6 if (extras.containsKey(CommonActivity.bundleAgendaView))
158    {
159  6 int iView = extras.getInt(CommonActivity.bundleAgendaView);
160  6 if (iView == 1) //day
161    {
162  2 long lStartDate = extras.getLong(CommonActivity.bundleAgendaViewStartDate);
163  2 calDate.setTimeInMillis(lStartDate);
164    }
165    }
166    }
167    }
168    }
169   
 
170  6 toggle private void SetStartTimeForDayAgendaView(Calendar calDate)
171    {
172  6 if (getIntent() != null)
173    {
174  6 Bundle extras = getIntent().getExtras();
175  6 if (extras != null)
176    {
177  6 if (extras.containsKey(CommonActivity.bundleHourOfDay))
178    {
179  0 int iView = extras.getInt(CommonActivity.bundleAgendaView);
180  0 if (iView == 1) //day
181    {
182  0 int iHourOfDay = extras.getInt(CommonActivity.bundleHourOfDay);
183  0 int iMinutes = extras.getInt(CommonActivity.bundleMinutes);
184  0 calDate.set(Calendar.HOUR_OF_DAY, iHourOfDay);
185  0 calDate.set(Calendar.MINUTE, iMinutes);
186    }
187    }
188    }
189    }
190    }
191   
 
192  6 toggle private void updateStartDateTimeForNewAppointment(Calendar calDate)
193    {
194  6 int iHour = calDate.get(Calendar.HOUR_OF_DAY);
195  6 int iMinute = calDate.get(Calendar.MINUTE);
196   
197  6 if (iHour < 23)
198  6 iHour += 1;
199  6 iMinute = 0;
200   
201  6 calDate.set(Calendar.HOUR_OF_DAY, iHour);
202  6 calDate.set(Calendar.MINUTE, iMinute);
203  6 calDate.set(Calendar.SECOND, 0);
204  6 calDate.set(Calendar.MILLISECOND, 0);
205    }
206   
 
207  9 toggle private void InitState()
208    {
209    //title
210  9 String sSubTitle = utils.GetResStr(R.string.titleDefaultAppointment);
211   
212    //date values
213  9 dateStart = Calendar.getInstance();
214  9 dateEndOn = Calendar.getInstance();
215   
216  9 dataRow.SetDuration(prefs.iMinutesDuration);
217   
218    //INSERT MODE
219  9 if (GetStartMode() == StartMode.NEW)
220    {
221  6 sSubTitle = utils.GetResStr(R.string.titleNewAppointment);
222  6 btnDelete.setVisibility(View.INVISIBLE);
223   
224    //initialize data
225  6 SetStartDateByAgendaView(dateStart);
226  6 updateStartDateTimeForNewAppointment(dateStart);
227  6 SetStartTimeForDayAgendaView(dateStart);
228   
229  6 chkAllDay.setChecked(false);
230  6 chkAlarm.setChecked(true);
231   
232    //repeat data
233  6 iRepeatType = 0; //none
234  6 iRepeatEvery = 1;
235  6 dateEndOn.setTimeInMillis(0); //no end date
236    }
237   
238    //EDIT MODE
239  9 if (GetStartMode() == StartMode.EDIT)
240    {
241  3 sSubTitle = utils.GetResStr(R.string.titleEditAppointment);
242   
243  3 dateStart.setTimeInMillis(dataRow.GetStartDate().getTimeInMillis());
244   
245  3 btnDelete.setVisibility(View.VISIBLE);
246  3 edSubject.setText(dataRow.GetSubject());
247  3 chkAllDay.setChecked(dataRow.GetAllDay());
248  3 chkAlarm.setChecked(dataRow.GetAlarm());
249   
250    //repeat data
251  3 iRepeatType = dataRow.GetRepeat().GetRepeatTypeAsInt();
252  3 iRepeatEvery = dataRow.GetRepeat().GetEvery();
253  3 dateEndOn.setTimeInMillis(dataRow.GetRepeat().GetEndOnDate().getTimeInMillis());
254    }
255   
256  9 restoreStateFromFreezeIfRequired();
257   
258  9 SetActivityTitle(sSubTitle);
259  9 UpdateStartDateTimeView();
260   
261  9 UpdateRepeatInfo();
262   
263    //set focus to subject
264  9 edSubject.requestFocus();
265  9 if (GetStartMode() == StartMode.EDIT)
266  3 edSubject.setSelection(edSubject.length());
267    }
268   
 
269  13 toggle private void UpdateRepeatInfo()
270    {
271  13 btnRepeatSelect.setText(GetRepeatInfo());
272    }
273   
 
274  13 toggle private String GetRepeatInfo()
275    {
276  13 String s = utils.GetResStr(R.string.strRepeatTypeNone);
277  13 String sUntil = utils.GetResStr(R.string.strRepeatInfoUntil);
278  13 String sEndDate = (dateEndOn.getTimeInMillis() == 0)?"":" " + sUntil + " " + AnCalDateUtils.formatMediumDate(this, dateEndOn);
279    //daily
280  13 if (iRepeatType == 1)
281  2 s = String.format(utils.GetResStr(R.string.strRepeatInfoDaily), iRepeatEvery, sEndDate);
282    //weekly
283  13 if (iRepeatType == 2)
284  2 s = String.format(utils.GetResStr(R.string.strRepeatInfoWeekly), iRepeatEvery, sEndDate);
285    //monthly
286  13 if (iRepeatType == 3)
287  2 s = String.format(utils.GetResStr(R.string.strRepeatInfoMonthly), iRepeatEvery, sEndDate);
288    //monthly
289  13 if (iRepeatType == 4)
290  1 s = String.format(utils.GetResStr(R.string.strRepeatInfoYearly), sEndDate);
291  13 return s;
292    }
293   
 
294  17 toggle private void UpdateStartDateTimeView()
295    {
296  17 btnStartDate.setText(AnCalDateUtils.formatMediumDate(this, dateStart));
297  17 if (chkAllDay.isChecked())
298    {
299  8 btnStartTime.setText(utils.GetResStr(R.string.labNoTime));
300    } else {
301  9 btnStartTime.setText(AnCalDateUtils.formatTime(this, dateStart));
302    }
303    }
304   
 
305  0 toggle protected void onSizeChanged(int w, int h, int oldw, int oldh)
306    {
307   
308    }
309   
 
310  8 toggle public void SaveData()
311    {
312    //check date if no repeat
313  8 if ((iRepeatType == 0) && (DateBeforeNow(dateStart)))
314  0 return;
315   
316  8 dataRow.SetSubject(edSubject.getText().toString());
317  8 dataRow.SetStartDate(dateStart);
318  8 dataRow.SetAllDay(chkAllDay.isChecked());
319  8 dataRow.SetAlarm(chkAlarm.isChecked());
320   
321    //set repeat type
322  8 RepeatData rd = dataRow.GetRepeat();
323  8 rd.SetRepeatTypeAsInt(iRepeatType);
324  8 rd.SetEvery(iRepeatEvery);
325  8 rd.SetEndOnDate(dateEndOn.getTimeInMillis());
326   
327  8 if (SaveDataToTable(dataTable))
328  8 CloseActivity(dataTable);
329    }
330   
 
331  1 toggle public void DeleteData()
332    {
333  1 if (DeleteDataFromTable(dataTable))
334  1 CloseActivity(dataTable);
335    }
336   
 
337  13 toggle @Override
338    protected void onActivityResult(int requestCode, int resultCode, Intent data)
339    {
340  13 super.onActivityResult(requestCode, resultCode, data);
341   
342  13 Bundle extras = CommonActivity.getIntentExtras(data);
343  13 if (extras != null)
344    {
345   
346    //check for repeat update
347  13 if (ActivityAppointmentRepeat.GetActivityResult(requestCode, resultCode, extras))
348    {
349  4 iRepeatType = ActivityAppointmentRepeat.getExtraRepeatType(extras);
350  4 iRepeatEvery = ActivityAppointmentRepeat.getExtraRepeatEvery(extras);
351  4 dateEndOn.setTimeInMillis(ActivityAppointmentRepeat.getExtraRepeatEndOnDate(extras));
352  4 UpdateRepeatInfo();
353  4 return;
354    }
355   
356    //check for date widget edit request code
357  9 if (requestCode == DateWidget.SELECT_DATE_REQUEST)
358    {
359  2 final long lDate = DateWidget.GetSelectedDateOnActivityResult(requestCode, resultCode, extras, dateStart);
360  2 if (lDate != -1)
361    {
362  2 UpdateStartDateTimeView();
363  2 return;
364    }
365    }
366   
367    //check for time widget edit request code
368  7 if ((requestCode == TimeWidget.SELECT_TIME_REQUEST) && (resultCode == RESULT_OK))
369    {
370  2 final int iHour = TimeWidget.GetSelectedTimeHourOnActivityResult(requestCode, resultCode, extras);
371  2 final int iMinute = TimeWidget.GetSelectedTimeMinuteOnActivityResult(requestCode, resultCode, extras);
372  2 dateStart.set(Calendar.HOUR_OF_DAY, iHour);
373  2 dateStart.set(Calendar.MINUTE, iMinute);
374  2 chkAllDay.setChecked(false);
375  2 UpdateStartDateTimeView();
376  2 return;
377    }
378   
379    //get KeyboardWidget result
380  5 if ((requestCode == KeyboardWidget.EDIT_TEXT_REQUEST) && (resultCode == RESULT_OK))
381    {
382  4 String sText = KeyboardWidget.GetTextOnActivityResult(requestCode, resultCode, extras);
383  4 edSubject.setText(sText);
384  4 return;
385    }
386   
387    }
388    }
389   
 
390  4 toggle public void OpenRepeatDialog()
391    {
392  4 ActivityAppointmentRepeat.OpenRepeatForEdit(this, bundleOtherDataStartup, iRepeatType, iRepeatEvery, dateEndOn.getTimeInMillis());
393    }
394   
 
395  3 toggle @Override
396    public void SaveDateValuesBeforeChange(Bundle data)
397    {
398  3 super.SaveDateValuesBeforeChange(data);
399  3 if (GetStartMode() == StartMode.EDIT)
400    {
401  3 data.putLong("dateStart", dataRow.GetStartDate().getTimeInMillis());
402  3 data.putLong("dateEndOn", dataRow.GetRepeat().GetEndOnDate().getTimeInMillis());
403    }
404    }
405   
 
406  8 toggle @Override
407    public boolean DateValuesChanged(Bundle data)
408    {
409  8 super.DateValuesChanged(data);
410  8 if (GetStartMode() == StartMode.EDIT)
411    {
412  2 if (dateStart.getTimeInMillis() != data.getLong("dateStart"))
413  1 return true;
414    }
415  7 return false;
416    }
417   
 
418  12 toggle @Override
419    protected void onSaveInstanceState(Bundle outState)
420    {
421  12 super.onSaveInstanceState(outState);
422    //save controls state
423  12 outState.putString("subject", edSubject.getText().toString());
424  12 outState.putBoolean("alarm", chkAlarm.isChecked());
425  12 outState.putLong("dateStart", dateStart.getTimeInMillis());
426  12 outState.putBoolean("allday", chkAllDay.isChecked());
427  12 outState.putInt("repeatType", iRepeatType);
428  12 outState.putInt("repeatEvery", iRepeatEvery);
429  12 outState.putLong("dateEndOn", dateEndOn.getTimeInMillis());
430    }
431   
 
432  0 toggle @Override
433    protected void restoreStateFromFreeze()
434    {
435  0 edSubject.setText(freeze.getString("subject"));
436  0 chkAlarm.setChecked(freeze.getBoolean("alarm"));
437  0 dateStart.setTimeInMillis(freeze.getLong("dateStart"));
438  0 chkAllDay.setChecked(freeze.getBoolean("allday"));
439  0 iRepeatType = freeze.getInt("repeatType");
440  0 iRepeatEvery = freeze.getInt("repeatEvery");
441  0 dateEndOn.setTimeInMillis(freeze.getLong("dateEndOn"));
442    }
443   
444    }