diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/BluetoothStateReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/BluetoothStateReceiver.java new file mode 100644 index 0000000000..2d72ba8609 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/receivers/BluetoothStateReceiver.java @@ -0,0 +1,50 @@ +package info.nightscout.androidaps.receivers; + +import android.bluetooth.BluetoothAdapter; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; + +public class BluetoothStateReceiver extends BroadcastReceiver { + + private static Logger LOG = LoggerFactory.getLogger(L.PUMP); + + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + + PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump(); + + LOG.debug("BluetoothStateReceiver"); + + if (action != null && activePump != null) { + + final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); + switch (state) { + case BluetoothAdapter.STATE_OFF: + case BluetoothAdapter.STATE_TURNING_OFF: + case BluetoothAdapter.STATE_TURNING_ON: + break; + + case BluetoothAdapter.STATE_ON: { + if ("Medtronic".equals(activePump.manufacter())) { + LOG.debug("BluetoothStateReceiver: Bluetooth back on. Sending broadcast to RileyLink Framework"); + RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected); + } + } + break; + } + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.java new file mode 100644 index 0000000000..6ab9f5bab7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; + +public class TimeDateOrTZChangeReceiver extends BroadcastReceiver { + + private static Logger LOG = LoggerFactory.getLogger(L.PUMP); + + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + + PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump(); + + LOG.debug("Date, Time and/or TimeZone changed."); + + if (action != null && activePump != null) { + LOG.debug("Date, Time and/or TimeZone changed. Notifying pump driver."); + activePump.timeDateOrTimeZoneChanged(); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/SP.java b/app/src/main/java/info/nightscout/androidaps/utils/SP.java index 9d9216ed27..84b6b4b70d 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/SP.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SP.java @@ -125,7 +125,7 @@ public class SP { editor.putInt(MainApp.gs(resourceID), value); editor.apply(); } - + static public void putString(int resourceID, String value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(MainApp.gs(resourceID), value);