2015-05-07 23:46:18 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2015-05-12 06:28:11 +02:00
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2015-05-07 23:46:18 +02:00
|
|
|
|
2015-09-05 00:14:09 +02:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.GregorianCalendar;
|
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-09-05 00:14:09 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
2016-04-25 23:18:55 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2015-05-07 23:46:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
public class TimeChangeReceiver extends BroadcastReceiver {
|
|
|
|
|
2015-05-12 06:28:11 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(TimeChangeReceiver.class);
|
2015-05-07 23:46:18 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2016-04-25 23:18:55 +02:00
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
2015-05-07 23:46:18 +02:00
|
|
|
final String action = intent.getAction();
|
|
|
|
|
2016-04-25 23:18:55 +02:00
|
|
|
if (prefs.getBoolean("datetime_synconconnect", true) && (action.equals(Intent.ACTION_TIME_CHANGED) || action.equals(Intent.ACTION_TIMEZONE_CHANGED))) {
|
2015-09-05 00:14:09 +02:00
|
|
|
Date newTime = GregorianCalendar.getInstance().getTime();
|
|
|
|
LOG.info("Time or Timezone changed, syncing with device: " + DateTimeUtils.formatDate(newTime) + " (" + newTime.toGMTString() + "), " + intent.getAction());
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetTime();
|
2015-05-07 23:46:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|