@@ -27,12 +27,20 @@ public class AlarmBroadcastReceiver extends WakefulBroadcastReceiver
27
27
{
28
28
private static final String TAG = "AlarmBroadcastReceiver" ;
29
29
30
+ /** The most important object in this class. */
30
31
private AlarmManager alarmManager ;
32
+
33
+ /** Attach an intent to the manager with specific ID. */
31
34
private PendingIntent enableAirplaneModePendingIntent ;
35
+
36
+ /** Attach another intent to the manager with specific ID. */
32
37
private PendingIntent disableAirplaneModePendingIntent ;
33
38
34
- private final SimpleDateFormat sdf1 = new SimpleDateFormat ("dd/MM" , Locale .getDefault ());
35
- private final SimpleDateFormat sdf2 = new SimpleDateFormat ("HH:mm" , Locale .getDefault ());
39
+ /** Display days/month. */
40
+ private static final SimpleDateFormat SDF_1 = new SimpleDateFormat ("dd/MM" , Locale .getDefault ());
41
+
42
+ /** Display hours/minutes. */
43
+ private static final SimpleDateFormat SDF_2 = new SimpleDateFormat ("HH:mm" , Locale .getDefault ());
36
44
37
45
@ Override
38
46
public void onReceive (Context context , Intent intent )
@@ -54,6 +62,7 @@ public void onReceive(Context context, Intent intent)
54
62
}
55
63
56
64
/**
65
+ * Set both start / stop alarms.
57
66
*
58
67
* @param context the context
59
68
* @return true if alarm was set
@@ -82,6 +91,8 @@ public String setAlarms(Context context)
82
91
83
92
calendarEnd .set (Calendar .HOUR_OF_DAY , Integer .valueOf (disable [0 ]));
84
93
calendarEnd .set (Calendar .MINUTE , Integer .valueOf (disable [1 ]));
94
+ calendarEnd .set (Calendar .SECOND , 0 );
95
+ calendarEnd .set (Calendar .MILLISECOND , 0 );
85
96
86
97
// If settings are like this [23:00 -> 08:00], convert to [23:00 -> (day +1) 08:00]
87
98
if (calendarStart .after (calendarEnd )) {
@@ -113,8 +124,8 @@ public String setAlarms(Context context)
113
124
message = context .getString (R .string .toast_next_airplane_mode_tomorrow );
114
125
} else {
115
126
message = String .format (context .getString (R .string .toast_next_airplane_mode_later ),
116
- sdf1 .format (calendarStart .getTime ()),
117
- sdf2 .format (calendarStart .getTime ()));
127
+ SDF_1 .format (calendarStart .getTime ()),
128
+ SDF_2 .format (calendarStart .getTime ()));
118
129
}
119
130
return message ;
120
131
}
@@ -177,6 +188,7 @@ private boolean getNextScheduledDay(Context context, Calendar now, Calendar star
177
188
}
178
189
179
190
/**
191
+ * Removes any registered alarms.
180
192
*
181
193
* @param context the context
182
194
*/
0 commit comments