OSDN Git Service

Enable the alarm when preferences change and not when hitting done.
authorPatrick Scott <phanna@android.com>
Mon, 8 Mar 2010 15:27:52 +0000 (10:27 -0500)
committerPatrick Scott <phanna@android.com>
Mon, 8 Mar 2010 15:27:52 +0000 (10:27 -0500)
The original intent was to enable the alarm when hitting done after making edits
but this caused the alarm to always turn on even if the user turned the alarm
off and hit done.

Bug: 2441762
Change-Id: I9f37ec2477ddced26df1c1fb4444cd5e5121e7d5

src/com/android/deskclock/SetAlarm.java

index 2f948e7..ee36a38 100644 (file)
@@ -144,8 +144,6 @@ public class SetAlarm extends PreferenceActivity
         Button b = (Button) findViewById(R.id.alarm_save);
         b.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {
-                    // Enable the alarm when clicking "Done"
-                    mEnabledPref.setChecked(true);
                     saveAlarm();
                     finish();
                 }
@@ -187,11 +185,15 @@ public class SetAlarm extends PreferenceActivity
     // Used to post runnables asynchronously.
     private static final Handler sHandler = new Handler();
 
-    public boolean onPreferenceChange(Preference p, Object newValue) {
+    public boolean onPreferenceChange(final Preference p, Object newValue) {
         // Asynchronously save the alarm since this method is called _before_
         // the value of the preference has changed.
         sHandler.post(new Runnable() {
             public void run() {
+                // Editing any preference (except enable) enables the alarm.
+                if (p != mEnabledPref) {
+                    mEnabledPref.setChecked(true);
+                }
                 saveAlarmAndEnableRevert();
             }
         });