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-10 11:21:16 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.PreferenceManager;
|
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-08-04 01:01:14 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
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) {
|
2015-05-10 11:21:16 +02:00
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2015-05-07 23:46:18 +02:00
|
|
|
final String action = intent.getAction();
|
|
|
|
|
2015-05-10 11:21:16 +02:00
|
|
|
if (sharedPrefs.getBoolean("datetime_synconconnect", true) && (action.equals(Intent.ACTION_TIME_CHANGED) || action.equals(Intent.ACTION_TIMEZONE_CHANGED))) {
|
2015-05-12 06:28:11 +02:00
|
|
|
LOG.info("Time or Timezone changed, syncing with device");
|
2015-08-04 01:01:14 +02:00
|
|
|
Intent startIntent = new Intent(context, DeviceCommunicationService.class);
|
|
|
|
startIntent.setAction(DeviceCommunicationService.ACTION_SETTIME);
|
2015-05-07 23:46:18 +02:00
|
|
|
context.startService(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|