Files
HypoAlarm/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmChangeReceiver.java
tim 093de96c68 - Remove the TIME_SET receiver, as this could reset the alarm whenever the network decides to reset the phone time.
- Recalculate the grace period notification progress, based on current time rather than once per update. This was causing the notification to persist when the phone went to sleep, past the time that the grace period had actually expired.
- Upgrade to latest libraries.
2014-07-09 18:23:31 +02:00

27 lines
1.2 KiB
Java

package za.org.treehouse.hypoalarm;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import java.util.Calendar;
public class AlarmChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
// Don't set this to happen on TIME_SET, or it'll restart the alarm every time the network (or NTP) sets the time.
// intent.getAction().equals("android.intent.action.TIME_SET")
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED") ||
intent.getAction().equals("android.intent.action.TIMEZONE_CHANGED")) {
String alarmTimeStr = sharedPref.getString(context.getString(R.string.AlarmTimePref), MainActivity.defaultTimeStr);
Calendar cal = MainActivity.TimeStringToCalendar(alarmTimeStr);
Log.d("AlarmChangeReceiver", intent.getAction() + ": resetting alarm for " + MainActivity.debugDate(cal));
MainActivity.setAlarm(context, cal);
}
}
}