From 22924b6afee333e16fb62a19f1ac044c87c528b5 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Wed, 16 Dec 2009 13:52:31 -0500 Subject: [PATCH] Check for null alarms and dismiss the snooze if the alarm is disabled. If the alarm that is currently active is deleted, disable snoozing the alarm. Bug: 2322130 --- src/com/android/deskclock/AlarmAlertFullScreen.java | 15 +++++++++++++++ src/com/android/deskclock/Alarms.java | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/src/com/android/deskclock/AlarmAlertFullScreen.java b/src/com/android/deskclock/AlarmAlertFullScreen.java index 3442da3..0173a12 100644 --- a/src/com/android/deskclock/AlarmAlertFullScreen.java +++ b/src/com/android/deskclock/AlarmAlertFullScreen.java @@ -132,6 +132,11 @@ public class AlarmAlertFullScreen extends Activity { // Attempt to snooze this alert. private void snooze() { + // Do not snooze if the snooze button is disabled. + if (!findViewById(R.id.snooze).isEnabled()) { + dismiss(false); + return; + } final String snooze = PreferenceManager.getDefaultSharedPreferences(this) .getString(SettingsActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE); @@ -211,6 +216,16 @@ public class AlarmAlertFullScreen extends Activity { } @Override + protected void onResume() { + super.onResume(); + // If the alarm was deleted at some point, disable snooze. + if (Alarms.getAlarm(getContentResolver(), mAlarm.id) == null) { + Button snooze = (Button) findViewById(R.id.snooze); + snooze.setEnabled(false); + } + } + + @Override protected void onStop() { super.onStop(); if (!isFinishing()) { diff --git a/src/com/android/deskclock/Alarms.java b/src/com/android/deskclock/Alarms.java index ebb337b..f46b058 100644 --- a/src/com/android/deskclock/Alarms.java +++ b/src/com/android/deskclock/Alarms.java @@ -229,6 +229,9 @@ public class Alarms { private static void enableAlarmInternal(final Context context, final Alarm alarm, boolean enabled) { + if (alarm == null) { + return; + } ContentResolver resolver = context.getContentResolver(); ContentValues values = new ContentValues(2); @@ -243,6 +246,9 @@ public class Alarms { alarm.daysOfWeek).getTimeInMillis(); } values.put(Alarm.Columns.ALARM_TIME, time); + } else { + // Clear the snooze if the id matches. + disableSnoozeAlert(context, alarm.id); } resolver.update(ContentUris.withAppendedId( @@ -447,6 +453,9 @@ public class Alarms { // Get the alarm from the db. final Alarm alarm = getAlarm(context.getContentResolver(), id); + if (alarm == null) { + return false; + } // The time in the database is either 0 (repeating) or a specific time // for a non-repeating alarm. Update this value so the AlarmReceiver // has the right time to compare. -- 2.11.0