Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../img/srcFileCovDistChart8.png 73% of files have more coverage
109   326   48   4,36
46   261   0,44   8,33
25     1,92  
3    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  CommonActivity       Line # 12 109 48 78,3% 0.78333336
  CommonActivity.StartMode       Line # 15 0 0 - -1.0
  CommonActivity.Action       Line # 20 0 0 - -1.0
 
No Tests
 
1    package pl.magot.vetch.ancal;
2   
3    import java.util.Calendar;
4   
5    import pl.magot.vetch.ancal.database.DataTable;
6    import pl.magot.vetch.ancal.database.Database;
7    import pl.magot.vetch.ancal.reminder.*;
8    import android.app.Activity;
9    import android.content.Intent;
10    import android.os.Bundle;
11   
 
12    public abstract class CommonActivity extends Activity
13    {
14    // enum
 
15    public enum StartMode
16    {
17    Default, EDIT, NEW, VIEW
18    };
19   
 
20    public enum Action
21    {
22    Default, ShowMsg
23    };
24   
25    // consts
26    public static final String bundleOptionsUpdated = "OptionsUpdated";
27    public static final String bundleTableUpdated = "TableUpdated";
28    public static final String bundleRowId = "RowId";
29    public static final String bundleHourOfDay = "HourOfDay";
30    public static final String bundleMinutes = "Minutes";
31    public static final String bundleAgendaView = "CurrentAgendaView";
32    public static final String bundleAgendaViewStartDate = "AgendaViewStartDate";
33   
34    // fields
35    private StartMode startMode = StartMode.Default;
36    private Bundle bundleDataStartup = new Bundle();
37    protected Bundle bundleOtherDataStartup = new Bundle();
38    protected Bundle bundleDateValues = new Bundle();
39   
40    // fields
41    public Prefs prefs = null;
42    public Utils utils = null;
43    public Database userdb = null;
44   
45    protected Bundle freeze = null;
46   
47    // methods
 
48  27 toggle public CommonActivity()
49    {
50    }
51   
 
52  27 toggle @Override
53    public void onCreate(Bundle icicle)
54    {
55  27 super.onCreate(icicle);
56   
57  27 freeze = null;
58  27 if (icicle != null)
59  0 freeze = new Bundle(icicle);
60   
61    // initialize base objects
62  27 prefs = new Prefs(this);
63  27 utils = new Utils(this);
64  27 userdb = new Database(this);
65    }
66   
 
67  50 toggle @Override
68    public void onStart()
69    {
70  50 super.onStart();
71   
72    }
73   
 
74  66 toggle @Override
75    public void onResume()
76    {
77  66 super.onResume();
78   
79    }
80   
 
81  50 toggle @Override
82    public void onStop()
83    {
84  50 super.onStop();
85   
86    }
87   
 
88  26 toggle @Override
89    public void onDestroy()
90    {
91  26 super.onDestroy();
92   
93    // close database
94  26 userdb.Close();
95    }
96   
 
97  122 toggle public StartMode GetStartMode()
98    {
99  122 startMode = StartMode.Default;
100  122 String sAction = getIntent().getAction();
101  122 if (sAction.contains("ACTION_MODE_NEW"))
102  75 startMode = StartMode.NEW;
103  122 if (sAction.contains("ACTION_MODE_EDIT"))
104  47 startMode = StartMode.EDIT;
105  122 if (sAction.contains("ACTION_MODE_VIEW"))
106  0 startMode = StartMode.VIEW;
107  122 return startMode;
108    }
109   
 
110  75 toggle public void SetActivityTitle(String sSubTitle)
111    {
112  75 String sTitle = getResources().getString(R.string.app_name);
113  75 if (sSubTitle.length() > 0)
114  75 sTitle += ": " + sSubTitle;
115  75 setTitle(sTitle);
116    }
117   
 
118  19 toggle public void OpenActivity(int iActivityRequestCode, String sAction)
119    {
120  19 OpenActivity(iActivityRequestCode, sAction, -1);
121    }
122   
 
123  27 toggle public void OpenActivity(int iActivityRequestCode, String sAction, long lRowId)
124    {
125  27 bundleDataStartup.clear();
126  27 bundleDataStartup.putLong(CommonActivity.bundleRowId, lRowId);
127  27 bundleDataStartup.putAll(bundleOtherDataStartup);
128  27 Intent it = new Intent(sAction);
129  27 it.putExtras(bundleDataStartup);
130  27 startActivityForResult(it, iActivityRequestCode);
131    }
132   
 
133  1 toggle private void ParseBundledAction(Bundle extras)
134    {
135  1 if (extras.containsKey("action"))
136    {
137  0 Action an = Action.valueOf(extras.getString("action"));
138   
139    // check result action of subactivity startup
140  0 if (an == Action.ShowMsg)
141    {
142  0 int iMsgId = extras.getInt("msgResStrId");
143  0 MessageType msgType = MessageType.create(extras.getInt("msgType"));
144    // show result message
145  0 utils.ShowMsgResStr(iMsgId, msgType);
146    }
147    }
148    }
149   
 
150  0 toggle private Bundle PutBundledMessage(int iMsgId)
151    {
152  0 Bundle extras = new Bundle();
153  0 extras.putInt("msgResStrId", iMsgId);
154  0 extras.putInt("msgType", MessageType.ERROR.getId());
155  0 extras.putString("action", Action.ShowMsg.toString());
156  0 return extras;
157    }
158   
 
159  76 toggle public static Bundle getIntentExtras(Intent data)
160    {
161    // data is null, when activity cancelled by BACK BUTTON
162  76 if (data != null)
163    {
164  74 Bundle extras = data.getExtras();
165  74 if (extras != null)
166    {
167  74 return extras;
168    }
169    }
170  2 return null;
171    }
172   
 
173  37 toggle @Override
174    protected void onActivityResult(int requestCode, int resultCode, Intent data)
175    {
176  37 super.onActivityResult(requestCode, resultCode, data);
177   
178  37 Bundle extras = getIntentExtras(data);
179  37 if (extras != null)
180    {
181  36 if (resultCode == RESULT_CANCELED)
182    {
183  1 ParseBundledAction(extras);
184    }
185  36 if (resultCode == RESULT_OK)
186    {
187    // OK RESULT parsed in parent class
188    }
189    }
190    }
191   
 
192  22 toggle protected void setIntentResult(String action, int resultCode, Bundle bundle)
193    {
194  22 Intent intentData = new Intent(action);
195  22 intentData.putExtras(bundle);
196  22 setResult(resultCode, intentData);
197    }
198   
 
199  8 toggle public boolean OpenDataForEdit(DataTable data)
200    {
201  8 long lRowId = RequestedRowId();
202  8 Database.Result result = data.GetRowDataForEdit(lRowId);
203  8 if (result == Database.Result.Success)
204    {
205    // save date values for change test
206  8 SaveDateValuesBeforeChange(bundleDateValues);
207   
208  8 return true;
209    } else
210    {
211    // return fail result for caller
212  0 int iMsgId = Database.GetErrDesc(result);
213  0 Bundle extras = PutBundledMessage(iMsgId);
214  0 setIntentResult("", RESULT_CANCELED, extras);
215   
216  0 return false;
217    }
218    }
219   
 
220  29 toggle public long RequestedRowId()
221    {
222  29 return getIntent().getExtras().getLong(CommonActivity.bundleRowId);
223    }
224   
 
225  18 toggle public boolean SaveDataToTable(DataTable data)
226    {
227  18 boolean bSuccess = false;
228    // update data into database
229  18 if (data.GetDataRow().Validate())
230    {
231  18 boolean bInsertMode = (GetStartMode() == StartMode.NEW);
232  18 long lRowId = RequestedRowId();
233  18 Database.Result result = data.UpdateData(bInsertMode, lRowId);
234  18 if (result == Database.Result.Success)
235    {
236    // if important dates changed, reset alarm
237  18 if (DateValuesChanged(bundleDateValues))
238  1 AlarmsManager.ResetAlarm(userdb, prefs, data, lRowId);
239   
240  18 bSuccess = true;
241    } else
242    {
243  0 utils.ShowMsgResStr(Database.GetErrDesc(result), MessageType.ERROR);
244    }
245    } else
246    {
247  0 utils
248    .ShowMsgResStr(R.string.infoEnterAllRequiredData, MessageType.INFO);
249    }
250  18 return bSuccess;
251    }
252   
 
253  5 toggle public boolean DateBeforeNow(Calendar calDate)
254    {
255  5 Calendar calNow = Calendar.getInstance();
256  5 if (calNow.get(Calendar.YEAR) == calDate.get(Calendar.YEAR))
257  4 if (calNow.get(Calendar.MONTH) == calDate.get(Calendar.MONTH))
258  4 if (calNow.get(Calendar.DAY_OF_MONTH) == calDate
259    .get(Calendar.DAY_OF_MONTH))
260  4 return false;
261  1 if (calDate.before(calNow))
262    {
263  0 utils.ShowMsgResStr(R.string.infoEnterValidDate, MessageType.INFO);
264  0 return true;
265    }
266  1 return false;
267    }
268   
 
269  1 toggle public void CloseActivity(String sCode, String sValue)
270    {
271  1 Bundle bundleDataResult = new Bundle();
272  1 bundleDataResult.putString(sCode, sValue);
273   
274  1 setIntentResult("", RESULT_OK, bundleDataResult);
275  1 finish();
276    }
277   
 
278  21 toggle public void CloseActivity(DataTable data)
279    {
280  21 Bundle bundleDataResult = new Bundle();
281  21 bundleDataResult.putString(bundleTableUpdated, data.GetTableName());
282   
283  21 setIntentResult("", RESULT_OK, bundleDataResult);
284  21 finish();
285    }
286   
 
287  3 toggle public boolean DeleteDataFromTable(DataTable data)
288    {
289  3 boolean bSuccess = false;
290  3 long lRowId = RequestedRowId();
291  3 Database.Result result = data.DeleteData(lRowId);
292  3 if (result == Database.Result.Success)
293    {
294    // check if alarm for delete and delete it
295  3 AlarmsManager.DeleteAlarm(userdb, prefs, data, lRowId);
296   
297  3 bSuccess = true;
298    } else
299    {
300  0 utils.ShowMsgResStr(Database.GetErrDesc(result), MessageType.ERROR);
301    }
302  3 return bSuccess;
303    }
304   
 
305  8 toggle public void SaveDateValuesBeforeChange(Bundle data)
306    {
307  8 if (data != null)
308  8 data.clear();
309    }
310   
 
311  18 toggle public boolean DateValuesChanged(Bundle data)
312    {
313  18 return false;
314    }
315   
 
316  21 toggle protected void restoreStateFromFreezeIfRequired()
317    {
318  21 if (freeze != null)
319    {
320  0 restoreStateFromFreeze();
321    }
322    }
323   
324    abstract protected void restoreStateFromFreeze();
325   
326    }