OSDN Git Service

Fix the clock face preference.
authorPatrick Scott <phanna@android.com>
Tue, 11 Aug 2009 17:39:40 +0000 (13:39 -0400)
committerPatrick Scott <phanna@android.com>
Tue, 11 Aug 2009 18:39:38 +0000 (14:39 -0400)
I was clearing all the preferences when removing the snooze and that was
clearing the clock face and visibility preference as well. Instead, remove the
snooze preferences. Also, use the constant PREF_CLOCK_FACE instead of the
literal string.

src/com/android/alarmclock/Alarms.java
src/com/android/alarmclock/ClockPicker.java

index 3b7adf4..d4973fa 100644 (file)
@@ -367,12 +367,12 @@ public class Alarms {
                 AlarmClock.PREFERENCES, 0);
         SharedPreferences.Editor ed = prefs.edit();
         if (id == -1) {
-            ed.clear();
+            clearSnoozePreference(ed);
         } else {
             ed.putInt(PREF_SNOOZE_ID, id);
             ed.putLong(PREF_SNOOZE_TIME, time);
+            ed.commit();
         }
-        ed.commit();
         // Set the next alert after updating the snooze.
         setNextAlert(context);
     }
@@ -389,12 +389,18 @@ public class Alarms {
             return;
         } else if (snoozeId == id) {
             // This is the same id so clear the shared prefs.
-            SharedPreferences.Editor ed = prefs.edit();
-            ed.clear();
-            ed.commit();
+            clearSnoozePreference(prefs.edit());
         }
     }
 
+    // Helper to remove the snooze preference. Do not use clear because that
+    // will erase the clock preferences.
+    private static void clearSnoozePreference(final SharedPreferences.Editor ed) {
+        ed.remove(PREF_SNOOZE_ID);
+        ed.remove(PREF_SNOOZE_TIME);
+        ed.commit();
+    };
+
     /**
      * If there is a snooze set, enable it in AlarmManager
      * @return true if snooze is set
index 039f5b8..31150a2 100644 (file)
@@ -83,7 +83,7 @@ public class ClockPicker extends Activity implements
 
     private synchronized void selectClock(int position) {
         SharedPreferences.Editor ed = mPrefs.edit();
-        ed.putInt("face", position);
+        ed.putInt(AlarmClock.PREF_CLOCK_FACE, position);
         ed.commit();
 
         setResult(RESULT_OK);