Home | History | Annotate | Download | only in deskclock

Lines Matching refs:alarm

40  * The Alarms provider supplies info about Alarm Clock settings
47 // is a public action used in the manifest for receiving Alarm broadcasts
48 // from the alarm manager.
51 // A public action sent by AlarmKlaxon when the alarm has stopped sounding
57 // can snooze the alarm (after ALARM_ALERT_ACTION and before ALARM_DONE_ACTION).
61 // can dismiss the alarm (after ALARM_ALERT_ACTION and before ALARM_DONE_ACTION).
64 // A public action sent by AlarmAlertFullScreen when a snoozed alarm was dismissed due
68 // A broadcast sent every time the next alarm time is set in the system
72 // show the alarm has been killed.
76 // alarm played before being killed.
79 // This string is used to indicate a silent alarm in the db.
86 // This string is used when passing an Alarm object through an intent.
87 public static final String ALARM_INTENT_EXTRA = "intent.extra.alarm";
89 // This extra is the raw Alarm object data. It is used in the
107 * Creates a new Alarm and fills in the given alarm's id.
109 public static long addAlarm(Context context, Alarm alarm) {
110 ContentValues values = createContentValues(alarm);
112 Alarm.Columns.CONTENT_URI, values);
113 alarm.id = (int) ContentUris.parseId(uri);
115 long timeInMillis = calculateAlarm(alarm);
116 if (alarm.enabled) {
124 * Removes an existing Alarm. If this alarm is snoozing, disables
131 /* If alarm is snoozing, lose it */
134 Uri uri = ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId);
142 return new CursorLoader(context, Alarm.Columns.CONTENT_URI,
143 Alarm.Columns.ALARM_QUERY_COLUMNS, null, null, Alarm.Columns.DEFAULT_SORT_ORDER);
152 Alarm.Columns.CONTENT_URI, Alarm.Columns.ALARM_QUERY_COLUMNS,
153 null, null, Alarm.Columns.DEFAULT_SORT_ORDER);
159 return contentResolver.query(Alarm.Columns.CONTENT_URI,
160 Alarm.Columns.ALARM_QUERY_COLUMNS, Alarm.Columns.WHERE_ENABLED,
164 private static ContentValues createContentValues(Alarm alarm) {
166 // Set the alarm_time value if this alarm does not repeat. This will be
169 if (!alarm.daysOfWeek.isRepeatSet()) {
170 time = calculateAlarm(alarm);
174 if (alarm.id != -1) {
175 values.put(Alarm.Columns._ID, alarm.id);
178 values.put(Alarm.Columns.ENABLED, alarm.enabled ? 1 : 0);
179 values.put(Alarm.Columns.HOUR, alarm.hour);
180 values.put(Alarm.Columns.MINUTES, alarm.minutes);
181 values.put(Alarm.Columns.ALARM_TIME, time);
182 values.put(Alarm.Columns.DAYS_OF_WEEK, alarm.daysOfWeek.getCoded());
183 values.put(Alarm.Columns.VIBRATE, alarm.vibrate);
184 values.put(Alarm.Columns.MESSAGE, alarm.label);
186 // A null alert Uri indicates a silent alarm.
187 values.put(Alarm.Columns.ALERT, alarm.alert == null ? ALARM_ALERT_SILENT
188 : alarm.alert.toString());
194 // If this alarm fires before the next snooze, clear the snooze to
195 // enable this alarm.
210 * Return an Alarm object representing the alarm id in the database.
211 * Returns null if no alarm exists.
213 public static Alarm getAlarm(ContentResolver contentResolver, int alarmId) {
215 ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId),
216 Alarm.Columns.ALARM_QUERY_COLUMNS,
218 Alarm alarm = null;
221 alarm = new Alarm(cursor);
225 return alarm;
230 * A convenience method to set an alarm in the Alarms
232 * @return Time when the alarm will fire. Or < 1 if update failed.
234 public static long setAlarm(Context context, Alarm alarm) {
235 ContentValues values = createContentValues(alarm);
238 ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarm.id),
241 Log.e("Error updating alarm " + alarm);
245 long timeInMillis = calculateAlarm(alarm);
247 if (alarm.enabled) {
248 // Disable the snooze if we just changed the snoozed alarm. This
249 // only does work if the snoozed alarm is the same as the given
250 // alarm.
252 disableSnoozeAlert(context, alarm.id);
254 // Disable the snooze if this alarm fires before the snoozed alarm.
255 // This works on every alarm since the user most likely intends to
256 // have the modified alarm fire next.
266 * A convenience method to enable or disable an alarm.
285 final Alarm alarm, boolean enabled) {
286 if (alarm == null) {
292 values.put(Alarm.Columns.ENABLED, enabled ? 1 : 0);
294 // If we are enabling the alarm, calculate alarm time since the time
295 // value in Alarm may be old.
298 if (!alarm.daysOfWeek.isRepeatSet()) {
299 time = calculateAlarm(alarm);
301 values.put(Alarm.Columns.ALARM_TIME, time);
304 disableSnoozeAlert(context, alarm.id);
308 Alarm.Columns.CONTENT_URI, alarm.id), values, null, null);
311 private static Alarm calculateNextAlert(final Context context) {
316 Set<Alarm> alarms = new HashSet<Alarm>();
319 // list. For a non-repeating alarm, when it goes of, it becomes disabled. A snoozed
320 // non-repeating alarm is not in the active list in the database.
326 final Alarm a = getAlarm(context.getContentResolver(), alarmId);
336 final Alarm a = new Alarm(cursor);
345 Alarm alarm = null;
347 for (Alarm a : alarms) {
348 // A time of 0 indicates this is a repeating alarm, so
354 // Update the alarm if it has been snoozed
358 Log.v("Disabling expired alarm set for " + Log.formatTime(a.time));
359 // Expired alarm, disable it and move along.
365 alarm = a;
369 return alarm;
383 Alarm alarm = new Alarm(cur);
384 // A time of 0 means this alarm repeats. If the time is
386 if (alarm.time != 0 && alarm.time < now) {
387 Log.v("Disabling expired alarm set for " +
388 Log.formatTime(alarm.time));
389 enableAlarmInternal(context, alarm, false);
400 * the user changes alarm settings. Activates snooze if set,
404 final Alarm alarm = calculateNextAlert(context);
405 if (alarm != null) {
406 enableAlert(context, alarm, alarm.time);
416 * actually launch the alert when the alarm triggers.
418 * @param alarm Alarm.
421 private static void enableAlert(Context context, final Alarm alarm,
427 Log.v("** setAlert id " + alarm.id + " atTime " + atTimeInMillis);
435 // does not know about the Alarm class, it throws a
439 // byte[] array. The AlarmReceiver class knows to build the Alarm
442 alarm.writeToParcel(out, 0);
557 * Updates the specified Alarm with the additional snooze time.
558 * Returns a boolean indicating whether the alarm was updated.
561 final SharedPreferences prefs, final Alarm alarm) {
562 if (!hasAlarmBeenSnoozed(prefs, alarm.id)) {
563 // No need to modify the alarm
567 final long time = prefs.getLong(getAlarmPrefSnoozeTimeKey(alarm.id), -1);
569 // for a non-repeating alarm. Update this value so the AlarmReceiver
571 alarm.time = time;
577 * Tells the StatusBar whether the alarm is enabled or disabled
585 private static long calculateAlarm(Alarm alarm) {
586 return calculateAlarm(alarm.hour, alarm.minutes, alarm.daysOfWeek)
591 * Given an alarm in hours and minutes, return a time suitable for
595 Alarm.DaysOfWeek daysOfWeek) {
604 // if alarm is behind current time, advance one day
620 Alarm.DaysOfWeek daysOfWeek) {
640 * Save time of the next alarm, as a formatted string, into the system