From 69b223ae3de87f19b1f4762bd5980a82766c5dc4 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Fri, 26 Feb 2010 08:18:46 -0500 Subject: [PATCH] Do not add a new alarm if the user cancels the time picker. TimePickerDialog calls onTimeSet only if the user hits the "Set" button. In the case of a new alarm, keep track of the call to onTimeSet and check it when the user presses back. Bug: 2338234 --- src/com/android/deskclock/SetAlarm.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/com/android/deskclock/SetAlarm.java b/src/com/android/deskclock/SetAlarm.java index 4939974..1bafe39 100644 --- a/src/com/android/deskclock/SetAlarm.java +++ b/src/com/android/deskclock/SetAlarm.java @@ -58,6 +58,7 @@ public class SetAlarm extends PreferenceActivity private int mHour; private int mMinutes; private boolean mCreateNewAlarm; + private boolean mTimePickerCancelled; /** * Set an alarm. Requires an Alarms.ALARM_ID to be passed in as an @@ -153,6 +154,8 @@ public class SetAlarm extends PreferenceActivity // The last thing we do is pop the time picker if this is a new alarm. if (mCreateNewAlarm) { + // Assume the user hit cancel + mTimePickerCancelled = true; showTimePicker(); } } @@ -169,7 +172,12 @@ public class SetAlarm extends PreferenceActivity @Override public void onBackPressed() { - saveAlarm(); + // In the usual case of viewing an alarm, mTimePickerCancelled is + // initialized to false. When creating a new alarm, this value is + // assumed true until the user changes the time. + if (!mTimePickerCancelled) { + saveAlarm(); + } finish(); } @@ -179,6 +187,8 @@ public class SetAlarm extends PreferenceActivity } public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + // onTimeSet is called when the user clicks "Set" + mTimePickerCancelled = false; mHour = hourOfDay; mMinutes = minute; updateTime(); -- 2.11.0