Loading src/com/android/deskclock/alarms/AlarmNotifications.java +22 −0 Original line number Diff line number Diff line Loading @@ -240,6 +240,28 @@ public final class AlarmNotifications { nm.cancel(instance.hashCode()); } /** * Updates the notification for an existing alarm. Use if the label has changed. */ public static void updateNotification(Context context, AlarmInstance instance) { switch (instance.mAlarmState) { case AlarmInstance.LOW_NOTIFICATION_STATE: showLowPriorityNotification(context, instance); break; case AlarmInstance.HIGH_NOTIFICATION_STATE: showHighPriorityNotification(context, instance); break; case AlarmInstance.SNOOZE_STATE: showSnoozeNotification(context, instance); break; case AlarmInstance.MISSED_STATE: showMissedNotification(context, instance); break; default: LogUtils.d("No notification to update"); } } public static Intent createViewAlarmIntent(Context context, AlarmInstance instance) { long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId); Loading src/com/android/deskclock/alarms/AlarmUpdateHandler.java +25 −10 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.deskclock.provider.AlarmInstance; import com.android.deskclock.widget.ActionableToastBar; import java.util.Calendar; import java.util.List; /** * API for asynchronously mutating a single alarm. Loading Loading @@ -117,21 +118,35 @@ public final class AlarmUpdateHandler implements View.OnTouchListener { Events.sendAlarmEvent(R.string.action_update, R.string.label_deskclock); ContentResolver cr = mAppContext.getContentResolver(); if (minorUpdate) { // For minor updates, don't affect any currently snoozed instances. AlarmStateManager.deleteNonSnoozeInstances(mAppContext, alarm.id); } else { AlarmStateManager.deleteAllInstances(mAppContext, alarm.id); } // Update alarm Alarm.updateAlarm(cr, alarm); if (alarm.enabled) { return setupAlarmInstance(alarm); } if (minorUpdate) { // just update the instance in the database and update notifications. final List<AlarmInstance> instanceList = AlarmInstance.getInstancesByAlarmId(cr, alarm.id); for (AlarmInstance instance : instanceList) { // Make a copy of the existing instance final AlarmInstance newInstance = new AlarmInstance(instance); // Copy over minor change data to the instance; we don't know // exactly which minor field changed, so just copy them all. newInstance.mVibrate = alarm.vibrate; newInstance.mRingtone = alarm.alert; newInstance.mLabel = alarm.label; // Since we copied the mId of the old instance and the mId is used // as the primary key in the AlarmInstance table, this will replace // the existing instance. AlarmInstance.updateInstance(cr, newInstance); // Update the notification for this instance. AlarmNotifications.updateNotification(mAppContext, newInstance); } return null; } // Otherwise, this is a major update and we're going to re-create the alarm AlarmStateManager.deleteAllInstances(mAppContext, alarm.id); return alarm.enabled ? setupAlarmInstance(alarm) : null; } @Override protected void onPostExecute(AlarmInstance instance) { Loading src/com/android/deskclock/provider/AlarmInstance.java +14 −0 Original line number Diff line number Diff line Loading @@ -304,6 +304,20 @@ public final class AlarmInstance implements ClockContract.InstancesColumns { mAlarmState = SILENT_STATE; } public AlarmInstance(AlarmInstance instance) { this.mId = instance.mId; this.mYear = instance.mYear; this.mMonth = instance.mMonth; this.mDay = instance.mDay; this.mHour = instance.mHour; this.mMinute = instance.mMinute; this.mLabel = instance.mLabel; this.mVibrate = instance.mVibrate; this.mRingtone = instance.mRingtone; this.mAlarmId = instance.mAlarmId; this.mAlarmState = instance.mAlarmState; } public AlarmInstance(Cursor c, boolean joinedTable) { if (joinedTable) { mId = c.getLong(Alarm.INSTANCE_ID_INDEX); Loading Loading
src/com/android/deskclock/alarms/AlarmNotifications.java +22 −0 Original line number Diff line number Diff line Loading @@ -240,6 +240,28 @@ public final class AlarmNotifications { nm.cancel(instance.hashCode()); } /** * Updates the notification for an existing alarm. Use if the label has changed. */ public static void updateNotification(Context context, AlarmInstance instance) { switch (instance.mAlarmState) { case AlarmInstance.LOW_NOTIFICATION_STATE: showLowPriorityNotification(context, instance); break; case AlarmInstance.HIGH_NOTIFICATION_STATE: showHighPriorityNotification(context, instance); break; case AlarmInstance.SNOOZE_STATE: showSnoozeNotification(context, instance); break; case AlarmInstance.MISSED_STATE: showMissedNotification(context, instance); break; default: LogUtils.d("No notification to update"); } } public static Intent createViewAlarmIntent(Context context, AlarmInstance instance) { long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId); Loading
src/com/android/deskclock/alarms/AlarmUpdateHandler.java +25 −10 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.deskclock.provider.AlarmInstance; import com.android.deskclock.widget.ActionableToastBar; import java.util.Calendar; import java.util.List; /** * API for asynchronously mutating a single alarm. Loading Loading @@ -117,21 +118,35 @@ public final class AlarmUpdateHandler implements View.OnTouchListener { Events.sendAlarmEvent(R.string.action_update, R.string.label_deskclock); ContentResolver cr = mAppContext.getContentResolver(); if (minorUpdate) { // For minor updates, don't affect any currently snoozed instances. AlarmStateManager.deleteNonSnoozeInstances(mAppContext, alarm.id); } else { AlarmStateManager.deleteAllInstances(mAppContext, alarm.id); } // Update alarm Alarm.updateAlarm(cr, alarm); if (alarm.enabled) { return setupAlarmInstance(alarm); } if (minorUpdate) { // just update the instance in the database and update notifications. final List<AlarmInstance> instanceList = AlarmInstance.getInstancesByAlarmId(cr, alarm.id); for (AlarmInstance instance : instanceList) { // Make a copy of the existing instance final AlarmInstance newInstance = new AlarmInstance(instance); // Copy over minor change data to the instance; we don't know // exactly which minor field changed, so just copy them all. newInstance.mVibrate = alarm.vibrate; newInstance.mRingtone = alarm.alert; newInstance.mLabel = alarm.label; // Since we copied the mId of the old instance and the mId is used // as the primary key in the AlarmInstance table, this will replace // the existing instance. AlarmInstance.updateInstance(cr, newInstance); // Update the notification for this instance. AlarmNotifications.updateNotification(mAppContext, newInstance); } return null; } // Otherwise, this is a major update and we're going to re-create the alarm AlarmStateManager.deleteAllInstances(mAppContext, alarm.id); return alarm.enabled ? setupAlarmInstance(alarm) : null; } @Override protected void onPostExecute(AlarmInstance instance) { Loading
src/com/android/deskclock/provider/AlarmInstance.java +14 −0 Original line number Diff line number Diff line Loading @@ -304,6 +304,20 @@ public final class AlarmInstance implements ClockContract.InstancesColumns { mAlarmState = SILENT_STATE; } public AlarmInstance(AlarmInstance instance) { this.mId = instance.mId; this.mYear = instance.mYear; this.mMonth = instance.mMonth; this.mDay = instance.mDay; this.mHour = instance.mHour; this.mMinute = instance.mMinute; this.mLabel = instance.mLabel; this.mVibrate = instance.mVibrate; this.mRingtone = instance.mRingtone; this.mAlarmId = instance.mAlarmId; this.mAlarmState = instance.mAlarmState; } public AlarmInstance(Cursor c, boolean joinedTable) { if (joinedTable) { mId = c.getLong(Alarm.INSTANCE_ID_INDEX); Loading