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
83   238   32   5,93
26   173   0,39   14
14     2,29  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  AlarmReminder       Line # 18 83 32 99,2% 0.9918699
 
No Tests
 
1   
2    package pl.magot.vetch.ancal.reminder;
3   
4   
5    import pl.magot.vetch.ancal.*;
6    import pl.magot.vetch.ancal.views.*;
7    import java.util.ArrayList;
8    import java.util.Calendar;
9    import android.content.Context;
10    import android.content.Intent;
11    import android.widget.Toast;
12    import android.app.NotificationManager;
13    import android.app.Notification;
14    import android.app.PendingIntent;
15    import android.os.Bundle;
16   
17   
 
18    public class AlarmReminder
19    {
20    //fields
21    private Context context = null;
22    protected AlarmService.AlarmPrefs prefs = null;
23    protected Utils utils = null;
24    private ArrayList<AlarmDataViewItem> alarmItems = new ArrayList<AlarmDataViewItem>();
25    private NotificationManager mNM = null;
26    private final int iNotifyID1 = 1;
27    private int iLastAlarmsHash = 0;
28    private Calendar calHashToday = Calendar.getInstance();
29    //private AlarmSound alarmSound = null;
30   
31    //fields
32    private String msgYouHaveASTS = "";
33    private String msgYouHaveTS = "";
34    private String msgYouHaveAS = "";
35    private String msgASTS = "";
36    private String msgTS = "";
37    private String msgAS = "";
38    private String strReminder = "";
39   
40    //fields
41    private String sAppName = "";
42   
43    //methods
 
44  1 toggle public AlarmReminder(Context ctx, AlarmService.AlarmPrefs prefs, Utils utils)
45    {
46  1 this.context = ctx;
47  1 this.prefs = prefs;
48  1 this.utils = utils;
49   
50  1 sAppName = this.context.getString(R.string.app_name);
51  1 mNM = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
52  1 RemoveNotify();
53   
54    //localize strings
55  1 msgYouHaveASTS = utils.GetResStr(R.string.msgYouHaveASTS);
56  1 msgYouHaveTS = utils.GetResStr(R.string.msgYouHaveTS);
57  1 msgYouHaveAS = utils.GetResStr(R.string.msgYouHaveAS);
58  1 msgASTS = utils.GetResStr(R.string.msgASTS);
59  1 msgTS = utils.GetResStr(R.string.msgTS);
60  1 msgAS = utils.GetResStr(R.string.msgAS);
61  1 strReminder = utils.GetResStr(R.string.strReminder);
62   
63    //get alarm sound
64    //alarmSound = new AlarmSound(context);
65    }
66   
 
67  30 toggle public void Clear()
68    {
69  30 alarmItems.clear();
70    }
71   
 
72  27 toggle public void RemoveNotify()
73    {
74  27 mNM.cancel(iNotifyID1);
75    }
76   
 
77  60 toggle public void AddAlarmData(ArrayList<AlarmDataViewItem> items)
78    {
79  60 this.alarmItems.addAll(items);
80    }
81   
 
82  30 toggle public boolean IsAlarm()
83    {
84  30 return (alarmItems.size() > 0);
85    }
86   
 
87  22 toggle public int GetItemsCount(int iOrderFilter)
88    {
89  22 int iCount = 0;
90  52 for (int index = 0; index < alarmItems.size(); index++)
91    {
92  30 AlarmDataViewItem item = alarmItems.get(index);
93  30 if (item.GetOrder() == iOrderFilter)
94  15 iCount++;
95    }
96  22 return iCount;
97    }
98   
 
99  7 toggle public String GetPopupMsg(int iCountAppts, int iCountTasks)
100    {
101  7 String msg = String.format(msgYouHaveASTS, iCountAppts, iCountTasks);
102  7 if ((iCountAppts == 0) && (iCountTasks > 0))
103  3 msg = String.format(msgYouHaveTS, iCountTasks);
104  7 if ((iCountTasks == 0) && (iCountAppts > 0))
105  4 msg = String.format(msgYouHaveAS, iCountAppts);
106  7 return msg;
107    }
108   
 
109  7 toggle public String GetStatusMsg(int iCountAppts, int iCountTasks)
110    {
111  7 String msg = String.format(msgASTS, iCountAppts, iCountTasks);
112  7 if ((iCountAppts == 0) && (iCountTasks > 0))
113  3 msg = String.format(msgTS, iCountTasks);
114  7 if ((iCountTasks == 0) && (iCountAppts > 0))
115  4 msg = String.format(msgAS, iCountAppts);
116  7 return msg;
117    }
118   
 
119  11 toggle public String GetTodayHashString()
120    {
121  11 calHashToday.setTimeInMillis(System.currentTimeMillis());
122  11 return Integer.toString(calHashToday.get(Calendar.YEAR)) +
123    Integer.toString(calHashToday.get(Calendar.MONTH)) +
124    Integer.toString(calHashToday.get(Calendar.DAY_OF_MONTH));
125    }
126   
 
127  11 toggle public String GetAlarmsHashString()
128    {
129  11 String sMsg = "";
130  26 for (int index = 0; index < alarmItems.size(); index++)
131    {
132  15 AlarmDataViewItem item = alarmItems.get(index);
133  15 sMsg += item.GetHashString();
134    }
135    //add today hash, for changing hash for next day compare (repeat appointments)
136  11 sMsg += GetTodayHashString();
137  11 return sMsg;
138    }
139   
 
140  11 toggle public boolean AlarmsChanged()
141    {
142  11 String sAlarmsHashString = GetAlarmsHashString();
143  11 if (sAlarmsHashString.hashCode() == iLastAlarmsHash)
144  4 return false;
145  7 iLastAlarmsHash = sAlarmsHashString.hashCode();
146  7 return true;
147    }
148   
 
149  14 toggle public void PutDataItemsToBundle(Bundle data, int iOrderFilter)
150    {
151  14 int iKeyIndex = 0;
152  32 for (int i = 0; i < alarmItems.size(); i++)
153    {
154  18 AlarmDataViewItem item = alarmItems.get(i);
155  18 if (item.GetOrder() == iOrderFilter)
156    {
157  9 String sKey = "_" + Integer.toString(iOrderFilter) + "_" + Integer.toString(iKeyIndex);
158   
159  9 data.putLong("rowid" + sKey, item.GetID());
160  9 data.putString("text" + sKey, item.GetText(utils, prefs.b24HourMode));
161   
162  9 iKeyIndex++;
163    }
164    }
165  14 data.putInt("typetotal_" + Integer.toString(iOrderFilter), iKeyIndex);
166    }
167   
 
168  7 toggle public PendingIntent getAlarmDialogIntent()
169    {
170  7 Intent intentAlarmDialog = new Intent("android.intent.action.AnCal.ACTION_MODE_VIEW_ALARMDIALOG");
171  7 Bundle data = new Bundle();
172  7 PutDataItemsToBundle(data, AlarmDataViewItem.iOrderAppts);
173  7 PutDataItemsToBundle(data, AlarmDataViewItem.iOrderTasks);
174  7 intentAlarmDialog.putExtras(data);
175    //return PendingIntent.getActivity(this.context, 0, intentAlarmDialog, PendingIntent.FLAG_CANCEL_CURRENT);
176  7 return PendingIntent.getActivity(this.context, 0, intentAlarmDialog, 0);
177    }
178   
 
179  30 toggle public void ShowNotification()
180    {
181  30 if (IsAlarm())
182    {
183  11 int iCountAppts = GetItemsCount(AlarmDataViewItem.iOrderAppts);
184  11 int iCountTasks = GetItemsCount(AlarmDataViewItem.iOrderTasks);
185   
186    //is there something to show ?
187  11 if ((iCountAppts > 0) || (iCountTasks > 0))
188    {
189    //check if alarms changed from last time
190  11 if (AlarmsChanged())
191    {
192    //remove last notify from status bar
193  7 RemoveNotify();
194   
195    //make notify text
196  7 final String sTitle = sAppName + ": " + strReminder;
197  7 String sMessage = GetPopupMsg(iCountAppts, iCountTasks);
198   
199    //make notify status
200  7 String sStatus = GetStatusMsg(iCountAppts, iCountTasks);
201   
202    //show popup message
203  7 ViewToastMsg viewToastMsg = new ViewToastMsg(this.context, sTitle, sMessage);
204  7 Toast toast = new Toast(this.context);
205  7 toast.setDuration(Toast.LENGTH_LONG);
206  7 toast.setView(viewToastMsg);
207  7 toast.show();
208   
209    //show status bar notification item
210  7 Notification notifyItem = new Notification(R.drawable.stat_notify_alarm, sStatus, System.currentTimeMillis());
211   
212    /*
213    final Uri uriAlarmSound = alarmSound.getUri();
214    if (uriAlarmSound == null)
215    {
216    notifyItem.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;
217    } else {
218    notifyItem.defaults = Notification.DEFAULT_LIGHTS;
219    notifyItem.sound = uriAlarmSound;
220    notifyItem.audioStreamType = AudioManager.STREAM_ALARM;
221    }
222    */
223   
224  7 notifyItem.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;
225  7 notifyItem.setLatestEventInfo(this.context, strReminder, sStatus, getAlarmDialogIntent());
226   
227    //run
228  7 mNM.notify(iNotifyID1, notifyItem);
229    }
230    }
231    } else {
232  19 RemoveNotify();
233  19 iLastAlarmsHash = 0;
234    }
235    }
236   
237    }
238