From d113d39916190abb47de17aed933ede52754874a Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 18 Feb 2017 18:13:13 +0100 Subject: [PATCH 1/2] wear setting to show detailed IOB --- .../nightscout/androidaps/PreferencesActivity.java | 6 ++++++ .../androidaps/plugins/Wear/WearPlugin.java | 4 +++- .../Wear/wearintegration/WatchUpdaterService.java | 10 +++++++--- app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/pref_wear.xml | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/xml/pref_wear.xml diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index f0d60cae19..d9807e9d00 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.utils.LocaleHelper; public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -115,6 +116,11 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResource(R.xml.pref_others); addPreferencesFromResource(R.xml.pref_advanced); initSummary(getPreferenceScreen()); + + WearPlugin wearPlugin = (WearPlugin) MainApp.getSpecificPlugin(WearPlugin.class); + if (wearPlugin != null && wearPlugin.isEnabled(PluginBase.GENERAL)) { + addPreferencesFromResource(R.xml.pref_wear); + } } public Preference getPreference (String key) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 96f2b75062..4113076899 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -120,8 +120,10 @@ public class WearPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventPreferenceChange ev) { - //possibly new high or low mark + // possibly new high or low mark resendDataToWatch(); + // status may be formated differently + sendDataToWatch(true, false, false); } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index fc08941cd3..93fe700af2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -520,9 +520,13 @@ public class WatchUpdaterService extends WearableListenerService implements IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round(); MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB(); IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round(); - status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "(" - + DecimalFormatter.to2Decimal(bolusIob.iob) + "|" - + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; + status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); + + if (mPrefs.getBoolean("wear_detailediob", true)) { + status += "(" + + DecimalFormatter.to2Decimal(bolusIob.iob) + "|" + + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; + } PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH); //unique content diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 21bcb13ff5..23fddfed1f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -507,4 +507,7 @@ Password for settings Unlock settings Approaching insulin daily limit + Wear settings + Show detailed IOB + Break down IOB into bolus and basal IOB on the watchface diff --git a/app/src/main/res/xml/pref_wear.xml b/app/src/main/res/xml/pref_wear.xml new file mode 100644 index 0000000000..bc5c475f9e --- /dev/null +++ b/app/src/main/res/xml/pref_wear.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file From abaafb87ebd575951d2e80d69b62f2cff5c939ca Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 18 Feb 2017 18:52:09 +0100 Subject: [PATCH 2/2] wear show on status when loop is disabled --- .../androidaps/plugins/Wear/WearPlugin.java | 12 ++++++++++++ .../wearintegration/WatchUpdaterService.java | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 4113076899..c9520ac82c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -15,6 +15,7 @@ import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterService; @@ -146,6 +147,17 @@ public class WearPlugin implements PluginBase { sendDataToWatch(false, true, false); } + @Subscribe + public void onStatusEvent(final EventRefreshGui ev) { + + LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); + if (activeloop == null) return; + + if(WatchUpdaterService.shouldReportLoopStatus(activeloop.isEnabled(PluginBase.LOOP))) { + sendDataToWatch(true, false, false); + } + } + @Subscribe public void onStatusEvent(final EventOverviewBolusProgress ev) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index 93fe700af2..9e1f9709dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -28,8 +28,10 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TempBasal; +import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.data.IobTotal; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; import info.nightscout.androidaps.plugins.Wear.WearPlugin; @@ -66,6 +68,7 @@ public class WatchUpdaterService extends WearableListenerService implements boolean wear_integration = false; SharedPreferences mPrefs; + private static boolean lastLoopStatus; @Override public void onCreate() { @@ -503,6 +506,15 @@ public class WatchUpdaterService extends WearableListenerService implements String status = ""; boolean shortString = true; + LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); + + if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) { + status += getString(R.string.disabledloop) + "\n"; + lastLoopStatus = false; + } else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) { + lastLoopStatus = true; + } + //Temp basal PumpInterface pump = MainApp.getConfigBuilder(); @@ -555,6 +567,10 @@ public class WatchUpdaterService extends WearableListenerService implements public void onConnectionFailed(ConnectionResult connectionResult) { } + public static boolean shouldReportLoopStatus(boolean enabled){ + return (lastLoopStatus != enabled); + } + public static int getBatteryLevel(Context context) { Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);