use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.
the class AlarmStateManager method deleteAllInstances.
/**
* This will delete and unregister all instances associated with alarmId, without affect
* the alarm itself. This should be used whenever modifying or deleting an alarm.
*
* @param context application context
* @param alarmId to find instances to delete.
*/
public static void deleteAllInstances(Context context, long alarmId) {
sSnoozeCount = 0;
ContentResolver cr = context.getContentResolver();
List<AlarmInstance> instances = AlarmInstance.getInstancesByAlarmId(cr, alarmId);
for (AlarmInstance instance : instances) {
unregisterInstance(context, instance);
AlarmInstance.deleteInstance(context.getContentResolver(), instance.mId);
}
updateNextAlarm(context);
}
use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.
the class AlarmStateManager method updateParentAlarm.
/**
* Used by dismissed and missed states, to update parent alarm. This will either
* disable, delete or reschedule parent alarm.
*
* @param context application context
* @param instance to update parent for
*/
private static void updateParentAlarm(Context context, AlarmInstance instance) {
ContentResolver cr = context.getContentResolver();
Alarm alarm = Alarm.getAlarm(cr, instance.mAlarmId);
if (alarm == null) {
LogUtils.e("Parent has been deleted with instance: " + instance.toString());
return;
}
if (!alarm.daysOfWeek.isRepeating()) {
if (alarm.deleteAfterUse) {
LogUtils.i("Deleting parent alarm: " + alarm.id);
Alarm.deleteAlarm(cr, alarm.id);
} else {
LogUtils.i("Disabling parent alarm: " + alarm.id);
alarm.enabled = false;
Alarm.updateAlarm(cr, alarm);
}
} else {
// This is a optimization for really old alarm instances. This prevent us
// from scheduling and dismissing alarms up to current time.
Calendar currentTime = Calendar.getInstance();
Calendar alarmTime = instance.getAlarmTime();
if (currentTime.after(alarmTime)) {
alarmTime = currentTime;
}
AlarmInstance nextRepeatedInstance = alarm.createInstanceAfter(alarmTime);
LogUtils.i("Creating new instance for repeating alarm " + alarm.id + " at " + sdf.format(nextRepeatedInstance.getAlarmTime().getTime()));
AlarmInstance.addInstance(cr, nextRepeatedInstance);
registerInstance(context, nextRepeatedInstance, true);
}
}
use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.
the class AlarmStateManager method updateNextAlarm.
/**
* Find and notify system what the next alarm that will fire. This is used
* to update text in the system and widgets.
*
* @param context application context
*/
public static void updateNextAlarm(Context context) {
AlarmInstance nextAlarm = null;
ContentResolver cr = context.getContentResolver();
String activeAlarmQuery = AlarmInstance.ALARM_STATE + "<" + AlarmInstance.PRE_ALARM_STATE;
for (AlarmInstance instance : AlarmInstance.getInstances(cr, activeAlarmQuery)) {
if (nextAlarm == null || instance.getAlarmTime().before(nextAlarm.getAlarmTime())) {
nextAlarm = instance;
}
}
AlarmNotifications.registerNextAlarmWithAlarmManager(context, nextAlarm);
}
use of org.omnirom.deskclock.provider.AlarmInstance in project android_packages_apps_OmniClock by omnirom.
the class AlarmStateManager method fixAlarmInstances.
/**
* Fix and update all alarm instance when a time change event occurs.
*
* @param context application context
*/
public static void fixAlarmInstances(Context context) {
// Register all instances after major time changes or when phone restarts
// TODO: Refactor this code to not use the overloaded registerInstance method.
ContentResolver contentResolver = context.getContentResolver();
for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
AlarmStateManager.registerInstance(context, instance, false);
}
AlarmStateManager.updateNextAlarm(context);
}
Aggregations