- Deal with time and timezone changes
This commit is contained in:
parent
54bd082e89
commit
571df2f2c2
@ -46,10 +46,12 @@
|
|||||||
<receiver android:name="za.org.treehouse.hypoalarm.GraceReceiver" />
|
<receiver android:name="za.org.treehouse.hypoalarm.GraceReceiver" />
|
||||||
<receiver android:name="za.org.treehouse.hypoalarm.CancelGraceReceiver" />
|
<receiver android:name="za.org.treehouse.hypoalarm.CancelGraceReceiver" />
|
||||||
<receiver
|
<receiver
|
||||||
android:name="za.org.treehouse.hypoalarm.BootReceiver"
|
android:name="za.org.treehouse.hypoalarm.AlarmChangeReceiver"
|
||||||
android:enabled="false" >
|
android:enabled="false" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
|
||||||
|
<action android:name="android.intent.action.TIME_SET" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
@ -9,14 +9,16 @@ import android.util.Log;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
public class BootReceiver extends BroadcastReceiver {
|
public class AlarmChangeReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
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);
|
String alarmTimeStr = sharedPref.getString(context.getString(R.string.AlarmTimePref), null);
|
||||||
Calendar cal = MainActivity.TimeStringToCalendar(alarmTimeStr);
|
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);
|
MainActivity.resetAlarm(context, cal);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -342,13 +342,13 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
}
|
}
|
||||||
Log.d("MainActivity", "Setting pre-alarm for " + MainActivity.debugDate(preNotifyCal));
|
Log.d("MainActivity", "Setting pre-alarm for " + MainActivity.debugDate(preNotifyCal));
|
||||||
|
|
||||||
// Set boot receiver, so alarm restarts on boot
|
// Set time change and boot receiver, so alarm restarts on boot
|
||||||
ComponentName bootReceiver = new ComponentName(context, BootReceiver.class);
|
ComponentName bootReceiver = new ComponentName(context, AlarmChangeReceiver.class);
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
pm.setComponentEnabledSetting(bootReceiver,
|
pm.setComponentEnabledSetting(bootReceiver,
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||||
PackageManager.DONT_KILL_APP);
|
PackageManager.DONT_KILL_APP);
|
||||||
Log.d("MainActivity", "Setting BootReceiver");
|
Log.d("MainActivity", "Setting boot receiver");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user