From 571df2f2c262492b4ecd3534368a73946e29517c Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 15 Apr 2014 13:26:29 +0200 Subject: [PATCH] - Deal with time and timezone changes --- HypoAlarm/src/main/AndroidManifest.xml | 4 +++- .../{BootReceiver.java => AlarmChangeReceiver.java} | 8 +++++--- .../java/za/org/treehouse/hypoalarm/MainActivity.java | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) rename HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/{BootReceiver.java => AlarmChangeReceiver.java} (67%) diff --git a/HypoAlarm/src/main/AndroidManifest.xml b/HypoAlarm/src/main/AndroidManifest.xml index 2621bb4..ac511e5 100644 --- a/HypoAlarm/src/main/AndroidManifest.xml +++ b/HypoAlarm/src/main/AndroidManifest.xml @@ -46,10 +46,12 @@ + + diff --git a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/BootReceiver.java b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmChangeReceiver.java similarity index 67% rename from HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/BootReceiver.java rename to HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmChangeReceiver.java index eeddc1b..7a9589a 100644 --- a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/BootReceiver.java +++ b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmChangeReceiver.java @@ -9,14 +9,16 @@ import android.util.Log; import java.util.Calendar; -public class BootReceiver extends BroadcastReceiver { +public class AlarmChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); - if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { + if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED") || + intent.getAction().equals("android.intent.action.TIMEZONE_CHANGED") || + intent.getAction().equals("android.intent.action.TIME_SET")) { String alarmTimeStr = sharedPref.getString(context.getString(R.string.AlarmTimePref), null); Calendar cal = MainActivity.TimeStringToCalendar(alarmTimeStr); - Log.d("BootReceiver", "Booting: Setting alarm for " + MainActivity.debugDate(cal)); + Log.d("AlarmChangeReceiver", intent.getAction() + ": resetting alarm for " + MainActivity.debugDate(cal)); MainActivity.resetAlarm(context, cal); } } diff --git a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java index 8afce2e..808f6c6 100644 --- a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java +++ b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java @@ -342,13 +342,13 @@ public class MainActivity extends ActionBarActivity { } Log.d("MainActivity", "Setting pre-alarm for " + MainActivity.debugDate(preNotifyCal)); - // Set boot receiver, so alarm restarts on boot - ComponentName bootReceiver = new ComponentName(context, BootReceiver.class); + // Set time change and boot receiver, so alarm restarts on boot + ComponentName bootReceiver = new ComponentName(context, AlarmChangeReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(bootReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); - Log.d("MainActivity", "Setting BootReceiver"); + Log.d("MainActivity", "Setting boot receiver"); } }