Loading src/com/android/deskclock/AlarmInitReceiver.java +13 −3 Original line number Diff line number Diff line Loading @@ -16,10 +16,14 @@ package com.android.deskclock; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.BroadcastReceiver; import android.content.SharedPreferences; import android.os.PowerManager.WakeLock; import android.preference.PreferenceManager; import com.android.deskclock.timer.TimerObj; public class AlarmInitReceiver extends BroadcastReceiver { Loading @@ -41,8 +45,14 @@ public class AlarmInitReceiver extends BroadcastReceiver { if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { Alarms.saveSnoozeAlert(context, Alarms.INVALID_ALARM_ID, -1); Alarms.disableExpiredAlarms(context); } // Clear stopwatch and timers data SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Log.v("AlarmInitReceiver - Cleaning old timer and stopwatch data"); TimerObj.cleanTimersFromSharedPrefs(prefs); Utils.clearSwSharedPref(prefs); } Alarms.setNextAlert(context); result.finish(); Log.v("AlarmInitReceiver finished"); Loading src/com/android/deskclock/Utils.java +20 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.deskclock; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; Loading @@ -25,6 +26,8 @@ import android.os.SystemClock; import android.text.TextUtils; import android.view.MenuItem; import com.android.deskclock.stopwatch.Stopwatches; import java.util.Locale; Loading Loading @@ -129,4 +132,21 @@ public class Utils { public static int getGrayColorId() { return R.color.clock_gray; } /** * Clears the persistent data of stopwatch (start time, state, laps, etc...). */ public static void clearSwSharedPref(SharedPreferences prefs) { SharedPreferences.Editor editor = prefs.edit(); editor.remove (Stopwatches.PREF_START_TIME); editor.remove (Stopwatches.PREF_ACCUM_TIME); editor.remove (Stopwatches.PREF_STATE); int lapNum = prefs.getInt(Stopwatches.PREF_LAP_NUM, Stopwatches.STOPWATCH_RESET); for (int i = 0; i < lapNum; i++) { String key = Stopwatches.PREF_LAP_TIME + Integer.toString(i); editor.remove(key); } editor.remove(Stopwatches.PREF_LAP_NUM); editor.apply(); } } src/com/android/deskclock/stopwatch/StopwatchFragment.java +2 −16 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ public class StopwatchFragment extends DeskClockFragment implements OnSharedPref ArrayList<Lap> mLaps = new ArrayList<Lap>(); private final LayoutInflater mInflater; private int mBackgroundColor; private final int mBackgroundColor; public LapsListAdapter(Context context) { mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); Loading Loading @@ -361,7 +361,7 @@ public class StopwatchFragment extends DeskClockFragment implements OnSharedPref private void doReset() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); clearSharedPref(prefs); Utils.clearSwSharedPref(prefs); mTime.clearSharedPref(prefs, "sw"); mAccumulatedTime = 0; mLapsAdapter.clearLaps(); Loading Loading @@ -679,20 +679,6 @@ public class StopwatchFragment extends DeskClockFragment implements OnSharedPref } } private void clearSharedPref(SharedPreferences prefs) { SharedPreferences.Editor editor = prefs.edit(); editor.remove (Stopwatches.PREF_START_TIME); editor.remove (Stopwatches.PREF_ACCUM_TIME); editor.remove (Stopwatches.PREF_STATE); int lapNum = prefs.getInt(Stopwatches.PREF_LAP_NUM, Stopwatches.STOPWATCH_RESET); for (int i = 0; i < lapNum; i++) { String key = Stopwatches.PREF_LAP_TIME + Integer.toString(i); editor.remove(key); } editor.remove(Stopwatches.PREF_LAP_NUM); editor.apply(); } public class ImageLabelAdapter extends ArrayAdapter<CharSequence> { private final ArrayList<CharSequence> mStrings; private final ArrayList<Drawable> mDrawables; Loading src/com/android/deskclock/timer/TimerObj.java +9 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class TimerObj implements Parcelable { Loading Loading @@ -264,5 +265,13 @@ public class TimerObj implements Parcelable { } } public static void cleanTimersFromSharedPrefs(SharedPreferences prefs) { ArrayList<TimerObj> timers = new ArrayList<TimerObj>(); getTimersFromSharedPrefs(prefs, timers); Iterator<TimerObj> i = timers.iterator(); while(i.hasNext()) { i.next().deleteFromSharedPref(prefs); } } } Loading
src/com/android/deskclock/AlarmInitReceiver.java +13 −3 Original line number Diff line number Diff line Loading @@ -16,10 +16,14 @@ package com.android.deskclock; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.BroadcastReceiver; import android.content.SharedPreferences; import android.os.PowerManager.WakeLock; import android.preference.PreferenceManager; import com.android.deskclock.timer.TimerObj; public class AlarmInitReceiver extends BroadcastReceiver { Loading @@ -41,8 +45,14 @@ public class AlarmInitReceiver extends BroadcastReceiver { if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { Alarms.saveSnoozeAlert(context, Alarms.INVALID_ALARM_ID, -1); Alarms.disableExpiredAlarms(context); } // Clear stopwatch and timers data SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Log.v("AlarmInitReceiver - Cleaning old timer and stopwatch data"); TimerObj.cleanTimersFromSharedPrefs(prefs); Utils.clearSwSharedPref(prefs); } Alarms.setNextAlert(context); result.finish(); Log.v("AlarmInitReceiver finished"); Loading
src/com/android/deskclock/Utils.java +20 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.deskclock; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; Loading @@ -25,6 +26,8 @@ import android.os.SystemClock; import android.text.TextUtils; import android.view.MenuItem; import com.android.deskclock.stopwatch.Stopwatches; import java.util.Locale; Loading Loading @@ -129,4 +132,21 @@ public class Utils { public static int getGrayColorId() { return R.color.clock_gray; } /** * Clears the persistent data of stopwatch (start time, state, laps, etc...). */ public static void clearSwSharedPref(SharedPreferences prefs) { SharedPreferences.Editor editor = prefs.edit(); editor.remove (Stopwatches.PREF_START_TIME); editor.remove (Stopwatches.PREF_ACCUM_TIME); editor.remove (Stopwatches.PREF_STATE); int lapNum = prefs.getInt(Stopwatches.PREF_LAP_NUM, Stopwatches.STOPWATCH_RESET); for (int i = 0; i < lapNum; i++) { String key = Stopwatches.PREF_LAP_TIME + Integer.toString(i); editor.remove(key); } editor.remove(Stopwatches.PREF_LAP_NUM); editor.apply(); } }
src/com/android/deskclock/stopwatch/StopwatchFragment.java +2 −16 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ public class StopwatchFragment extends DeskClockFragment implements OnSharedPref ArrayList<Lap> mLaps = new ArrayList<Lap>(); private final LayoutInflater mInflater; private int mBackgroundColor; private final int mBackgroundColor; public LapsListAdapter(Context context) { mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); Loading Loading @@ -361,7 +361,7 @@ public class StopwatchFragment extends DeskClockFragment implements OnSharedPref private void doReset() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); clearSharedPref(prefs); Utils.clearSwSharedPref(prefs); mTime.clearSharedPref(prefs, "sw"); mAccumulatedTime = 0; mLapsAdapter.clearLaps(); Loading Loading @@ -679,20 +679,6 @@ public class StopwatchFragment extends DeskClockFragment implements OnSharedPref } } private void clearSharedPref(SharedPreferences prefs) { SharedPreferences.Editor editor = prefs.edit(); editor.remove (Stopwatches.PREF_START_TIME); editor.remove (Stopwatches.PREF_ACCUM_TIME); editor.remove (Stopwatches.PREF_STATE); int lapNum = prefs.getInt(Stopwatches.PREF_LAP_NUM, Stopwatches.STOPWATCH_RESET); for (int i = 0; i < lapNum; i++) { String key = Stopwatches.PREF_LAP_TIME + Integer.toString(i); editor.remove(key); } editor.remove(Stopwatches.PREF_LAP_NUM); editor.apply(); } public class ImageLabelAdapter extends ArrayAdapter<CharSequence> { private final ArrayList<CharSequence> mStrings; private final ArrayList<Drawable> mDrawables; Loading
src/com/android/deskclock/timer/TimerObj.java +9 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class TimerObj implements Parcelable { Loading Loading @@ -264,5 +265,13 @@ public class TimerObj implements Parcelable { } } public static void cleanTimersFromSharedPrefs(SharedPreferences prefs) { ArrayList<TimerObj> timers = new ArrayList<TimerObj>(); getTimersFromSharedPrefs(prefs, timers); Iterator<TimerObj> i = timers.iterator(); while(i.hasNext()) { i.next().deleteFromSharedPref(prefs); } } }