diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 78202d9250..03f5b414ce 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -82,6 +82,8 @@
+
+
diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java
index 45aff91654..a677b65d6a 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainApp.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java
@@ -69,6 +69,7 @@ import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
+import info.nightscout.androidaps.plugins.Source.SourcePoctechPlugin;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
@@ -178,6 +179,8 @@ public class MainApp extends Application {
pluginsList.add(SourceGlimpPlugin.getPlugin());
if (!Config.NSCLIENT)
pluginsList.add(SourceDexcomG5Plugin.getPlugin());
+ if (!Config.NSCLIENT)
+ pluginsList.add(SourcePoctechPlugin.getPlugin());
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
pluginsList.add(FoodPlugin.getPlugin());
diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
index f8437d8d36..9780e6c3eb 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
+import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
@@ -38,6 +39,7 @@ import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
+import info.nightscout.androidaps.plugins.Source.SourcePoctechPlugin;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.utils.BundleLogger;
@@ -54,6 +56,7 @@ public class DataService extends IntentService {
boolean mm640gEnabled = false;
boolean glimpEnabled = false;
boolean dexcomG5Enabled = false;
+ boolean poctechEnabled = false;
public DataService() {
super("DataService");
@@ -70,36 +73,49 @@ public class DataService extends IntentService {
mm640gEnabled = false;
glimpEnabled = false;
dexcomG5Enabled = false;
+ poctechEnabled = false;
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
xDripEnabled = true;
nsClientEnabled = false;
mm640gEnabled = false;
glimpEnabled = false;
dexcomG5Enabled = false;
+ poctechEnabled = false;
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
xDripEnabled = false;
nsClientEnabled = true;
mm640gEnabled = false;
glimpEnabled = false;
dexcomG5Enabled = false;
+ poctechEnabled = false;
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
xDripEnabled = false;
nsClientEnabled = false;
mm640gEnabled = true;
glimpEnabled = false;
dexcomG5Enabled = false;
+ poctechEnabled = false;
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
xDripEnabled = false;
nsClientEnabled = false;
mm640gEnabled = false;
glimpEnabled = true;
dexcomG5Enabled = false;
+ poctechEnabled = false;
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceDexcomG5Plugin.class)) {
xDripEnabled = false;
nsClientEnabled = false;
mm640gEnabled = false;
glimpEnabled = false;
dexcomG5Enabled = true;
+ poctechEnabled = false;
+ } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourcePoctechPlugin.class)) {
+ xDripEnabled = false;
+ nsClientEnabled = false;
+ mm640gEnabled = false;
+ glimpEnabled = false;
+ dexcomG5Enabled = false;
+ poctechEnabled = true;
}
boolean isNSProfile = MainApp.getConfigBuilder().getActiveProfileInterface() != null && MainApp.getConfigBuilder().getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
@@ -129,6 +145,10 @@ public class DataService extends IntentService {
if (dexcomG5Enabled) {
handleNewDataFromDexcomG5(intent);
}
+ } else if (Intents.POCTECH_BG.equals(action)) {
+ if (poctechEnabled) {
+ handleNewDataFromPoctech(intent);
+ }
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
if (nsClientEnabled || SP.getBoolean(R.string.key_ns_autobackfill, true))
handleNewDataFromNSClient(intent);
@@ -250,6 +270,41 @@ public class DataService extends IntentService {
}
}
+ private void handleNewDataFromPoctech(Intent intent) {
+
+ Bundle bundle = intent.getExtras();
+ if (bundle == null) return;
+
+ BgReading bgReading = new BgReading();
+
+ String data = bundle.getString("data");
+ log.debug("Received Poctech Data", data);
+
+ try {
+ JSONArray jsonArray = new JSONArray(data);
+ log.debug("Received Poctech Data size:" + jsonArray.length());
+ for (int i = 0; i < jsonArray.length(); i++) {
+ JSONObject json = jsonArray.getJSONObject(i);
+ bgReading.value = json.getDouble("current");
+ bgReading.direction = json.getString("direction");
+ bgReading.date = json.getLong("date");
+ bgReading.raw = json.getDouble("raw");
+ if (JsonHelper.safeGetString(json, "utils", Constants.MGDL).equals(Constants.MMOL))
+ bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL;
+ boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech");
+ if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
+ NSUpload.uploadBg(bgReading);
+ }
+ if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
+ NSUpload.sendToXdrip(bgReading);
+ }
+ }
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
private void handleNewDataFromMM640g(Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle == null) return;
diff --git a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java
index 744530c8f2..25485fb34d 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java
@@ -49,4 +49,6 @@ public interface Intents {
String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED";
String DEXCOMG5_BG = "com.dexcom.cgm.DATA";
+
+ String POCTECH_BG = "com.china.poctech.data";
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java
new file mode 100644
index 0000000000..13cb99d392
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java
@@ -0,0 +1,39 @@
+package info.nightscout.androidaps.plugins.Source;
+
+import info.nightscout.androidaps.Config;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.BgSourceInterface;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.interfaces.PluginDescription;
+import info.nightscout.androidaps.interfaces.PluginType;
+
+/**
+ * Created by mike on 05.08.2016.
+ */
+public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface {
+
+ private static SourcePoctechPlugin plugin = null;
+
+ public static SourcePoctechPlugin getPlugin() {
+ if (plugin == null)
+ plugin = new SourcePoctechPlugin();
+ return plugin;
+ }
+
+ private SourcePoctechPlugin() {
+ super(new PluginDescription()
+ .mainType(PluginType.BGSOURCE)
+ .fragmentClass(BGSourceFragment.class.getName())
+ .pluginName(R.string.poctech)
+ .showInList(!Config.NSCLIENT)
+ .preferencesId(R.xml.pref_poctech)
+ .description(R.string.description_source_poctech)
+ );
+ }
+
+ @Override
+ public boolean advancedFilteringSupported() {
+ return false;
+ }
+
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 744040cabf..eb9e2cc36c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -803,6 +803,7 @@
Upload BG data to NS
dexcomg5_nsupload
G5 upload settings
+ Poctech upload settings
Show detailed delta
Show delta with one more decimal place
45 60 75 90 105 120
@@ -1139,4 +1140,6 @@
Open navigation
Close navigation
Plugin preferences
+ Poctech
+ Receive BG values from Poctech app
diff --git a/app/src/main/res/xml/pref_dexcomg5.xml b/app/src/main/res/xml/pref_dexcomg5.xml
index 03c49bf624..cd987825d5 100644
--- a/app/src/main/res/xml/pref_dexcomg5.xml
+++ b/app/src/main/res/xml/pref_dexcomg5.xml
@@ -1,7 +1,6 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file