From 034faa4f6e09036a1f458008c3192d49fda2af28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karri=20Niemel=C3=A4?= Date: Tue, 29 Aug 2017 15:06:53 +0300 Subject: [PATCH 01/40] Adding support out_units --- .../plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java | 6 ++++++ .../plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 66696ac9b8..7833dbf54e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.Date; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; @@ -224,6 +225,11 @@ public class DetermineBasalAdapterAMAJS { mProfile.add("temptargetSet", tempTargetSet); mProfile.add("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true)); mProfile.add("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d)); + + if (units.equals(Constants.MMOL)) { + mProfile.add("out_units", "mmol/L"); + } + mV8rt.add(PARAM_profile, mProfile); mCurrentTemp = new V8Object(mV8rt); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index dc4d2ee70d..a03ef9731b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; @@ -242,6 +243,11 @@ public class DetermineBasalAdapterMAJS { mProfile.add("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units)); mProfile.add("current_basal", pump.getBaseBasalRate()); + + if (units.equals(Constants.MMOL)) { + mProfile.add("out_units", "mmol/L"); + } + mCurrentTemp.add("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()); mCurrentTemp.add("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()); From 981a96aa16330403c76a720286c90f241badfb6b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 29 Aug 2017 17:59:46 +0200 Subject: [PATCH 02/40] ConfigBuilder layout --- .../ConfigBuilder/ConfigBuilderFragment.java | 45 +--- .../res/layout/configbuilder_fragment.xml | 248 +++++++++--------- .../res/layout/configbuilder_simpleitem.xml | 59 ++--- .../res/layout/configbuilder_smallitem.xml | 48 ---- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values/colors.xml | 1 + 6 files changed, 171 insertions(+), 232 deletions(-) delete mode 100644 app/src/main/res/layout/configbuilder_smallitem.xml diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index be9341b860..3f2c27ef08 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.ConfigBuilder; import android.content.Context; -import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.DisplayMetrics; @@ -58,8 +57,6 @@ public class ConfigBuilderFragment extends Fragment { TextView pumpLabel; ListView loopListView; TextView loopLabel; - ListView treatmentsListView; - TextView treatmentsLabel; ListView profileListView; TextView profileLabel; ListView apsListView; @@ -76,27 +73,16 @@ public class ConfigBuilderFragment extends Fragment { PluginCustomAdapter bgsourceDataAdapter = null; PluginCustomAdapter pumpDataAdapter = null; PluginCustomAdapter loopDataAdapter = null; - PluginCustomAdapter treatmentsDataAdapter = null; PluginCustomAdapter profileDataAdapter = null; PluginCustomAdapter apsDataAdapter = null; PluginCustomAdapter constraintsDataAdapter = null; PluginCustomAdapter generalDataAdapter = null; - boolean smallWidth; - - // TODO: sorting - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.configbuilder_fragment, container, false); - //check screen width - final DisplayMetrics dm = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); - int screen_width = dm.widthPixels; - smallWidth = screen_width < Constants.SMALL_WIDTH; - insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview); sensitivityListView = (ListView) view.findViewById(R.id.configbuilder_sensitivitylistview); bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview); @@ -105,8 +91,6 @@ public class ConfigBuilderFragment extends Fragment { pumpLabel = (TextView) view.findViewById(R.id.configbuilder_pumplabel); loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview); loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel); - treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview); - treatmentsLabel = (TextView) view.findViewById(R.id.configbuilder_treatmentslabel); profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview); profileLabel = (TextView) view.findViewById(R.id.configbuilder_profilelabel); apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview); @@ -141,48 +125,43 @@ public class ConfigBuilderFragment extends Fragment { } void setViews() { - insulinDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginBase.INSULIN), PluginBase.INSULIN); + insulinDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginBase.INSULIN), PluginBase.INSULIN); insulinListView.setAdapter(insulinDataAdapter); setListViewHeightBasedOnChildren(insulinListView); - bgsourceDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginBase.BGSOURCE), PluginBase.BGSOURCE); + bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginBase.BGSOURCE), PluginBase.BGSOURCE); bgsourceListView.setAdapter(bgsourceDataAdapter); if (MainApp.getSpecificPluginsVisibleInList(PluginBase.BGSOURCE).size() == 0) bgsourceLabel.setVisibility(View.GONE); setListViewHeightBasedOnChildren(bgsourceListView); - pumpDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.PUMP), PluginBase.PUMP); + pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.PUMP), PluginBase.PUMP); pumpListView.setAdapter(pumpDataAdapter); if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PUMP).size() == 0) pumpLabel.setVisibility(View.GONE); setListViewHeightBasedOnChildren(pumpListView); - loopDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP), PluginBase.LOOP); + loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP), PluginBase.LOOP); loopListView.setAdapter(loopDataAdapter); setListViewHeightBasedOnChildren(loopListView); if (MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP).size() == 0) loopLabel.setVisibility(View.GONE); - treatmentsDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT), PluginBase.TREATMENT); - treatmentsListView.setAdapter(treatmentsDataAdapter); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT).size() == 0) - treatmentsLabel.setVisibility(View.GONE); - setListViewHeightBasedOnChildren(treatmentsListView); - profileDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginBase.PROFILE), PluginBase.PROFILE); + profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginBase.PROFILE), PluginBase.PROFILE); profileListView.setAdapter(profileDataAdapter); if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PROFILE).size() == 0) profileLabel.setVisibility(View.GONE); setListViewHeightBasedOnChildren(profileListView); - apsDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.APS), PluginBase.APS); + apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.APS), PluginBase.APS); apsListView.setAdapter(apsDataAdapter); setListViewHeightBasedOnChildren(apsListView); if (MainApp.getSpecificPluginsVisibleInList(PluginBase.APS).size() == 0) apsLabel.setVisibility(View.GONE); - sensivityDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginBase.SENSITIVITY), PluginBase.SENSITIVITY); + sensivityDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginBase.SENSITIVITY), PluginBase.SENSITIVITY); sensitivityListView.setAdapter(sensivityDataAdapter); setListViewHeightBasedOnChildren(sensitivityListView); - constraintsDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginBase.CONSTRAINTS), PluginBase.CONSTRAINTS); + constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginBase.CONSTRAINTS), PluginBase.CONSTRAINTS); constraintsListView.setAdapter(constraintsDataAdapter); setListViewHeightBasedOnChildren(constraintsListView); if (MainApp.getSpecificPluginsVisibleInList(PluginBase.CONSTRAINTS).size() == 0) constraintsLabel.setVisibility(View.GONE); - generalDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.GENERAL), PluginBase.GENERAL); + generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.GENERAL), PluginBase.GENERAL); generalListView.setAdapter(generalDataAdapter); setListViewHeightBasedOnChildren(generalListView); @@ -217,7 +196,7 @@ public class ConfigBuilderFragment extends Fragment { PluginViewHolder holder = null; if (view == null) { - view = LayoutInflater.from(parent.getContext()).inflate(smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, null); + view = LayoutInflater.from(parent.getContext()).inflate(R.layout.configbuilder_simpleitem, null); holder = new PluginViewHolder(); holder.name = (TextView) view.findViewById(R.id.configbuilder_simpleitem_name); @@ -307,6 +286,10 @@ public class ConfigBuilderFragment extends Fragment { } } + if (plugin.isEnabled(type)) { + view.setBackgroundColor(MainApp.sResources.getColor(R.color.configBuilderSelectedBackground)); + } + return view; } diff --git a/app/src/main/res/layout/configbuilder_fragment.xml b/app/src/main/res/layout/configbuilder_fragment.xml index 02aaeb78af..881afb9f80 100644 --- a/app/src/main/res/layout/configbuilder_fragment.xml +++ b/app/src/main/res/layout/configbuilder_fragment.xml @@ -25,173 +25,177 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - diff --git a/app/src/main/res/layout/configbuilder_simpleitem.xml b/app/src/main/res/layout/configbuilder_simpleitem.xml index 5adac7e03b..ea3775a5d0 100644 --- a/app/src/main/res/layout/configbuilder_simpleitem.xml +++ b/app/src/main/res/layout/configbuilder_simpleitem.xml @@ -3,41 +3,40 @@ - - - - - - + android:orientation="vertical"> + android:layout_gravity="left" + android:layout_marginLeft="5dp" + android:layout_weight="1" + android:text="ConfigBuilder plugin text" /> + + + + + + diff --git a/app/src/main/res/layout/configbuilder_smallitem.xml b/app/src/main/res/layout/configbuilder_smallitem.xml deleted file mode 100644 index 63b1b2c20f..0000000000 --- a/app/src/main/res/layout/configbuilder_smallitem.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index e656d0053d..20a54298c2 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -607,7 +607,7 @@ Ruština Při zapnuté detektci sensitivity nezapomeňte vkládat všechny sacharidy. Jinak budou odchylky mylně vyhodnocovány jako změna sensitivity !! Sensitivita AAPS - Sensotivita Oref0 + Sensitivita Oref0 Sensitivita vážený průměr OpenAPS OAPS diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 5b1d364563..cb9206a4c7 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -34,6 +34,7 @@ #779ECB #3e3d3d + #262525 #f4d700 #67dfe8 From 7dfe77dc9ccdd404d6e4fb08b51ebf1ead15fc6f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 29 Aug 2017 19:47:32 +0200 Subject: [PATCH 03/40] single line in configbuilder --- .../res/layout/configbuilder_simpleitem.xml | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/app/src/main/res/layout/configbuilder_simpleitem.xml b/app/src/main/res/layout/configbuilder_simpleitem.xml index ea3775a5d0..806ae3ea98 100644 --- a/app/src/main/res/layout/configbuilder_simpleitem.xml +++ b/app/src/main/res/layout/configbuilder_simpleitem.xml @@ -3,40 +3,29 @@ + android:orientation="horizontal"> + + - - - - - - + From 7da8b2de5c9321b7dcb7d0ea290557d6f78d6233 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 29 Aug 2017 21:40:06 +0200 Subject: [PATCH 04/40] visibility icon --- .../res/drawable/visibility_black_16x16.png | Bin 0 -> 233 bytes .../res/layout/configbuilder_fragment.xml | 39 +++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/drawable/visibility_black_16x16.png diff --git a/app/src/main/res/drawable/visibility_black_16x16.png b/app/src/main/res/drawable/visibility_black_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..d24867dcdf25e7cf90ddd1c90d999359b2410d3f GIT binary patch literal 233 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6Hh8)?hG>ZHJ?QP_#K^#UA$dlw z!^Ox823=u7mli2?D4ek4o@lVxlkb*Op!5sVugwxwpJxi2Kd{WX*vTHBmS%U?dRyZ8 zxvdf}D@{bW&9km$#kuTRrESXN@+D+#OsB+3>);<3ubGGyCcZqdzC(^nkoA{R+PCr} z`&qTT99=b&UIrZraE^X>d*!swj$-ZI^IUjLrbgX!DG6PBwdBmvi2Iv6XY3B!`tZbB h{@~#ER(!eV - + android:layout_height="wrap_content"> + + + + + Date: Thu, 31 Aug 2017 09:09:26 +0300 Subject: [PATCH 05/40] Update strings.xml --- app/src/main/res/values-bg/strings.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 84ae6eaf3b..4234a55d4f 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -91,7 +91,7 @@ Treatments Временен базал Профил - APS + Алгоритъм за APS Общи дни Минимална продължителност @@ -355,8 +355,8 @@ Единици: мг/дл ммол/л - DIA(време на действие на инсулина): - Целеви диапазон: + DIA: + Целева КЗ: Редактирай базални стойности Редактирай Инс. чувствителност Редактирай Инс./ВХ @@ -540,7 +540,7 @@ Бързодействащ инсулин Novorapid, Novolog, Humalog ИНС - Бързодействащ инсулин с удължаване + Бързодействащ инсулин с удължение Разреши използването на Суперболус Разреши функцията суперболус в съветника. Не я разрешавайте докато не научите какво наистина прави. ТОВА МОЖЕ ДА СЪЗДАДЕ ОПАСНОСТ ОТ ПРЕДОЗИРАНЕ С ИНСУЛИН. IOB @@ -639,7 +639,7 @@ ПОМПА Дата DIA от %s е твърде кратка - използвай %s вместо това! - със свободен пик по Oref + Със свободен пик по Oref Пик на кривата на IOB Време на пик [мин.] НЕВАЛИДНО From c312b51fcf83ab7be1aeb159e5b959ab189644a2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 31 Aug 2017 19:32:28 +0200 Subject: [PATCH 06/40] consolidate DanaR fragments --- .../info/nightscout/androidaps/MainApp.java | 12 +- .../plugins/PumpDanaR/DanaRFragment.java | 29 +- .../plugins/PumpDanaR/DanaRPlugin.java | 8 + .../PumpDanaRKorean/DanaRKoreanFragment.java | 248 ----------------- .../PumpDanaRKorean/DanaRKoreanPlugin.java | 15 +- .../plugins/PumpDanaRv2/DanaRv2Fragment.java | 250 ------------------ .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 17 +- 7 files changed, 53 insertions(+), 526 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 338b5f2e07..3431bfd39c 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -47,11 +47,11 @@ import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPe import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment; import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment; import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfileFragment; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanFragment; +import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; -import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Fragment; +import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; @@ -120,9 +120,9 @@ public class MainApp extends Application { pluginsList.add(SensitivityOref0Plugin.getPlugin()); pluginsList.add(SensitivityAAPSPlugin.getPlugin()); pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin()); - if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin()); - if (Config.DANAR) pluginsList.add(DanaRKoreanFragment.getPlugin()); - if (Config.DANARv2) pluginsList.add(DanaRv2Fragment.getPlugin()); + if (Config.DANAR) pluginsList.add(DanaRPlugin.getPlugin()); + if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin()); + if (Config.DANARv2) pluginsList.add(DanaRv2Plugin.getPlugin()); pluginsList.add(CareportalFragment.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index 87c635cbef..f392485f4b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -39,15 +39,6 @@ import info.nightscout.utils.SetWarnColor; public class DanaRFragment extends SubscriberFragment { private static Logger log = LoggerFactory.getLogger(DanaRFragment.class); - private static DanaRPlugin danaRPlugin; - - public static DanaRPlugin getPlugin() { - if (danaRPlugin == null) { - danaRPlugin = new DanaRPlugin(); - } - return danaRPlugin; - } - private static Handler sHandler; private static HandlerThread sHandlerThread; @@ -146,7 +137,7 @@ public class DanaRFragment extends SubscriberFragment { sHandler.post(new Runnable() { @Override public void run() { - DanaRPlugin.sExecutionService.connect("Connect request from GUI"); + MainApp.getConfigBuilder().refreshDataFromPump("Connect request from GUI"); } } ); @@ -218,11 +209,21 @@ public class DanaRFragment extends SubscriberFragment { dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); - basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); - if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); + basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getBaseBasalRate()) + " U/h"); + // DanaRPlugin, DanaRKoreanPlugin + if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) { + if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { + tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); + } else { + tempBasalView.setText(""); + } } else { - tempBasalView.setText(""); + // v2 plugin + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); + } else { + tempBasalView.setText(""); + } } if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index bc5b23ad92..f4343c1629 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -69,6 +69,14 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C private static DanaRPump pump = DanaRPump.getInstance(); private static boolean useExtendedBoluses = false; + private static DanaRPlugin plugin = null; + + public static DanaRPlugin getPlugin() { + if (plugin == null) + plugin = new DanaRPlugin(); + return plugin; + } + public static PumpDescription pumpDescription = new PumpDescription(); public DanaRPlugin() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java deleted file mode 100644 index 50ec8883c6..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java +++ /dev/null @@ -1,248 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpDanaRKorean; - - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.os.HandlerThread; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.TextView; - -import com.squareup.otto.Subscribe; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.events.EventPumpStatusChanged; -import info.nightscout.androidaps.events.EventTempBasalChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SetWarnColor; - -public class DanaRKoreanFragment extends SubscriberFragment { - private static Logger log = LoggerFactory.getLogger(DanaRKoreanFragment.class); - - private static DanaRKoreanPlugin danaRKoreanPlugin = new DanaRKoreanPlugin(); - - public static DanaRKoreanPlugin getPlugin() { - return danaRKoreanPlugin; - } - - private static Handler sHandler; - private static HandlerThread sHandlerThread; - - private Handler loopHandler = new Handler(); - private Runnable refreshLoop = null; - - TextView lastConnectionView; - TextView btConnectionView; - TextView lastBolusView; - TextView dailyUnitsView; - TextView basaBasalRateView; - TextView tempBasalView; - TextView extendedBolusView; - TextView batteryView; - TextView reservoirView; - TextView iobView; - TextView firmwareView; - TextView basalStepView; - TextView bolusStepView; - Button viewProfileButton; - Button historyButton; - Button statsButton; - - - public DanaRKoreanFragment() { - if (sHandlerThread == null) { - sHandlerThread = new HandlerThread(DanaRKoreanFragment.class.getSimpleName()); - sHandlerThread.start(); - sHandler = new Handler(sHandlerThread.getLooper()); - } - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (refreshLoop == null) { - refreshLoop = new Runnable() { - @Override - public void run() { - updateGUI(); - loopHandler.postDelayed(refreshLoop, 60 * 1000L); - } - }; - loopHandler.postDelayed(refreshLoop, 60 * 1000L); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.danar_fragment, container, false); - btConnectionView = (TextView) view.findViewById(R.id.danar_btconnection); - lastConnectionView = (TextView) view.findViewById(R.id.danar_lastconnection); - lastBolusView = (TextView) view.findViewById(R.id.danar_lastbolus); - dailyUnitsView = (TextView) view.findViewById(R.id.danar_dailyunits); - basaBasalRateView = (TextView) view.findViewById(R.id.danar_basabasalrate); - tempBasalView = (TextView) view.findViewById(R.id.danar_tempbasal); - extendedBolusView = (TextView) view.findViewById(R.id.danar_extendedbolus); - batteryView = (TextView) view.findViewById(R.id.danar_battery); - reservoirView = (TextView) view.findViewById(R.id.danar_reservoir); - iobView = (TextView) view.findViewById(R.id.danar_iob); - firmwareView = (TextView) view.findViewById(R.id.danar_firmware); - viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile); - historyButton = (Button) view.findViewById(R.id.danar_history); - statsButton = (Button) view.findViewById(R.id.danar_stats); - basalStepView = (TextView) view.findViewById(R.id.danar_basalstep); - bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep); - - - viewProfileButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - FragmentManager manager = getFragmentManager(); - ProfileViewDialog profileViewDialog = new ProfileViewDialog(); - profileViewDialog.show(manager, "ProfileViewDialog"); - } - }); - - historyButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(new Intent(getContext(), DanaRHistoryActivity.class)); - } - }); - - statsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(new Intent(getContext(), DanaRStatsActivity.class)); - } - }); - - btConnectionView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - sHandler.post(new Runnable() { - @Override - public void run() { - DanaRKoreanPlugin.sExecutionService.connect("Connect request from GUI"); - } - } - ); - } - }); - - updateGUI(); - return view; - } - - @Subscribe - public void onStatusEvent(final EventPumpStatusChanged c) { - Activity activity = getActivity(); - if (activity != null) { - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - if (c.sStatus == EventPumpStatusChanged.CONNECTING) - btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s"); - else if (c.sStatus == EventPumpStatusChanged.CONNECTED) - btConnectionView.setText("{fa-bluetooth}"); - else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED) - btConnectionView.setText("{fa-bluetooth-b}"); - } - } - ); - } - } - - @Subscribe - public void onStatusEvent(final EventDanaRNewStatus s) { - updateGUI(); - } - - @Subscribe - public void onStatusEvent(final EventTempBasalChange s) { - updateGUI(); - } - - @Subscribe - public void onStatusEvent(final EventExtendedBolusChange s) { - updateGUI(); - } - - // GUI functions - @Override - protected void updateGUI() { - - Activity activity = getActivity(); - if (activity != null && basaBasalRateView != null) - activity.runOnUiThread(new Runnable() { - @SuppressLint("SetTextI18n") - @Override - public void run() { - DanaRPump pump = DanaRPump.getInstance(); - if (pump.lastConnection.getTime() != 0) { - Long agoMsec = System.currentTimeMillis() - pump.lastConnection.getTime(); - int agoMin = (int) (agoMsec / 60d / 1000d); - lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); - SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d); - } -// if (pump.lastBolusTime.getTime() != 0) { -// Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime(); -// double agoHours = agoMsec / 60d / 60d / 1000d; -// if (agoHours < 6) // max 6h back -// lastBolusView.setText(formatTime.format(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + " U"); -// else lastBolusView.setText(""); -// } - - dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); - SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); - basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h"); - if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); - } else { - tempBasalView.setText(""); - } - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { - extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString()); - } else { - extendedBolusView.setText(""); - } - reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U"); - SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d); - batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}"); - SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d); - iobView.setText(pump.iob + " U"); - if (pump.isNewPump) { - firmwareView.setText(String.format(MainApp.sResources.getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode)); - } else { - firmwareView.setText("OLD"); - } - basalStepView.setText("" + pump.basalStep); - bolusStepView.setText("" + pump.bolusStep); - } - }); - - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 354db54c48..e912eac0b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -23,6 +23,8 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; @@ -36,12 +38,11 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; import info.nightscout.utils.DateUtil; @@ -57,7 +58,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf @Override public String getFragmentClass() { - return DanaRKoreanFragment.class.getName(); + return DanaRFragment.class.getName(); } static boolean fragmentPumpEnabled = false; @@ -70,6 +71,14 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf private static DanaRPump pump = DanaRPump.getInstance(); private static boolean useExtendedBoluses = false; + private static DanaRKoreanPlugin plugin = null; + + public static DanaRKoreanPlugin getPlugin() { + if (plugin == null) + plugin = new DanaRKoreanPlugin(); + return plugin; + } + public static PumpDescription pumpDescription = new PumpDescription(); public DanaRKoreanPlugin() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java deleted file mode 100644 index 85d9f4b5f2..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java +++ /dev/null @@ -1,250 +0,0 @@ -package info.nightscout.androidaps.plugins.PumpDanaRv2; - - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.os.HandlerThread; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.TextView; - -import com.squareup.otto.Subscribe; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.events.EventPumpStatusChanged; -import info.nightscout.androidaps.events.EventTempBasalChange; -import info.nightscout.androidaps.plugins.Common.SubscriberFragment; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity; -import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; -import info.nightscout.utils.DateUtil; -import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.SetWarnColor; - -public class DanaRv2Fragment extends SubscriberFragment { - private static Logger log = LoggerFactory.getLogger(DanaRv2Fragment.class); - - private static DanaRv2Plugin danaRPlugin; - - public static DanaRv2Plugin getPlugin() { - if (danaRPlugin == null) { - danaRPlugin = new DanaRv2Plugin(); - } - return danaRPlugin; - } - - private static Handler sHandler; - private static HandlerThread sHandlerThread; - - private Handler loopHandler = new Handler(); - private Runnable refreshLoop = null; - - TextView lastConnectionView; - TextView btConnectionView; - TextView lastBolusView; - TextView dailyUnitsView; - TextView basaBasalRateView; - TextView tempBasalView; - TextView extendedBolusView; - TextView batteryView; - TextView reservoirView; - TextView iobView; - TextView firmwareView; - TextView basalStepView; - TextView bolusStepView; - Button viewProfileButton; - Button historyButton; - Button statsButton; - - - public DanaRv2Fragment() { - if (sHandlerThread == null) { - sHandlerThread = new HandlerThread(DanaRv2Fragment.class.getSimpleName()); - sHandlerThread.start(); - sHandler = new Handler(sHandlerThread.getLooper()); - } - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (refreshLoop == null) { - refreshLoop = new Runnable() { - @Override - public void run() { - updateGUI(); - loopHandler.postDelayed(refreshLoop, 60 * 1000L); - } - }; - loopHandler.postDelayed(refreshLoop, 60 * 1000L); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.danar_fragment, container, false); - btConnectionView = (TextView) view.findViewById(R.id.danar_btconnection); - lastConnectionView = (TextView) view.findViewById(R.id.danar_lastconnection); - lastBolusView = (TextView) view.findViewById(R.id.danar_lastbolus); - dailyUnitsView = (TextView) view.findViewById(R.id.danar_dailyunits); - basaBasalRateView = (TextView) view.findViewById(R.id.danar_basabasalrate); - tempBasalView = (TextView) view.findViewById(R.id.danar_tempbasal); - extendedBolusView = (TextView) view.findViewById(R.id.danar_extendedbolus); - batteryView = (TextView) view.findViewById(R.id.danar_battery); - reservoirView = (TextView) view.findViewById(R.id.danar_reservoir); - iobView = (TextView) view.findViewById(R.id.danar_iob); - firmwareView = (TextView) view.findViewById(R.id.danar_firmware); - viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile); - historyButton = (Button) view.findViewById(R.id.danar_history); - statsButton = (Button) view.findViewById(R.id.danar_stats); - basalStepView = (TextView) view.findViewById(R.id.danar_basalstep); - bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep); - - - viewProfileButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - FragmentManager manager = getFragmentManager(); - ProfileViewDialog profileViewDialog = new ProfileViewDialog(); - profileViewDialog.show(manager, "ProfileViewDialog"); - } - }); - - historyButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(new Intent(getContext(), DanaRHistoryActivity.class)); - } - }); - - statsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(new Intent(getContext(), DanaRStatsActivity.class)); - } - }); - - btConnectionView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - sHandler.post(new Runnable() { - @Override - public void run() { - DanaRv2Plugin.sExecutionService.connect("Connect request from GUI"); - } - } - ); - } - }); - - updateGUI(); - return view; - } - - @Subscribe - public void onStatusEvent(final EventPumpStatusChanged c) { - Activity activity = getActivity(); - if (activity != null) { - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - if (c.sStatus == EventPumpStatusChanged.CONNECTING) - btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s"); - else if (c.sStatus == EventPumpStatusChanged.CONNECTED) - btConnectionView.setText("{fa-bluetooth}"); - else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED) - btConnectionView.setText("{fa-bluetooth-b}"); - } - } - ); - } - } - - @Subscribe - public void onStatusEvent(final EventDanaRNewStatus s) { - updateGUI(); - } - - @Subscribe - public void onStatusEvent(final EventTempBasalChange s) { - updateGUI(); - } - - @Subscribe - public void onStatusEvent(final EventExtendedBolusChange s) { - updateGUI(); - } - - // GUI functions - @Override - protected void updateGUI() { - Activity activity = getActivity(); - if (activity != null && basaBasalRateView != null) - activity.runOnUiThread(new Runnable() { - @SuppressLint("SetTextI18n") - @Override - public void run() { - DanaRPump pump = DanaRPump.getInstance(); - if (pump.lastConnection.getTime() != 0) { - Long agoMsec = System.currentTimeMillis() - pump.lastConnection.getTime(); - int agoMin = (int) (agoMsec / 60d / 1000d); - lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.sResources.getString(R.string.minago), agoMin) + ")"); - SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d); - } - if (pump.lastBolusTime.getTime() != 0) { - Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime(); - double agoHours = agoMsec / 60d / 60d / 1000d; - if (agoHours < 6) // max 6h back - lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U"); - else lastBolusView.setText(""); - } - - dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); - SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); - basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); - } else { - tempBasalView.setText(""); - } - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { - extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString()); - } else { - extendedBolusView.setText(""); - } - reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U"); - SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d); - batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}"); - SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d); - iobView.setText(pump.iob + " U"); - if (pump.isNewPump) { - firmwareView.setText(String.format(MainApp.sResources.getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode)); - } else { - firmwareView.setText("OLD"); - } - basalStepView.setText("" + pump.basalStep); - bolusStepView.setText("" + pump.bolusStep); - } - }); - - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 6960e96b17..9ff9efeaf3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -4,9 +4,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; -import android.content.SharedPreferences; import android.os.IBinder; -import android.preference.PreferenceManager; import android.support.annotation.Nullable; import com.squareup.otto.Subscribe; @@ -25,6 +23,8 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; @@ -37,13 +37,12 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.utils.DateUtil; @@ -58,7 +57,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, @Override public String getFragmentClass() { - return DanaRv2Fragment.class.getName(); + return DanaRFragment.class.getName(); } static boolean fragmentPumpEnabled = false; @@ -68,6 +67,14 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, public static DanaRv2ExecutionService sExecutionService; + private static DanaRv2Plugin plugin = null; + + public static DanaRv2Plugin getPlugin() { + if (plugin == null) + plugin = new DanaRv2Plugin(); + return plugin; + } + private static DanaRPump pump = DanaRPump.getInstance(); public static PumpDescription pumpDescription = new PumpDescription(); From db952759e119540988a72a4f5b4d491f19aec485 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 31 Aug 2017 22:00:45 +0200 Subject: [PATCH 07/40] Insulin fragments consolidation --- .../info/nightscout/androidaps/MainApp.java | 20 +++---- .../androidaps/PreferencesActivity.java | 2 +- .../ConfigBuilder/ConfigBuilderFragment.java | 4 +- .../ActivityGraph.java | 2 +- .../InsulinFastactingPlugin.java | 12 +++- .../InsulinFastactingProlongedPlugin.java | 12 +++- .../InsulinFragment.java} | 18 ++---- .../InsulinOrefBasePlugin.java | 2 +- .../InsulinOrefFreePeakPlugin.java | 12 +++- .../InsulinOrefRapidActingPlugin.java | 12 +++- .../InsulinOrefUltraRapidActingPlugin.java | 12 +++- .../InsulinFastactingProlongedFragment.java | 57 ------------------ .../InsulinOrefFreePeakFragment.java | 58 ------------------- .../InsulinOrefRapidActingFragment.java | 57 ------------------ .../InsulinOrefUltraRapidActingFragment.java | 58 ------------------- app/src/main/res/layout/insulin_fragment.xml | 4 +- .../layout/overview_calibration_dialog.xml | 2 +- .../overview_newextendedbolus_dialog.xml | 2 +- .../layout/overview_newtempbasal_dialog.xml | 2 +- 19 files changed, 75 insertions(+), 273 deletions(-) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinFastacting => Insulin}/ActivityGraph.java (97%) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinFastacting => Insulin}/InsulinFastactingPlugin.java (91%) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinFastactingProlonged => Insulin}/InsulinFastactingProlongedPlugin.java (91%) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinFastacting/InsulinFastactingFragment.java => Insulin/InsulinFragment.java} (67%) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinOrefCurves => Insulin}/InsulinOrefBasePlugin.java (98%) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinOrefCurves => Insulin}/InsulinOrefFreePeakPlugin.java (82%) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinOrefCurves => Insulin}/InsulinOrefRapidActingPlugin.java (81%) rename app/src/main/java/info/nightscout/androidaps/plugins/{InsulinOrefCurves => Insulin}/InsulinOrefUltraRapidActingPlugin.java (81%) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastactingProlonged/InsulinFastactingProlongedFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefFreePeakFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefRapidActingFragment.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefUltraRapidActingFragment.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 3431bfd39c..18727d87f0 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -30,11 +30,11 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragment; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; -import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment; -import info.nightscout.androidaps.plugins.InsulinFastactingProlonged.InsulinFastactingProlongedFragment; -import info.nightscout.androidaps.plugins.InsulinOrefCurves.InsulinOrefFreePeakFragment; -import info.nightscout.androidaps.plugins.InsulinOrefCurves.InsulinOrefRapidActingFragment; -import info.nightscout.androidaps.plugins.InsulinOrefCurves.InsulinOrefUltraRapidActingFragment; +import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin; +import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingProlongedPlugin; +import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; +import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin; +import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopFragment; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment; @@ -112,11 +112,11 @@ public class MainApp extends Application { pluginsList.add(OverviewFragment.getPlugin()); pluginsList.add(IobCobCalculatorPlugin.getPlugin()); if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin()); - pluginsList.add(InsulinFastactingFragment.getPlugin()); - pluginsList.add(InsulinFastactingProlongedFragment.getPlugin()); - pluginsList.add(InsulinOrefRapidActingFragment.getPlugin()); - pluginsList.add(InsulinOrefUltraRapidActingFragment.getPlugin()); - pluginsList.add(InsulinOrefFreePeakFragment.getPlugin()); + pluginsList.add(InsulinFastactingPlugin.getPlugin()); + pluginsList.add(InsulinFastactingProlongedPlugin.getPlugin()); + pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin()); + pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin()); + pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin()); pluginsList.add(SensitivityOref0Plugin.getPlugin()); pluginsList.add(SensitivityAAPSPlugin.getPlugin()); pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index 5c3372123e..c5abda1eae 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -14,7 +14,7 @@ import android.preference.PreferenceManager; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.plugins.InsulinOrefCurves.InsulinOrefFreePeakPlugin; +import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index 3f2c27ef08..e79c1b06ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -4,7 +4,6 @@ package info.nightscout.androidaps.plugins.ConfigBuilder; import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -21,7 +20,6 @@ import com.crashlytics.android.answers.CustomEvent; import java.util.ArrayList; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventConfigBuilderChange; @@ -34,7 +32,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface; -import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingPlugin; +import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/ActivityGraph.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/ActivityGraph.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java index 3eda06fb37..5a0d7fcce9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/ActivityGraph.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/ActivityGraph.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinFastacting; +package info.nightscout.androidaps.plugins.Insulin; import android.content.Context; import android.graphics.Color; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/InsulinFastactingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/InsulinFastactingPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java index e055e3d3ed..3c7a7b950e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/InsulinFastactingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinFastacting; +package info.nightscout.androidaps.plugins.Insulin; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; @@ -17,6 +17,14 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface { private static boolean fragmentEnabled = true; private static boolean fragmentVisible = false; + private static InsulinFastactingPlugin plugin = null; + + public static InsulinFastactingPlugin getPlugin() { + if (plugin == null) + plugin = new InsulinFastactingPlugin(); + return plugin; + } + @Override public int getType() { return INSULIN; @@ -24,7 +32,7 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface { @Override public String getFragmentClass() { - return InsulinFastactingFragment.class.getName(); + return InsulinFragment.class.getName(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastactingProlonged/InsulinFastactingProlongedPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java similarity index 91% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastactingProlonged/InsulinFastactingProlongedPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java index 3c5df052df..a9f95f0776 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastactingProlonged/InsulinFastactingProlongedPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinFastactingProlonged; +package info.nightscout.androidaps.plugins.Insulin; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; @@ -17,6 +17,14 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte private static boolean fragmentEnabled = false; private static boolean fragmentVisible = false; + private static InsulinFastactingProlongedPlugin plugin = null; + + public static InsulinFastactingProlongedPlugin getPlugin() { + if (plugin == null) + plugin = new InsulinFastactingProlongedPlugin(); + return plugin; + } + @Override public int getType() { return INSULIN; @@ -24,7 +32,7 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte @Override public String getFragmentClass() { - return InsulinFastactingProlongedFragment.class.getName(); + return InsulinFragment.class.getName(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/InsulinFastactingFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java similarity index 67% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/InsulinFastactingFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java index f62d063193..7cd14f346c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastacting/InsulinFastactingFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinFastacting; +package info.nightscout.androidaps.plugins.Insulin; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -14,13 +14,7 @@ import info.nightscout.androidaps.R; * Created by mike on 17.04.2017. */ -public class InsulinFastactingFragment extends Fragment { - static InsulinFastactingPlugin insulinFastactingPlugin = new InsulinFastactingPlugin(); - - static public InsulinFastactingPlugin getPlugin() { - return insulinFastactingPlugin; - } - +public class InsulinFragment extends Fragment { TextView insulinName; TextView insulinComment; TextView insulinDia; @@ -47,10 +41,10 @@ public class InsulinFastactingFragment extends Fragment { } private void updateGUI() { - insulinName.setText(insulinFastactingPlugin.getFriendlyName()); - insulinComment.setText(insulinFastactingPlugin.getComment()); - insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(insulinFastactingPlugin.getDia()) + "h"); - insulinGraph.show(insulinFastactingPlugin); + insulinName.setText(MainApp.getConfigBuilder().getActiveInsulin().getFriendlyName()); + insulinComment.setText(MainApp.getConfigBuilder().getActiveInsulin().getComment()); + insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(MainApp.getConfigBuilder().getActiveInsulin().getDia()) + "h"); + insulinGraph.show(MainApp.getConfigBuilder().getActiveInsulin()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefBasePlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java index 10dfd5dce5..b37e3b5c85 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefBasePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinOrefCurves; +package info.nightscout.androidaps.plugins.Insulin; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefFreePeakPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefFreePeakPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java index 747eabda5b..53612762ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefFreePeakPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinOrefCurves; +package info.nightscout.androidaps.plugins.Insulin; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -13,6 +13,14 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin { private static boolean fragmentEnabled = false; private static boolean fragmentVisible = false; + private static InsulinOrefFreePeakPlugin plugin = null; + + public static InsulinOrefFreePeakPlugin getPlugin() { + if (plugin == null) + plugin = new InsulinOrefFreePeakPlugin(); + return plugin; + } + public static final int DEFAULT_PEAK = 75; @Override @@ -27,7 +35,7 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin { @Override public String getFragmentClass() { - return InsulinOrefFreePeakFragment.class.getName(); + return InsulinFragment.class.getName(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefRapidActingPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java index 6f6973bc58..c8791869a5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinOrefCurves; +package info.nightscout.androidaps.plugins.Insulin; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -12,6 +12,14 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin { private static boolean fragmentEnabled = false; private static boolean fragmentVisible = false; + private static InsulinOrefRapidActingPlugin plugin = null; + + public static InsulinOrefRapidActingPlugin getPlugin() { + if (plugin == null) + plugin = new InsulinOrefRapidActingPlugin(); + return plugin; + } + public static final int PEAK = 75; @Override @@ -26,7 +34,7 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin { @Override public String getFragmentClass() { - return InsulinOrefRapidActingFragment.class.getName(); + return InsulinFragment.class.getName(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefUltraRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java similarity index 81% rename from app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefUltraRapidActingPlugin.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java index 975707d38b..0f09d96d74 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefUltraRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.InsulinOrefCurves; +package info.nightscout.androidaps.plugins.Insulin; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -12,6 +12,14 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { private static boolean fragmentEnabled = false; private static boolean fragmentVisible = false; + private static InsulinOrefUltraRapidActingPlugin plugin = null; + + public static InsulinOrefUltraRapidActingPlugin getPlugin() { + if (plugin == null) + plugin = new InsulinOrefUltraRapidActingPlugin(); + return plugin; + } + public static final int PEAK = 55; @Override @@ -26,7 +34,7 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { @Override public String getFragmentClass() { - return InsulinOrefUltraRapidActingFragment.class.getName(); + return InsulinFragment.class.getName(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastactingProlonged/InsulinFastactingProlongedFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastactingProlonged/InsulinFastactingProlongedFragment.java deleted file mode 100644 index 1747f5f4ab..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinFastactingProlonged/InsulinFastactingProlongedFragment.java +++ /dev/null @@ -1,57 +0,0 @@ -package info.nightscout.androidaps.plugins.InsulinFastactingProlonged; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph; - -/** - * Created by mike on 17.04.2017. - */ - -public class InsulinFastactingProlongedFragment extends Fragment { - static InsulinFastactingProlongedPlugin insulinFastactingProlongedPlugin = new InsulinFastactingProlongedPlugin(); - - static public InsulinFastactingProlongedPlugin getPlugin() { - return insulinFastactingProlongedPlugin; - } - - TextView insulinName; - TextView insulinComment; - TextView insulinDia; - ActivityGraph insulinGraph; - - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.insulin_fragment, container, false); - - insulinName = (TextView) view.findViewById(R.id.insulin_name); - insulinComment = (TextView) view.findViewById(R.id.insulin_comment); - insulinDia = (TextView) view.findViewById(R.id.insulin_dia); - insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph); - - updateGUI(); - - return view; - } - - @Override - public void onResume() { - super.onResume(); - updateGUI(); - } - - private void updateGUI() { - insulinName.setText(insulinFastactingProlongedPlugin.getFriendlyName()); - insulinComment.setText(insulinFastactingProlongedPlugin.getComment()); - insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(insulinFastactingProlongedPlugin.getDia()) + "h"); - insulinGraph.show(insulinFastactingProlongedPlugin); - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefFreePeakFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefFreePeakFragment.java deleted file mode 100644 index f7120369b3..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefFreePeakFragment.java +++ /dev/null @@ -1,58 +0,0 @@ -package info.nightscout.androidaps.plugins.InsulinOrefCurves; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph; - -/** - * Created by adrian on 14/08/17. - */ - -public class InsulinOrefFreePeakFragment extends Fragment { - - static InsulinOrefFreePeakPlugin insulinPlugin = new InsulinOrefFreePeakPlugin(); - - static public InsulinOrefFreePeakPlugin getPlugin() { - return insulinPlugin; - } - - TextView insulinName; - TextView insulinComment; - TextView insulinDia; - ActivityGraph insulinGraph; - - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.insulin_fragment, container, false); - - insulinName = (TextView) view.findViewById(R.id.insulin_name); - insulinComment = (TextView) view.findViewById(R.id.insulin_comment); - insulinDia = (TextView) view.findViewById(R.id.insulin_dia); - insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph); - - updateGUI(); - - return view; - } - - @Override - public void onResume() { - super.onResume(); - updateGUI(); - } - - private void updateGUI() { - insulinName.setText(insulinPlugin.getFriendlyName()); - insulinComment.setText(insulinPlugin.getComment()); - insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(insulinPlugin.getDia()) + "h"); - insulinGraph.show(insulinPlugin); - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefRapidActingFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefRapidActingFragment.java deleted file mode 100644 index e30c087d21..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefRapidActingFragment.java +++ /dev/null @@ -1,57 +0,0 @@ -package info.nightscout.androidaps.plugins.InsulinOrefCurves; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph; - -/** - * Created by adrian on 14/08/17. - */ - -public class InsulinOrefRapidActingFragment extends Fragment { - - static InsulinOrefRapidActingPlugin insulinPlugin = new InsulinOrefRapidActingPlugin(); - - static public InsulinOrefRapidActingPlugin getPlugin() { - return insulinPlugin; - } - - TextView insulinName; - TextView insulinComment; - TextView insulinDia; - ActivityGraph insulinGraph; - - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.insulin_fragment, container, false); - - insulinName = (TextView) view.findViewById(R.id.insulin_name); - insulinComment = (TextView) view.findViewById(R.id.insulin_comment); - insulinDia = (TextView) view.findViewById(R.id.insulin_dia); - insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph); - - updateGUI(); - - return view; - } - - @Override - public void onResume() { - super.onResume(); - updateGUI(); - } - - private void updateGUI() { - insulinName.setText(insulinPlugin.getFriendlyName()); - insulinComment.setText(insulinPlugin.getComment()); - insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(insulinPlugin.getDia()) + "h"); - insulinGraph.show(insulinPlugin); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefUltraRapidActingFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefUltraRapidActingFragment.java deleted file mode 100644 index ea05c7f2e7..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/InsulinOrefCurves/InsulinOrefUltraRapidActingFragment.java +++ /dev/null @@ -1,58 +0,0 @@ -package info.nightscout.androidaps.plugins.InsulinOrefCurves; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph; - -/** - * Created by adrian on 14/08/17. - */ - -public class InsulinOrefUltraRapidActingFragment extends Fragment { - - static InsulinOrefUltraRapidActingPlugin insulinPlugin = new InsulinOrefUltraRapidActingPlugin(); - - static public InsulinOrefUltraRapidActingPlugin getPlugin() { - return insulinPlugin; - } - - TextView insulinName; - TextView insulinComment; - TextView insulinDia; - ActivityGraph insulinGraph; - - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.insulin_fragment, container, false); - - insulinName = (TextView) view.findViewById(R.id.insulin_name); - insulinComment = (TextView) view.findViewById(R.id.insulin_comment); - insulinDia = (TextView) view.findViewById(R.id.insulin_dia); - insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph); - - updateGUI(); - - return view; - } - - @Override - public void onResume() { - super.onResume(); - updateGUI(); - } - - private void updateGUI() { - insulinName.setText(insulinPlugin.getFriendlyName()); - insulinComment.setText(insulinPlugin.getComment()); - insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(insulinPlugin.getDia()) + "h"); - insulinGraph.show(insulinPlugin); - } - -} diff --git a/app/src/main/res/layout/insulin_fragment.xml b/app/src/main/res/layout/insulin_fragment.xml index e9a172ae87..88581403dc 100644 --- a/app/src/main/res/layout/insulin_fragment.xml +++ b/app/src/main/res/layout/insulin_fragment.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment"> + tools:context="info.nightscout.androidaps.plugins.Insulin.InsulinFragment"> - + tools:context="info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog"> + tools:context="info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog"> + tools:context="info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog"> Date: Fri, 1 Sep 2017 10:37:59 +0300 Subject: [PATCH 08/40] update russian --- app/src/main/res/values-ru/strings.xml | 95 ++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 8a5910fb92..2964a144c1 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -53,7 +53,7 @@ абсолют углеводы действие углеводов - продолжительность действия + Длительность действия кем введено время события тип события @@ -221,7 +221,7 @@ палец сенсор ВЕРХНЯЯ отметка - час/а/ов назад + час. назад импортировать настройки из инициализация... ИНС @@ -382,7 +382,7 @@ использовать до: добавить расширенный болюс - величина базала + величина базала (%) % (100% = current) редактировать удалить @@ -559,8 +559,95 @@ xdrip xdrip+ не установлен строка состояния xdrip (часы) - "состояние xdrip (часы) " + состояние xdrip (часы) xds разрешенный предел достигнут AndroidAPS + Ожидаемое время усваивания всех углеводов пищи в часах + Максимальное время усваимости пищи + Настройки усваиваемости + АКТИВИРОВАТЬ ПРОФИЛЬ + БАЗ + Базал отсутствует в профиле. Применяются данные по умолчанию + АКТИВНОСТЬ + канюля проработала + ВозрКан + УГЛЕВОДЫ ; БОЛЮС + МОНИТОРИНГ; OPENAPS + Инсулин проработал + ВозрИнс + Длительность (мин) + Батарея помпы работает + ВозрБат + ПОМПА + замена батареи помпы + сенсор пропаботал + ВОЗРСенс + определение чувствительности + не все профили загружены! + требует активации для отправки данных на помпу! + Данные не сохранены! + Просмотреть расширенный болюс % + DanaRv2 + дата + устройство + pначение длительности работы инс %s слишком мало - применено $s + не отслеживать смены профиля + все смены профиля игнорируются; используется только активный профиль + расширенный болюс + Акуу-Зуфл Щкуа + час + соотношение инс-углев отсутствует в профиле. применено соотн. по умолчанию + Время пика действующего инс IOB + время пика (в мин.) + НЕВЕРНО + Неверный профиль !!! + фактор чувствительности к инс. отутствует в профиле. Применен фактор по умолчанию + блокировка экрана + блок + отмена + OK + Голландский + опции оповещения + Активировать передачу на другие приложения (напр. xDrip) + Активировать локальную передачу + Высокий + Низкий + Нет данных + Порог устаревших данных (мин) + сейчас установлен на %f + Порог тревоги из-за устаревших данных (мин) + Тревога выс + Тревога низкий + Тревога нет данных + OpenAPS + OAPS + отмена расшир болюса + значения базала (ед/ч) + тип базала + смена профиля + помпа + быстро действующий Oref + СООТН + обновить данные из NS + heccrbq + Xedcnd + Активируя Autosense не забывайте вводить все съеденные углеводы. Иначе отклонения в углеводах будут неверно определены как изменение чувствительности !! + Чувствительность AAPS + Чувствительность Oref0 + средневзвешенная чувствительность + Шведский + Целевое значение отсутствует в профиле. Применено значение по умолчанию + ВремБазал + ВремЦель + Fiasp + Сверхбыстрый Oref + Неподдерживаемая версия Nightscout + uploader + UPLD + ПРОДЛ + Просмотр уведомлений + Пропустить уведомления как потдтвержденные от Wear + интервал для autosens (ч) + Время в часах в прошлом для определения чувствительности (время усвоения углеводов исключается) From 15a40cba80472eee5800997625ec41a967982f44 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 1 Sep 2017 14:02:47 +0200 Subject: [PATCH 09/40] Split treatments into smaller packages before broadcasting --- .../plugins/NSClientInternal/broadcasts/BroadcastTreatment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 0d998a2bcd..99644c7ba3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -183,7 +183,7 @@ public class BroadcastTreatment { ret.add(newarr); } newarr = new JSONArray(); - count = 200; + count = 100; } newarr.put(array.get(i)); --count; From 7801db5a29c580af26aa4775e8535e38297c3893 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 2 Sep 2017 10:25:46 +0200 Subject: [PATCH 10/40] fix danar bolus step --- .../nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java | 2 +- .../androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index f4343c1629..96871ac128 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -88,7 +88,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C MainApp.bus().register(this); pumpDescription.isBolusCapable = true; - pumpDescription.bolusStep = 0.1d; + pumpDescription.bolusStep = 0.05d; pumpDescription.isExtendedBolusCapable = true; pumpDescription.extendedBolusStep = 0.05d; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 9ff9efeaf3..82bbc23e5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -86,7 +86,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, MainApp.bus().register(this); pumpDescription.isBolusCapable = true; - pumpDescription.bolusStep = 0.1d; + pumpDescription.bolusStep = 0.05d; pumpDescription.isExtendedBolusCapable = true; pumpDescription.extendedBolusStep = 0.05d; From 3bebea37ae9a66b2f74cc03cb3195f2ba2ac8e3f Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 3 Sep 2017 01:50:27 +0200 Subject: [PATCH 11/40] Use OK/Cancel buttons for 'profile changes refresh from NS' dialog in Treatments tab. --- .../TreatmentsProfileSwitchFragment.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java index fc9d836b8b..7fcca51e67 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java @@ -6,7 +6,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.graphics.Paint; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; @@ -28,14 +27,11 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileIntervals; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventProfileSwitchChange; -import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.NSUpload; -import info.nightscout.utils.OKDialog; import info.nightscout.utils.SP; /** @@ -61,8 +57,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen @Override public ProfileSwitchViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_profileswitch_item, viewGroup, false); - ProfileSwitchViewHolder ProfileSwitchViewHolder = new ProfileSwitchViewHolder(v); - return ProfileSwitchViewHolder; + return new ProfileSwitchViewHolder(v); } @Override @@ -187,14 +182,18 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen public void onClick(View view) { switch (view.getId()) { case R.id.profileswitch_refreshfromnightscout: - OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.confirmation), MainApp.sResources.getString(R.string.refresheventsfromnightscout) + "?", new Runnable() { - @Override - public void run() { + AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); + builder.setTitle(this.getContext().getString(R.string.confirmation)); + builder.setMessage(this.getContext().getString(R.string.refresheventsfromnightscout) + "?"); + builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { MainApp.getDbHelper().resetProfileSwitch(); Intent restartNSClient = new Intent(Intents.ACTION_RESTART); MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); } }); + builder.setNegativeButton(this.getContext().getString(R.string.cancel), null); + builder.show(); break; } } From 1fd99a958259f8dd339d6fc8406101581359a389 Mon Sep 17 00:00:00 2001 From: SMUSTAF1 Date: Tue, 5 Sep 2017 13:29:43 +0200 Subject: [PATCH 12/40] changing the color of the bolus value, for visual clarify and confirmation. Reducing errors. --- .../plugins/Overview/Dialogs/NewTreatmentDialog.java | 12 +++++++----- .../plugins/Overview/Dialogs/WizardDialog.java | 10 +++++++--- app/src/main/res/values/colors.xml | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index e2edb1e76a..cf750a2d39 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -7,6 +7,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; +import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -80,15 +81,16 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Double insulin = SafeParse.stringToDouble(editInsulin.getText()); final Integer carbs = SafeParse.stringToInt(editCarbs.getText()); - String confirmMessage = getString(R.string.entertreatmentquestion) + "\n"; + String confirmMessage = getString(R.string.entertreatmentquestion) + "
"; Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs); - confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U"; - confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; + confirmMessage += getString(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""; + confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; if (insulinAfterConstraints - insulin != 0 || !Objects.equals(carbsAfterConstraints, carbs)) - confirmMessage += "\n" + getString(R.string.constraintapllied); + confirmMessage += "
" + getString(R.string.constraintapllied); + final double finalInsulinAfterConstraints = insulinAfterConstraints; final int finalCarbsAfterConstraints = carbsAfterConstraints; @@ -97,7 +99,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(this.getContext().getString(R.string.confirmation)); - builder.setMessage(confirmMessage); + builder.setMessage(Html.fromHtml(confirmMessage)); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index bda03a8a27..1839a9d217 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -9,6 +9,7 @@ import android.os.HandlerThread; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.text.Editable; +import android.text.Html; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; @@ -274,13 +275,16 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com case R.id.ok: if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) { DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); + String confirmMessage = getString(R.string.entertreatmentquestion); Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(calculatedTotalInsulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(calculatedCarbs); - confirmMessage += "\n" + getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U"; - confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; + confirmMessage += "
" + getString(R.string.bolus) + ": " + "" + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U" + ""; + confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; + + if (insulinAfterConstraints - calculatedTotalInsulin != 0 || !carbsAfterConstraints.equals(calculatedCarbs)) { AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -299,7 +303,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); - builder.setMessage(confirmMessage); + builder.setMessage(Html.fromHtml(confirmMessage)); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cb9206a4c7..4c5c58c993 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,6 +3,7 @@ #ff00ff #00ffff #FFFB8C00 + #FFFFCC03 #8BC34A #FFFFFF #00FF00 From 98848b61eca78a946f625499893aa2bf24942ae9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 5 Sep 2017 22:47:10 +0200 Subject: [PATCH 13/40] send max 30 at once to NS --- .../plugins/NSClientInternal/services/NSClientService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index cbc18acbca..d171f87fc8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -684,10 +684,11 @@ public class NSClientService extends Service { MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend started: " + reason)); CloseableIterator iterator = null; + int maxcount = 30; try { iterator = MainApp.getDbHelper().getDbRequestInterator(); try { - while (iterator.hasNext()) { + while (iterator.hasNext() && maxcount > 0) { DbRequest dbr = iterator.next(); if (dbr.action.equals("dbAdd")) { NSAddAck addAck = new NSAddAck(); @@ -702,6 +703,7 @@ public class NSClientService extends Service { NSUpdateAck updateUnsetAck = new NSUpdateAck(dbr.action, dbr._id); dbUpdateUnset(dbr, updateUnsetAck); } + maxcount--; } } finally { iterator.close(); From b1e3b45ce9f7ad75f5546775cb5ce80d6c7f2906 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Sep 2017 15:34:00 +0200 Subject: [PATCH 14/40] Add temp target to Wizard dialog Also, store checkboxes' state as prefereces. (cherry picked from commit 6e1c66e) --- .../interfaces/TreatmentsInterface.java | 1 + .../ConfigBuilder/ConfigBuilderPlugin.java | 6 ++ .../Overview/Dialogs/WizardDialog.java | 56 ++++++++++++------- .../plugins/Overview/OverviewFragment.java | 10 ++-- .../plugins/Treatments/TreatmentsPlugin.java | 12 +++- .../plugins/Wear/ActionStringHandler.java | 5 +- .../info/nightscout/utils/BolusWizard.java | 35 ++++++------ .../res/layout/overview_wizard_dialog.xml | 38 +++++++++---- app/src/main/res/values/strings.xml | 7 +++ 9 files changed, 111 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index 5e8b4e52e8..044b259ac9 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -52,6 +52,7 @@ public interface TreatmentsInterface { boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo); + TempTarget getTempTargetFromHistory(); TempTarget getTempTargetFromHistory(long time); Intervals getTempTargetsFromHistory(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 6bc0e1e807..8f6b47e2ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -890,6 +890,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return newRecordCreated; } + @Override + @Nullable + public TempTarget getTempTargetFromHistory() { + return activeTreatments.getTempTargetFromHistory(System.currentTimeMillis()); + } + @Override @Nullable public TempTarget getTempTargetFromHistory(long time) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index bda03a8a27..bbfc688252 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -50,6 +50,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; +import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; @@ -73,6 +74,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com TextView bgInsulin; TextView bgUnits; CheckBox bgCheckbox; + CheckBox ttCheckbox; TextView carbs; TextView carbsInsulin; TextView bolusIobInsulin; @@ -216,17 +218,21 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin); bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox); + ttCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_ttcheckbox); + bgtrendCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgtrendcheckbox); + cobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_cobcheckbox); bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox); basalIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_basaliobcheckbox); superbolusCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_sbcheckbox); - bgtrendCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgtrendcheckbox); - cobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_cobcheckbox); + loadCheckedStates(); + bgCheckbox.setOnCheckedChangeListener(this); + ttCheckbox.setOnCheckedChangeListener(this); + bgtrendCheckbox.setOnCheckedChangeListener(this); + cobCheckbox.setOnCheckedChangeListener(this); basalIobCheckbox.setOnCheckedChangeListener(this); bolusIobCheckbox.setOnCheckedChangeListener(this); superbolusCheckbox.setOnCheckedChangeListener(this); - bgtrendCheckbox.setOnCheckedChangeListener(this); - cobCheckbox.setOnCheckedChangeListener(this); profileSpinner = (Spinner) view.findViewById(R.id.treatments_wizard_profile); profileSpinner.setOnItemSelectedListener(this); @@ -253,9 +259,29 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + saveCheckedStates(); + ttCheckbox.setEnabled(bgCheckbox.isChecked() && MainApp.getConfigBuilder().getTempTargetFromHistory() != null); calculateInsulin(); } + private void saveCheckedStates() { + SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_tt), ttCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked()); + } + + private void loadCheckedStates() { + bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); + ttCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_tt), false)); + bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false)); + cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false)); + bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); + basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true)); + } + @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { calculateInsulin(); @@ -381,31 +407,17 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com BgReading lastBg = DatabaseHelper.actualBg(); if (lastBg != null) { - Double lastBgValue = lastBg.valueToUnits(units); - Double sens = profile.getIsf(); - Double targetBGLow = profile.getTargetLow(); - Double targetBGHigh = profile.getTargetHigh(); - Double bgDiff; - if (lastBgValue <= targetBGLow) { - bgDiff = lastBgValue - targetBGLow; - } else { - bgDiff = lastBgValue - targetBGHigh; - } - - bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + DecimalFormatter.to1Decimal(sens)); - bgInsulin.setText(DecimalFormatter.to2Decimal(bgDiff / sens) + "U"); editBg.removeTextChangedListener(textWatcher); //bgInput.setText(lastBg.valueToUnitsToString(units)); editBg.setValue(lastBg.valueToUnits(units)); editBg.addTextChangedListener(textWatcher); } else { - bg.setText(""); - bgInsulin.setText(""); editBg.removeTextChangedListener(textWatcher); //bgInput.setText(""); editBg.setValue(0d); editBg.addTextChangedListener(textWatcher); } + ttCheckbox.setEnabled(MainApp.getConfigBuilder().getTempTargetFromHistory() != null); // IOB calculation MainApp.getConfigBuilder().updateTotalIOBTreatments(); @@ -458,6 +470,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } c_bg = bgCheckbox.isChecked() ? c_bg : 0d; + TempTarget tempTarget = ttCheckbox.isChecked() ? MainApp.getConfigBuilder().getTempTargetFromHistory() : null; // COB Double c_cob = 0d; @@ -466,12 +479,13 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com try { c_cob = SafeParse.stringToDouble(ConfigBuilderPlugin.getActiveAPS().getLastAPSResult().json().getString("COB")); } catch (JSONException e) { + log.error("Unhandled exception", e); } } } BolusWizard wizard = new BolusWizard(); - wizard.doCalc(specificProfile, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), bgtrendCheckbox.isChecked()); + wizard.doCalc(specificProfile, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), bgtrendCheckbox.isChecked()); bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.sens)); bgInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromBG) + "U"); @@ -522,6 +536,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com total.setText(getString(R.string.result) + ": " + insulinText + " " + carbsText); okButton.setVisibility(View.VISIBLE); } else { + // TODO this should also be run when loading the dialog as the OK button is initially visible + // but does nothing if neither carbs nor insulin is > 0 total.setText(getString(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g"); okButton.setVisibility(View.INVISIBLE); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index d871bd4c40..363918a9b9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -127,9 +127,6 @@ import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; -//Added By Rumen for staledata alarm -import info.nightscout.androidaps.plugins.Overview.Notification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); @@ -637,12 +634,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, void onClickQuickwizard() { final BgReading actualBg = DatabaseHelper.actualBg(); final Profile profile = MainApp.getConfigBuilder().getProfile(); + final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive(); if (quickWizardEntry != null && actualBg != null) { quickWizardButton.setVisibility(View.VISIBLE); BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false); + wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false); final JSONObject boluscalcJSON = new JSONObject(); try { @@ -976,7 +974,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // temp target - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); + TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); if (tempTarget != null) { tempTargetView.setTextColor(Color.BLACK); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); @@ -1117,7 +1115,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, quickWizardButton.setVisibility(View.VISIBLE); String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false); + wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false); text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U"; quickWizardButton.setText(text); if (wizard.calculatedTotalInsulin <= 0) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 0f5a6c582e..c7962cabc2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -272,7 +272,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public TemporaryBasal getRealTempBasalFromHistory(long time) { - return (TemporaryBasal) tempBasals.getValueByInterval(time); + return tempBasals.getValueByInterval(time); } @Override @@ -358,7 +358,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public ExtendedBolus getExtendedBolusFromHistory(long time) { - return (ExtendedBolus) extendedBoluses.getValueByInterval(time); + return extendedBoluses.getValueByInterval(time); } @Override @@ -464,10 +464,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { initializeTempTargetData(); } + @Nullable + @Override + public TempTarget getTempTargetFromHistory() { + return tempTargets.getValueByInterval(System.currentTimeMillis()); + } + @Nullable @Override public TempTarget getTempTargetFromHistory(long time) { - return (TempTarget) tempTargets.getValueByInterval(time); + return tempTargets.getValueByInterval(time); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index e60e30d158..07d41a0d8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -202,9 +202,10 @@ public class ActionStringHandler { sendError("No recent BG to base calculation on!"); return; } + DecimalFormat format = new DecimalFormat("0.00"); BolusWizard bolusWizard = new BolusWizard(); - bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false); + bolusWizard.doCalc(profile, null, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false); Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin); if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) { @@ -470,7 +471,7 @@ public class ActionStringHandler { } //Check for Temp-Target: - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); + TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); if (tempTarget != null) { ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits()); ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd()); diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index f4eb4907ef..984454005c 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -1,12 +1,11 @@ package info.nightscout.utils; -import java.util.Date; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; -import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.TempTarget; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; /** * Created by mike on 11.10.2016. @@ -15,6 +14,7 @@ import info.nightscout.androidaps.data.Profile; public class BolusWizard { // Inputs Profile specificProfile = null; + TempTarget tempTarget; public Integer carbs = 0; Double bg = 0d; Double correction; @@ -33,9 +33,6 @@ public class BolusWizard { public Double targetBGHigh = 0d; public Double bgDiff = 0d; - IobTotal bolusIob; - IobTotal basalIob; - public Double insulinFromBG = 0d; public Double insulinFromCarbs = 0d; public Double insulingFromBolusIOB = 0d; @@ -50,23 +47,29 @@ public class BolusWizard { public Double totalBeforePercentageAdjustment = 0d; public Double carbsEquivalent = 0d; - public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { - return doCalc(specificProfile, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend); + public Double doCalc(Profile specificProfile, TempTarget tempTarget, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { + return doCalc(specificProfile, tempTarget, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend); } - public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { + public Double doCalc(Profile specificProfile, TempTarget tempTarget, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { this.specificProfile = specificProfile; + this.tempTarget = tempTarget; this.carbs = carbs; this.bg = bg; this.correction = correction; + this.includeBolusIOB = includeBolusIOB; + this.includeBasalIOB = includeBasalIOB; this.superBolus = superBolus; this.trend = trend; - // Insulin from BG sens = specificProfile.getIsf(); targetBGLow = specificProfile.getTargetLow(); targetBGHigh = specificProfile.getTargetHigh(); + if (tempTarget != null) { + targetBGLow = tempTarget.low; + targetBGHigh = tempTarget.high; + } if (bg <= targetBGLow) { bgDiff = bg - targetBGLow; } else { @@ -108,13 +111,13 @@ public class BolusWizard { } // Total - calculatedTotalInsulin = totalBeforePercentageAdjustment = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; - - //percentage - if(totalBeforePercentageAdjustment > 0){ - calculatedTotalInsulin = totalBeforePercentageAdjustment*percentageCorrection/100d; - } + calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; + // Percentage adjustment + totalBeforePercentageAdjustment = calculatedTotalInsulin; + if (calculatedTotalInsulin > 0) { + calculatedTotalInsulin = calculatedTotalInsulin * percentageCorrection / 100d; + } if (calculatedTotalInsulin < 0) { carbsEquivalent = -calculatedTotalInsulin * ic; diff --git a/app/src/main/res/layout/overview_wizard_dialog.xml b/app/src/main/res/layout/overview_wizard_dialog.xml index c7b764faba..a8aa4bdd4f 100644 --- a/app/src/main/res/layout/overview_wizard_dialog.xml +++ b/app/src/main/res/layout/overview_wizard_dialog.xml @@ -225,15 +225,29 @@ + + + + @@ -269,7 +283,7 @@ android:id="@+id/treatments_wizard_bgtrend" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -306,7 +320,7 @@ android:id="@+id/treatments_wizard_cob" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -412,7 +426,7 @@ android:id="@+id/treatments_wizard_carbs" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -446,7 +460,7 @@ android:id="@+id/treatments_wizard_sb" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -480,7 +494,7 @@ android:id="@+id/treatments_wizard_correction" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> Insulin Carbs BG + TT Carbs Corr U @@ -701,5 +702,11 @@ ACTIVATE PROFILE Date INVALID + wizard_include_bg + wizard_include_tt + wizard_include_cob + wizard_include_trend_bg + wizard_include_bolus_iob + wizard_include_basal_iob From 627cb8e9b2bfec42b7ac61595fc19adffd564afe Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Sep 2017 16:37:08 +0200 Subject: [PATCH 15/40] WizardDialog: don't persist state of tt checkbox, default to false. This assumes that a default is not useful, as it needs to be decided whether this is needed on each case (using tt when bolusing to start eating soon, but not using it when bolusing for the meal at the end of a tt). --- .../androidaps/plugins/Overview/Dialogs/WizardDialog.java | 2 -- app/src/main/res/layout/overview_wizard_dialog.xml | 2 +- app/src/main/res/values/strings.xml | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index bbfc688252..4b81737a0e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -266,7 +266,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com private void saveCheckedStates() { SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); - SP.putBoolean(getString(R.string.key_wizard_include_tt), ttCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); @@ -275,7 +274,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com private void loadCheckedStates() { bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); - ttCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_tt), false)); bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false)); cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false)); bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); diff --git a/app/src/main/res/layout/overview_wizard_dialog.xml b/app/src/main/res/layout/overview_wizard_dialog.xml index a8aa4bdd4f..faaae6967d 100644 --- a/app/src/main/res/layout/overview_wizard_dialog.xml +++ b/app/src/main/res/layout/overview_wizard_dialog.xml @@ -234,7 +234,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="32dp" - android:checked="true" /> + android:checked="false" /> Date INVALID wizard_include_bg - wizard_include_tt wizard_include_cob wizard_include_trend_bg wizard_include_bolus_iob From c50fad81bbaba1706e2a8b414b512560c4052fd3 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 20 Aug 2017 11:17:05 +0200 Subject: [PATCH 16/40] Log exceptions in catch blocks rather than printing to console. The default code used by Android Studio when generating a try/catch can be altered in Settings under Editor->File and Code Templates->Catch Statement body to log.error("Unhandled exception", e); to also do this for newly generated code. (cherry picked from commit c2ae29f) (cherry picked from commit 6031a25) --- .../nightscout/androidaps/MainActivity.java | 2 +- .../Services/AlarmSoundService.java | 4 +- .../androidaps/Services/DataService.java | 18 ++-- .../nightscout/androidaps/data/IobTotal.java | 8 +- .../nightscout/androidaps/data/Profile.java | 12 +-- .../androidaps/data/ProfileStore.java | 8 +- .../androidaps/data/PumpEnactResult.java | 6 +- .../androidaps/db/CareportalEvent.java | 8 +- .../androidaps/db/DatabaseHelper.java | 100 +++++++++--------- .../nightscout/androidaps/db/DbRequest.java | 4 +- .../androidaps/db/ProfileSwitch.java | 2 +- .../plugins/Actions/dialogs/FillDialog.java | 8 +- .../dialogs/NewExtendedBolusDialog.java | 6 +- .../Actions/dialogs/NewTempBasalDialog.java | 6 +- .../Dialogs/NewNSTreatmentDialog.java | 10 +- .../ConfigBuilder/ConfigBuilderPlugin.java | 4 +- .../ObjectivesPlugin.java | 4 +- .../IobCobCalculator/AutosensResult.java | 5 +- .../androidaps/plugins/Loop/APSResult.java | 6 +- .../androidaps/plugins/Loop/DeviceStatus.java | 2 +- .../plugins/NSClientInternal/UploadQueue.java | 4 +- .../NSClientInternal/acks/NSAddAck.java | 2 +- .../NSClientInternal/acks/NSPingAck.java | 8 +- .../broadcasts/BroadcastStatus.java | 4 +- .../broadcasts/BroadcastTreatment.java | 2 +- .../NSClientInternal/data/NSAlarm.java | 12 ++- .../plugins/NSClientInternal/data/NSCal.java | 2 +- .../NSClientInternal/data/NSDeviceStatus.java | 13 ++- .../plugins/NSClientInternal/data/NSMbg.java | 2 +- .../data/NSSettingsStatus.java | 28 ++--- .../plugins/NSClientInternal/data/NSSgv.java | 10 +- .../NSClientInternal/data/NSTreatment.java | 14 ++- .../receivers/DBAccessReceiver.java | 17 ++- .../services/NSClientService.java | 16 +-- .../DetermineBasalAdapterAMAJS.java | 2 +- .../OpenAPSAMA/DetermineBasalResultAMA.java | 12 ++- .../OpenAPSAMA/OpenAPSAMAFragment.java | 2 +- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 6 +- .../OpenAPSMA/DetermineBasalAdapterMAJS.java | 2 +- .../OpenAPSMA/DetermineBasalResultMA.java | 7 +- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 9 +- .../Overview/Dialogs/BolusProgressDialog.java | 2 +- .../Dialogs/EditQuickWizardDialog.java | 5 +- .../Overview/Dialogs/NewTreatmentDialog.java | 6 +- .../Overview/Dialogs/WizardDialog.java | 2 +- .../plugins/Overview/OverviewFragment.java | 2 +- .../plugins/Overview/OverviewPlugin.java | 5 +- .../plugins/Overview/QuickWizard.java | 19 ++-- .../CircadianPercentageProfilePlugin.java | 2 +- .../ProfileLocal/LocalProfilePlugin.java | 2 +- .../plugins/ProfileNS/NSProfilePlugin.java | 2 +- .../ProfileSimple/SimpleProfilePlugin.java | 2 +- .../plugins/PumpDanaR/DanaRPlugin.java | 2 +- .../plugins/PumpDanaR/DanaRPump.java | 6 +- .../plugins/PumpDanaR/SerialIOThread.java | 6 +- .../activities/DanaRNSHistorySync.java | 2 +- .../services/DanaRExecutionService.java | 6 +- .../PumpDanaRKorean/DanaRKoreanPlugin.java | 2 +- .../PumpDanaRKorean/SerialIOThread.java | 6 +- .../services/DanaRKoreanExecutionService.java | 6 +- .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 2 +- .../plugins/PumpDanaRv2/SerialIOThread.java | 6 +- .../services/DanaRv2ExecutionService.java | 6 +- .../PumpVirtual/VirtualPumpPlugin.java | 2 +- .../androidaps/receivers/NSAlarmReceiver.java | 5 +- .../nightscout/utils/ImportExportPrefs.java | 8 +- .../info/nightscout/utils/JSONFormatter.java | 7 +- .../java/info/nightscout/utils/NSUpload.java | 26 ++--- .../info/nightscout/utils/TimeListEdit.java | 10 +- .../watchfaces/CircleWatchface.java | 2 +- .../androidaps/watchfaces/NOChart.java | 2 +- 71 files changed, 325 insertions(+), 233 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 2cb501b99a..68df307dbf 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -114,7 +114,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe try { // activity may be destroyed setUpTabs(true); } catch (IllegalStateException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } boolean lockScreen = BuildConfig.NSCLIENTOLNY && SP.getBoolean("lockscreen", false); if (lockScreen) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java b/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java index 41587e79b9..60dd92a2c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java @@ -50,7 +50,7 @@ public class AlarmSoundService extends Service { player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); afd.close(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } player.setLooping(true); // Set looping player.setVolume(100, 100); @@ -59,7 +59,7 @@ public class AlarmSoundService extends Service { player.prepare(); player.start(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return START_STICKY; 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 39eb023cb3..05af04230d 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -244,7 +244,7 @@ public class DataService extends IntentService { MainApp.bus().post(new EventDismissNotification(Notification.OLD_NSCLIENT)); } } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (ConfigBuilderPlugin.nightscoutVersionCode < Config.SUPPORTEDNSVERSION) { Notification notification = new Notification(Notification.OLD_NS, MainApp.sResources.getString(R.string.unsupportednsversion), Notification.URGENT); @@ -269,7 +269,7 @@ public class DataService extends IntentService { if (targetlow != null) OverviewPlugin.bgTargetLow = targetlow; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } @@ -298,7 +298,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } // Handle profile @@ -313,7 +313,7 @@ public class DataService extends IntentService { if (Config.logIncommingData) log.debug("Received profileStore: " + activeProfile + " " + profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT)) { @@ -332,7 +332,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -353,7 +353,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -376,7 +376,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -401,7 +401,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -430,7 +430,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java b/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java index bd924d35b5..3240e79327 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java +++ b/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java @@ -2,6 +2,8 @@ package info.nightscout.androidaps.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; @@ -9,6 +11,8 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.Round; public class IobTotal { + private static Logger log = LoggerFactory.getLogger(IobTotal.class); + public double iob; public double activity; public double bolussnooze; @@ -86,7 +90,7 @@ public class IobTotal { json.put("activity", activity); json.put("time", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } @@ -100,7 +104,7 @@ public class IobTotal { json.put("activity", activity); json.put("time", DateUtil.toISOString(new Date(time))); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 984d92c4e5..09885448e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -109,7 +109,7 @@ public class Profile { MainApp.bus().post(new EventDismissNotification(Notification.TARGET_MISSING)); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.invalidprofile)); } } @@ -129,7 +129,7 @@ public class Profile { try { json.put("units", units); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } @@ -156,7 +156,7 @@ public class Profile { Double value = o.getDouble("value"); sparse.put(tas, value); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return sparse; @@ -176,7 +176,7 @@ public class Profile { } lastValue = value; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return lastValue; @@ -215,7 +215,7 @@ public class Profile { if (index + 1 < array.length()) retValue += "\n"; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retValue; @@ -297,7 +297,7 @@ public class Profile { } return ret; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new BasalValue[0]; } diff --git a/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java b/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java index 3e2217454f..f97d8b5e02 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java @@ -50,7 +50,7 @@ public class ProfileStore { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return profile; } @@ -65,7 +65,7 @@ public class ProfileStore { return defaultProfileName; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return defaultProfileName; } @@ -90,7 +90,7 @@ public class ProfileStore { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return profile; } @@ -108,7 +108,7 @@ public class ProfileStore { ret.add(profileName); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ret; diff --git a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java index bfddeff320..7a4a520bee 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java +++ b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java @@ -5,6 +5,8 @@ import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -12,6 +14,8 @@ import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.Round; public class PumpEnactResult extends Object { + private static Logger log = LoggerFactory.getLogger(PumpEnactResult.class); + public boolean success = false; // request was processed successfully (but possible no change was needed) public boolean enacted = false; // request was processed successfully and change has been made public String comment = ""; @@ -101,7 +105,7 @@ public class PumpEnactResult extends Object { result.put("duration", duration); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index f65da51176..b80f4f932e 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -142,7 +142,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { JSONObject object = new JSONObject(json); mbg = object.getDouble("mgdl"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return Profile.fromMgdlToUnits(mbg, units); } @@ -155,7 +155,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { units = object.getString("units"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (glucose != 0d) { double mmol = 0d; @@ -186,7 +186,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { if (object.has("notes")) return object.getString("notes"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return Translator.translate(eventType); } @@ -198,7 +198,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { if (object.has("duration")) return object.getInt("duration") * 60 * 1000L; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 2b4cc87f20..55533aeb4e 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -207,7 +207,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(true); scheduleBgChange(); // trigger refresh @@ -234,7 +234,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, Treatment.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTreatmentChange(); } @@ -244,7 +244,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, TempTarget.class, true); TableUtils.createTableIfNotExists(connectionSource, TempTarget.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTemporaryTargetChange(); } @@ -255,7 +255,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(false); scheduleTemporaryBasalChange(); @@ -267,7 +267,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleExtendedBolusChange(); } @@ -277,7 +277,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, CareportalEvent.class, true); TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleCareportalEventChange(); } @@ -287,7 +287,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleProfileSwitchChange(); } @@ -353,7 +353,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -430,7 +430,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { bgReadings = daoBgreadings.query(preparedQuery); return bgReadings; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -441,7 +441,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoDbRequest().create(dbr); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -449,7 +449,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { return getDaoDbRequest().delete(dbr); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -458,7 +458,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { return getDaoDbRequest().deleteById(nsClientId); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -478,7 +478,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return delete(dbList.get(0)); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -487,7 +487,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { TableUtils.clearTable(connectionSource, DbRequest.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -495,7 +495,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { return getDaoDbRequest().closeableIterator(); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return null; } } @@ -583,7 +583,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -593,7 +593,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTreatments().delete(treatment); updateEarliestDataChange(treatment.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTreatmentChange(); } @@ -603,7 +603,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTreatments().update(treatment); updateEarliestDataChange(treatment.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTreatmentChange(); } @@ -636,7 +636,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return trList.get(0); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -685,7 +685,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { treatments = daoTreatments.query(preparedQuery); return treatments; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -715,7 +715,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } createOrUpdate(treatment); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -733,7 +733,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { tempTargets = daoTempTargets.query(preparedQuery); return tempTargets; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -787,7 +787,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -797,7 +797,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTempTargets().delete(tempTarget); scheduleTemporaryTargetChange(); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -847,7 +847,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { tempTarget.source = Source.NIGHTSCOUT; createOrUpdate(tempTarget); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -874,7 +874,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -885,7 +885,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoDanaRHistory().createOrUpdate(record); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -900,7 +900,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { PreparedQuery preparedQuery = queryBuilder.prepare(); historyList = getDaoDanaRHistory().query(preparedQuery); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); historyList = new ArrayList<>(); } return historyList; @@ -927,7 +927,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } } catch (SQLException | JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1013,7 +1013,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -1023,7 +1023,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTemporaryBasal().delete(tempBasal); updateEarliestDataChange(tempBasal.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTemporaryBasalChange(); } @@ -1039,7 +1039,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { tempbasals = getDaoTemporaryBasal().query(preparedQuery); return tempbasals; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1132,7 +1132,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { createOrUpdate(tempBasal); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1161,7 +1161,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return list.get(0); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -1242,7 +1242,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -1252,7 +1252,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoExtendedBolus().delete(extendedBolus); updateEarliestDataChange(extendedBolus.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleExtendedBolusChange(); } @@ -1268,7 +1268,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { extendedBoluses = getDaoExtendedBolus().query(preparedQuery); return extendedBoluses; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1298,7 +1298,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -1349,7 +1349,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { extendedBolus._id = trJson.getString("_id"); createOrUpdate(extendedBolus); } catch (SQLException | JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1383,7 +1383,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoCareportalEvents().createOrUpdate(careportalEvent); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleCareportalEventChange(); } @@ -1392,7 +1392,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoCareportalEvents().delete(careportalEvent); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleCareportalEventChange(); } @@ -1413,7 +1413,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { else return null; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -1429,7 +1429,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { careportalEvents = getDaoCareportalEvents().query(preparedQuery); return careportalEvents; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1453,7 +1453,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.debug("CareportalEvent not found database: " + _id); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1486,7 +1486,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { careportalEvent._id = trJson.getString("_id"); createOrUpdate(careportalEvent); } catch (SQLException | JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1521,7 +1521,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { profileSwitches = daoProfileSwitch.query(preparedQuery); return profileSwitches; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1575,7 +1575,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -1585,7 +1585,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoProfileSwitch().delete(profileSwitch); scheduleProfileSwitchChange(); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1640,7 +1640,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { profileSwitch.profilePlugin = trJson.getString("profilePlugin"); createOrUpdate(profileSwitch); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1667,7 +1667,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java b/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java index 203436661c..fcda5c9c04 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java @@ -77,7 +77,7 @@ public class DbRequest { if (_id != null) object.put("_id", _id); if (nsClientID != null) object.put("nsClientID", nsClientID); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return object; } @@ -96,7 +96,7 @@ public class DbRequest { if (jsonObject.has("nsClientID")) result.nsClientID = jsonObject.getString("nsClientID"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index fb99934382..cd5efc7465 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -60,7 +60,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { try { profile = new Profile(new JSONObject(profileJson)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return profile; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index 8a4d4001cb..f434a08d96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -21,6 +21,9 @@ import android.widget.TextView; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import info.nightscout.androidaps.Constants; @@ -37,6 +40,7 @@ import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; public class FillDialog extends DialogFragment implements OnClickListener { + private static Logger log = LoggerFactory.getLogger(FillDialog.class); Button deliverButton; TextView insulin; @@ -183,8 +187,8 @@ public class FillDialog extends DialogFragment implements OnClickListener { builder.setNegativeButton(getString(R.string.cancel), null); builder.show(); dismiss(); - } catch (Exception e) { - e.printStackTrace(); + } catch (RuntimeException e) { + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java index c85d5c4540..1bfab76993 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java @@ -17,6 +17,9 @@ import android.widget.RadioButton; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import info.nightscout.androidaps.Constants; @@ -28,6 +31,7 @@ import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewExtendedBolusDialog extends DialogFragment implements View.OnClickListener { + private static Logger log = LoggerFactory.getLogger(NewExtendedBolusDialog.class); PlusMinusEditText editInsulin; PlusMinusEditText editDuration; @@ -115,7 +119,7 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli dismiss(); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } break; case R.id.cancel: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index 9582dced87..9bd6cd26c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -19,6 +19,9 @@ import android.widget.RelativeLayout; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import info.nightscout.androidaps.MainApp; @@ -32,6 +35,7 @@ import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener { + private static Logger log = LoggerFactory.getLogger(NewTempBasalDialog.class); RadioButton percentRadio; RadioButton absoluteRadio; @@ -180,7 +184,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi dismiss(); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } break; case R.id.cancel: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index b10ab5dab8..cc337d6c00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -482,7 +482,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(editSplit.getText())) / 100 / SafeParse.stringToDouble(editDuration.getText()) * 60); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return data; } @@ -577,7 +577,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick ret += "\n"; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ret; @@ -596,7 +596,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick try { doProfileSwitch(profileStore, data.getString("profile"), data.getInt("duration")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } else if (options.executeTempTarget) { @@ -623,13 +623,13 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick NSUpload.uploadCareportalEntryToNS(data); Answers.getInstance().logCustom(new CustomEvent("TempTarget")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } else { NSUpload.uploadCareportalEntryToNS(data); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 6bc0e1e807..aa603286f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -185,7 +185,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain if (SP.contains(settingVisible)) p.setFragmentVisible(type, SP.getBoolean(settingVisible, true) && SP.getBoolean(settingEnabled, true)); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } @@ -989,7 +989,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain MainApp.bus().post(new EventNewNotification(notarget)); return new Profile(new JSONObject("{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"6\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"8\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}}")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index e04efb70cb..81e0493746 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -227,7 +227,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { o.started = new Date(SP.getLong("Objectives" + num + "started", 0L)); o.accomplished = new Date(SP.getLong("Objectives" + num + "accomplished", 0L)); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } bgIsAvailableInNS = SP.getBoolean("Objectives" + "bgIsAvailableInNS", false); @@ -235,7 +235,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { try { manualEnacts = SP.getInt("Objectives" + "manualEnacts", 0); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (Config.logPrefsChange) log.debug("Objectives loaded"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java index 1e40005b36..4e0f8ef107 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java @@ -2,11 +2,14 @@ package info.nightscout.androidaps.plugins.IobCobCalculator; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Created by mike on 06.01.2017. */ public class AutosensResult { + private static Logger log = LoggerFactory.getLogger(AutosensResult.class); //default values to show when autosens algorithm is not called public double ratio = 1d; @@ -24,7 +27,7 @@ public class AutosensResult { ret.put("sensResult", sensResult); ret.put("ratio", ratio); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ret; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java index 69e161524f..a1a3d9c904 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java @@ -7,6 +7,8 @@ import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -17,6 +19,8 @@ import info.nightscout.utils.DecimalFormatter; * Created by mike on 09.06.2016. */ public class APSResult { + private static Logger log = LoggerFactory.getLogger(APSResult.class); + public String reason; public double rate; public int duration; @@ -72,7 +76,7 @@ public class APSResult { json.put("reason", reason); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java index 3080717773..acf59865d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java @@ -397,7 +397,7 @@ public class DeviceStatus { if (uploaderBattery != 0) record.put("uploaderBattery", uploaderBattery); if (created_at != null) record.put("created_at" , created_at); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return record; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java index 76a2855478..6e1c02db4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java @@ -90,7 +90,7 @@ public class UploadQueue { log.debug("Removed item from UploadQueue. " + UploadQueue.status()); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }); @@ -126,7 +126,7 @@ public class UploadQueue { iterator.close(); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java index b4ba0c3364..709c53f6d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java @@ -49,7 +49,7 @@ public class NSAddAck implements Ack { } return; } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java index 2824e922aa..1ec6e3991c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java @@ -1,7 +1,11 @@ package info.nightscout.androidaps.plugins.NSClientInternal.acks; +import android.os.SystemClock; + import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.socket.client.Ack; @@ -9,6 +13,8 @@ import io.socket.client.Ack; * Created by mike on 29.12.2015. */ public class NSPingAck implements Ack { + private static Logger log = LoggerFactory.getLogger(NSPingAck.class); + public long mills = 0; public boolean received = false; public boolean auth_received = false; @@ -27,7 +33,7 @@ public class NSPingAck implements Ack { write = authorization.optBoolean("write"); write_treatment = authorization.optBoolean("write_treatment"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } received = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java index 7c6862cb14..4ee2427af8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java @@ -32,7 +32,7 @@ public class BroadcastStatus { bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); bundle.putInt("nsclientversioncode", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode); } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("nightscoutversionname", NSClientService.nightscoutVersionName); bundle.putInt("nightscoutversioncode", NSClientService.nightscoutVersionCode); @@ -49,7 +49,7 @@ public class BroadcastStatus { bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); bundle.putInt("nsclientversioncode", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode); } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("nightscoutversionname", NSClientService.nightscoutVersionName); bundle.putInt("nightscoutversioncode", NSClientService.nightscoutVersionCode); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 99644c7ba3..572cf7e055 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -192,7 +192,7 @@ public class BroadcastTreatment { ret.add(newarr); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); ret = new ArrayList<>(); ret.add(array); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java index f7a7f79303..1c28b790d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java @@ -2,12 +2,16 @@ package info.nightscout.androidaps.plugins.NSClientInternal.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Created by mike on 11.06.2017. */ public class NSAlarm { + private static Logger log = LoggerFactory.getLogger(NSAlarm.class); + JSONObject data; public NSAlarm(JSONObject data) { @@ -20,7 +24,7 @@ public class NSAlarm { try { retval = data.getInt("level"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; @@ -32,7 +36,7 @@ public class NSAlarm { try { retval = data.getString("group"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; @@ -44,7 +48,7 @@ public class NSAlarm { try { retval = data.getString("title"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; @@ -56,7 +60,7 @@ public class NSAlarm { try { retval = data.getString("message"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java index 74b5f688d9..93d46fa18e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java @@ -19,7 +19,7 @@ public class NSCal { intercept = json.getDouble("intercept"); scale = json.getDouble("scale"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); log.debug("Data: " + json.toString()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java index 8ce3fc87e2..2a2e1b8044 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java @@ -5,6 +5,8 @@ import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; @@ -70,6 +72,7 @@ import info.nightscout.utils.SP; } */ public class NSDeviceStatus { + private static Logger log = LoggerFactory.getLogger(NSDeviceStatus.class); private static NSDeviceStatus instance = null; @@ -102,7 +105,7 @@ public class NSDeviceStatus { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ""; } @@ -237,7 +240,7 @@ public class NSDeviceStatus { deviceStatusPumpData.extended = Html.fromHtml(exteneded.toString()); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -278,7 +281,7 @@ public class NSDeviceStatus { deviceStatusOpenAPSData.clockEnacted = clock; } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -315,7 +318,7 @@ public class NSDeviceStatus { string.append("").append(DateUtil.minAgo(deviceStatusOpenAPSData.clockSuggested)).append(" ").append(deviceStatusOpenAPSData.suggested.getString("reason")).append("
"); return Html.fromHtml(string.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return Html.fromHtml(""); } @@ -353,7 +356,7 @@ public class NSDeviceStatus { uploaders.put(device, uploader); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java index 79fa60c3bb..353dd49b74 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java @@ -17,7 +17,7 @@ public class NSMbg { mbg = json.getDouble("mgdl"); this.json = json.toString(); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); log.debug("Data: " + json.toString()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java index c2c3aa036f..3feced94cd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java @@ -4,6 +4,8 @@ import android.support.annotation.Nullable; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; import java.util.Objects; @@ -99,6 +101,8 @@ import java.util.Objects; } */ public class NSSettingsStatus { + private static Logger log = LoggerFactory.getLogger(NSSettingsStatus.class); + private static NSSettingsStatus instance = null; public static NSSettingsStatus getInstance() { @@ -160,7 +164,7 @@ public class NSSettingsStatus { return new JSONObject(extended); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; @@ -195,7 +199,7 @@ public class NSSettingsStatus { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -207,7 +211,7 @@ public class NSSettingsStatus { try { ret = data.getString(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -219,7 +223,7 @@ public class NSSettingsStatus { try { ret = data.getInt(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -231,7 +235,7 @@ public class NSSettingsStatus { try { ret = data.getLong(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -243,7 +247,7 @@ public class NSSettingsStatus { try { ret = new Date(data.getString(key)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -255,7 +259,7 @@ public class NSSettingsStatus { try { ret = data.getBoolean(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -301,7 +305,7 @@ public class NSSettingsStatus { return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0d; } @@ -317,7 +321,7 @@ public class NSSettingsStatus { return pump; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -329,7 +333,7 @@ public class NSSettingsStatus { return pump.getBoolean("enableAlerts"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -341,7 +345,7 @@ public class NSSettingsStatus { return pump.getString("fields"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ""; } @@ -353,7 +357,7 @@ public class NSSettingsStatus { return pump.getBoolean("enableAlerts"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java index 78ddc7a8f7..af134ea50d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java @@ -2,12 +2,16 @@ package info.nightscout.androidaps.plugins.NSClientInternal.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * * {"mgdl":105,"mills":1455136282375,"device":"xDrip-BluetoothWixel","direction":"Flat","filtered":98272,"unfiltered":98272,"noise":1,"rssi":100} */ public class NSSgv { + private static Logger log = LoggerFactory.getLogger(NSSgv.class); + private JSONObject data; public NSSgv(JSONObject obj) { @@ -20,7 +24,7 @@ public class NSSgv { try { ret = data.getString(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -32,7 +36,7 @@ public class NSSgv { try { ret = data.getInt(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -44,7 +48,7 @@ public class NSSgv { try { ret = data.getLong(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java index 1b48f27e2f..a9f960edd0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java @@ -2,10 +2,14 @@ package info.nightscout.androidaps.plugins.NSClientInternal.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; public class NSTreatment { + private static Logger log = LoggerFactory.getLogger(NSTreatment.class); + private JSONObject data; private String action = null; // "update", "remove" or null (add) @@ -21,7 +25,7 @@ public class NSTreatment { try { ret = data.getString(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -33,7 +37,7 @@ public class NSTreatment { try { ret = data.getDouble(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -45,7 +49,7 @@ public class NSTreatment { try { ret = data.getInt(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -57,7 +61,7 @@ public class NSTreatment { try { ret = data.getLong(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -69,7 +73,7 @@ public class NSTreatment { try { ret = new Date(data.getString(key)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java index 3546a1d5e0..a9f3509213 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java @@ -50,9 +50,18 @@ public class DBAccessReceiver extends BroadcastReceiver { String _id = null; JSONObject data = null; String action = bundles.getString("action"); - try { collection = bundles.getString("collection"); } catch (Exception e) {} - try { _id = bundles.getString("_id"); } catch (Exception e) {} - try { data = new JSONObject(bundles.getString("data")); } catch (Exception e) {} + try { + collection = bundles.getString("collection"); + } catch (Exception e) { + } + try { + _id = bundles.getString("_id"); + } catch (Exception e) { + } + try { + data = new JSONObject(bundles.getString("data")); + } catch (Exception e) { + } if (data == null && !action.equals("dbRemove") || _id == null && action.equals("dbRemove")) { log.debug("DBACCESS no data inside record"); @@ -67,7 +76,7 @@ public class DBAccessReceiver extends BroadcastReceiver { try { data.put("NSCLIENT_ID", nsclientid); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (!isAllowedCollection(collection)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index d171f87fc8..465d5e42c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -258,7 +258,7 @@ public class NSClientService extends Service { authMessage.put("from", latestDateInReceivedData); // send data newer than authMessage.put("secret", nsAPIhashCode); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return; } MainApp.bus().post(new EventNSClientNewLog("AUTH", "requesting auth")); @@ -326,7 +326,7 @@ public class NSClientService extends Service { try { MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", data.has("message") ? data.getString("message") : "received")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } BroadcastAnnouncement.handleAnnouncement(data, getApplicationContext()); log.debug(data.toString()); @@ -561,7 +561,7 @@ public class NSClientService extends Service { } MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData))); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } //MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end"); } finally { @@ -583,7 +583,7 @@ public class NSClientService extends Service { mSocket.emit("dbUpdate", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBUPDATE " + dbr.collection, "Sent " + dbr._id)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -597,7 +597,7 @@ public class NSClientService extends Service { mSocket.emit("dbUpdateUnset", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBUPDATEUNSET " + dbr.collection, "Sent " + dbr._id)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -610,7 +610,7 @@ public class NSClientService extends Service { mSocket.emit("dbRemove", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBREMOVE " + dbr.collection, "Sent " + dbr._id)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -633,7 +633,7 @@ public class NSClientService extends Service { mSocket.emit("dbAdd", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBADD " + dbr.collection, "Sent " + dbr.nsClientID)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -709,7 +709,7 @@ public class NSClientService extends Service { iterator.close(); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 7833dbf54e..44ab8ecb14 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -103,7 +103,7 @@ public class DetermineBasalAdapterAMAJS { try { result = new DetermineBasalResultAMA(v8ObjectReuslt, new JSONObject(ret)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java index c2a55ff894..31501b7032 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java @@ -5,6 +5,8 @@ import com.eclipsesource.v8.V8Object; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Date; @@ -15,6 +17,8 @@ import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.data.IobTotal; public class DetermineBasalResultAMA extends APSResult { + private static Logger log = LoggerFactory.getLogger(DetermineBasalResultAMA.class); + public Date date; public JSONObject json = new JSONObject(); public double eventualBG; @@ -69,7 +73,7 @@ public class DetermineBasalResultAMA extends APSResult { try { newResult.json = new JSONObject(json.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } newResult.eventualBG = eventualBG; newResult.snoozeBG = snoozeBG; @@ -83,7 +87,7 @@ public class DetermineBasalResultAMA extends APSResult { JSONObject ret = new JSONObject(this.json.toString()); return ret; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -126,7 +130,7 @@ public class DetermineBasalResultAMA extends APSResult { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return array; } @@ -151,7 +155,7 @@ public class DetermineBasalResultAMA extends APSResult { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return latest; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java index 419a55f057..c0d0662747 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java @@ -112,7 +112,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam()); iobDataView.setText(String.format(MainApp.sResources.getString(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); iobDataView.setText("JSONException"); } profileView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getProfileParam())); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index 53bcfcf1ec..28bc0f9e4e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -160,8 +160,8 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { double maxIob = SP.getDouble("openapsma_max_iob", 1.5d); double maxBasal = SP.getDouble("openapsma_max_basal", 1d); - double minBg = Profile.toMgdl(profile.getTargetLow(), units); - double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); + double minBg = Profile.toMgdl(profile.getTargetLow(), units); + double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); double targetBg = (minBg + maxBg) / 2; minBg = Round.roundTo(minBg, 0.1d); @@ -242,7 +242,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { try { determineBasalResultAMA.json.put("timestamp", DateUtil.toISOString(now)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index a03ef9731b..a8f797f8c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -135,7 +135,7 @@ public class DetermineBasalAdapterMAJS { try { result = new DetermineBasalResultMA(v8ObjectReuslt, new JSONObject(ret)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } storedGlucoseStatus = mV8rt.executeStringScript("JSON.stringify(" + PARAM_glucoseStatus + ");"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java index a0cd1a75b0..23f7c14a88 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java @@ -7,11 +7,14 @@ import com.eclipsesource.v8.V8Object; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.plugins.Loop.APSResult; public class DetermineBasalResultMA extends APSResult { + private static Logger log = LoggerFactory.getLogger(DetermineBasalResultMA.class); public JSONObject json = new JSONObject(); public double eventualBG; @@ -70,7 +73,7 @@ public class DetermineBasalResultMA extends APSResult { try { newResult.json = new JSONObject(json.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } newResult.eventualBG = eventualBG; newResult.snoozeBG = snoozeBG; @@ -84,7 +87,7 @@ public class DetermineBasalResultMA extends APSResult { JSONObject ret = new JSONObject(this.json.toString()); return ret; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 95f1235161..a5c2276a2e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -160,8 +160,8 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { double maxIob = SP.getDouble("openapsma_max_iob", 1.5d); double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1")); - double minBg = Profile.toMgdl(profile.getTargetLow(), units); - double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); + double minBg = Profile.toMgdl(profile.getTargetLow(), units); + double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); double targetBg = (minBg + maxBg) / 2; minBg = Round.roundTo(minBg, 0.1d); @@ -196,7 +196,8 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return; if (!checkOnlyHardLimits(profile.getIc(), "carbratio", 2, 100)) return; - if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900)) return; + if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900)) + return; if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; @@ -224,7 +225,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { try { determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index f536af5860..0977cf3b9a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -171,7 +171,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL try { dismiss(); } catch (Exception e) { - e.printStackTrace(); // TODO: do this better way + log.error("Unhandled exception", e); } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java index 1179841098..95bcea7908 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java @@ -14,6 +14,8 @@ import android.widget.EditText; import android.widget.Spinner; import org.json.JSONException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -27,6 +29,7 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.SafeParse; public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener { + private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class); QuickWizard.QuickWizardEntry entry = new QuickWizard().newEmptyItem(); QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard; @@ -104,7 +107,7 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic int validToInt = DateUtil.toSeconds(toSpinner.getSelectedItem().toString()); entry.storage.put("validTo", validToInt); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } quickWizard.addOrUpdate(entry); dismiss(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index e2edb1e76a..ccc2d277bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -19,6 +19,9 @@ import android.widget.TextView; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import java.util.Objects; @@ -35,6 +38,7 @@ import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewTreatmentDialog extends DialogFragment implements OnClickListener { + private static Logger log = LoggerFactory.getLogger(NewTreatmentDialog.class); NumberPicker editCarbs; NumberPicker editInsulin; @@ -130,7 +134,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene builder.show(); dismiss(); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } break; case R.id.cancel: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index bda03a8a27..a4b6310c8d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -550,7 +550,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com boluscalcJSON.put("insulintrend", wizard.insulinFromTrend); boluscalcJSON.put("insulin", calculatedTotalInsulin); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index d871bd4c40..ac5a57d963 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -664,7 +664,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, boluscalcJSON.put("insulintrend", wizard.insulinFromTrend); boluscalcJSON.put("insulin", wizard.calculatedTotalInsulin); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (wizard.calculatedTotalInsulin > 0d && quickWizardEntry.carbs() > 0d) { DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java index 30148f94c2..bb89a70fdf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java @@ -4,6 +4,8 @@ import com.squareup.otto.Subscribe; import org.json.JSONArray; import org.json.JSONException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -17,6 +19,7 @@ import info.nightscout.utils.SP; * Created by mike on 05.08.2016. */ public class OverviewPlugin implements PluginBase { + private static Logger log = LoggerFactory.getLogger(OverviewPlugin.class); public static double bgTargetLow = 80d; public static double bgTargetHigh = 180d; @@ -30,7 +33,7 @@ public class OverviewPlugin implements PluginBase { try { quickWizard.setData(new JSONArray(storedData)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } MainApp.bus().register(this); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java index 63ad14ab6b..2962575a68 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java @@ -6,6 +6,8 @@ import android.preference.PreferenceManager; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; @@ -18,6 +20,7 @@ import info.nightscout.utils.DateUtil; */ public class QuickWizard { + private static Logger log = LoggerFactory.getLogger(QuickWizard.class); public class QuickWizardEntry { public JSONObject storage; @@ -36,7 +39,7 @@ public class QuickWizard { try { storage = new JSONObject(emptyData); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } position = -1; } @@ -54,7 +57,7 @@ public class QuickWizard { try { return storage.getString("buttonText"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ""; } @@ -63,7 +66,7 @@ public class QuickWizard { try { return storage.getInt("carbs"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -80,7 +83,7 @@ public class QuickWizard { try { return storage.getInt("validFrom"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -89,7 +92,7 @@ public class QuickWizard { try { return storage.getInt("validTo"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -117,7 +120,7 @@ public class QuickWizard { try { return new QuickWizardEntry((JSONObject) storage.get(position), position); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -127,7 +130,7 @@ public class QuickWizard { try { if (new QuickWizardEntry((JSONObject) storage.get(i), i).isActive()) return true; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return false; @@ -157,7 +160,7 @@ public class QuickWizard { try { storage.put(newItem.position, newItem.storage); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } save(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java index 768cdf90e7..6158a00978 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java @@ -253,7 +253,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); store.put(profileName, profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } convertedProfile = new ProfileStore(json); convertedProfileName = profileName; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java index 8aca0a8dbc..51d231edeb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java @@ -229,7 +229,7 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface { profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); store.put("LocalProfile", profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } convertedProfile = new ProfileStore(json); convertedProfileName = "LocalProfile"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java index 758521d5a8..cb9a189ff7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java @@ -134,7 +134,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface { try { profile = new ProfileStore(new JSONObject(profileString)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); profile = null; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java index e02f4918c2..687f45ee97 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java @@ -191,7 +191,7 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface { profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); store.put("SimpleProfile", profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } convertedProfile = new ProfileStore(json); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 96871ac128..9b85807cd1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -703,7 +703,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); pumpjson.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pumpjson; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java index 55fdc7ad04..7948d00d96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.PumpDanaR; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.text.DecimalFormat; import java.util.Date; @@ -16,6 +18,8 @@ import info.nightscout.utils.SP; * Created by mike on 04.07.2016. */ public class DanaRPump { + private static Logger log = LoggerFactory.getLogger(DanaRPump.class); + private static DanaRPump instance = null; public static DanaRPump getInstance() { @@ -189,7 +193,7 @@ public class DanaRPump { profile.put("units", units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL); store.put(PROFILE_PREFIX + (activeProfile + 1), profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } catch (Exception e) { return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java index 461b353c3e..9cac697486 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java @@ -44,7 +44,7 @@ public class SerialIOThread extends Thread { mOutputStream = mRfCommSocket.getOutputStream(); mInputStream = mRfCommSocket.getInputStream(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } this.start(); } @@ -158,7 +158,7 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - e.printStackTrace(); + log.error("Unhandled exception", e); } synchronized (message) { @@ -166,7 +166,7 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java index 0668a74c1d..e7813fac10 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java @@ -220,7 +220,7 @@ public class DanaRNSHistorySync { MainApp.bus().post(ev); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 606eab3794..56d07b1892 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -209,9 +209,9 @@ public class DanaRExecutionService extends Service { try { mRfcommSocket.connect(); } catch (IOException e) { - //e.printStackTrace(); + //log.error("Unhandled exception", e); if (e.getMessage().contains("socket closed")) { - e.printStackTrace(); + log.error("Unhandled exception", e); break; } } @@ -352,7 +352,7 @@ public class DanaRExecutionService extends Service { NSUpload.uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index e912eac0b4..d688010de6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -700,7 +700,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); pumpjson.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pumpjson; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java index 597a49a676..2c1cf901d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java @@ -45,7 +45,7 @@ public class SerialIOThread extends Thread { mOutputStream = mRfCommSocket.getOutputStream(); mInputStream = mRfCommSocket.getInputStream(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } this.start(); } @@ -159,7 +159,7 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - e.printStackTrace(); + log.error("Unhandled exception", e); } synchronized (message) { @@ -167,7 +167,7 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index b7c9f8ca2c..15f8b82c91 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -205,9 +205,9 @@ public class DanaRKoreanExecutionService extends Service { try { mRfcommSocket.connect(); } catch (IOException e) { - //e.printStackTrace(); + //log.error("Unhandled exception", e); if (e.getMessage().contains("socket closed")) { - e.printStackTrace(); + log.error("Unhandled exception", e); break; } } @@ -345,7 +345,7 @@ public class DanaRKoreanExecutionService extends Service { NSUpload.uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 82bbc23e5c..65d3917381 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -632,7 +632,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); pumpjson.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pumpjson; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java index 0b67b6acc6..b5a0b4768e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java @@ -45,7 +45,7 @@ public class SerialIOThread extends Thread { mOutputStream = mRfCommSocket.getOutputStream(); mInputStream = mRfCommSocket.getInputStream(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } this.start(); } @@ -159,7 +159,7 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - e.printStackTrace(); + log.error("Unhandled exception", e); } synchronized (message) { @@ -167,7 +167,7 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 0ac333787a..0a4ebcfac0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -180,9 +180,9 @@ public class DanaRv2ExecutionService extends Service { try { mRfcommSocket.connect(); } catch (IOException e) { - //e.printStackTrace(); + //log.error("Unhandled exception", e); if (e.getMessage().contains("socket closed")) { - e.printStackTrace(); + log.error("Unhandled exception", e); break; } } @@ -325,7 +325,7 @@ public class DanaRv2ExecutionService extends Service { NSUpload.uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index c04ec9b12f..b87b219556 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -415,7 +415,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { pump.put("reservoir", reservoirInUnits); pump.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pump; } diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java index bff2e6695a..c4a9fa89b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java @@ -7,6 +7,8 @@ import android.os.Bundle; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; @@ -16,6 +18,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; public class NSAlarmReceiver extends BroadcastReceiver { + private static Logger log = LoggerFactory.getLogger(NSAlarmReceiver.class); @Override public void onReceive(Context context, Intent intent) { @@ -27,7 +30,7 @@ public class NSAlarmReceiver extends BroadcastReceiver { try { json = new JSONObject(data); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return; } NSAlarm nsAlarm = new NSAlarm(json); diff --git a/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java b/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java index 1e501fbdf0..b8eb49e98e 100644 --- a/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java +++ b/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java @@ -76,9 +76,9 @@ public class ImportExportPrefs { ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.exported)); } catch (FileNotFoundException e) { ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.filenotfound) + " " + file); - e.printStackTrace(); + log.error("Unhandled exception", e); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }) @@ -127,9 +127,9 @@ public class ImportExportPrefs { }); } catch (FileNotFoundException e) { ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.filenotfound) + " " + file); - e.printStackTrace(); + log.error("Unhandled exception", e); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }) diff --git a/app/src/main/java/info/nightscout/utils/JSONFormatter.java b/app/src/main/java/info/nightscout/utils/JSONFormatter.java index a37169f061..499ba01652 100644 --- a/app/src/main/java/info/nightscout/utils/JSONFormatter.java +++ b/app/src/main/java/info/nightscout/utils/JSONFormatter.java @@ -6,6 +6,8 @@ import android.text.Spanned; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Iterator; @@ -13,6 +15,7 @@ import java.util.Iterator; * Created by mike on 11.07.2016. */ public class JSONFormatter { + private static Logger log = LoggerFactory.getLogger(JSONFormatter.class); public static Spanned format(final String jsonString) { final JsonVisitor visitor = new JsonVisitor(4, ' '); @@ -24,7 +27,7 @@ public class JSONFormatter { else return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return Html.fromHtml(""); } } @@ -34,7 +37,7 @@ public class JSONFormatter { try { return Html.fromHtml(visitor.visit(object, 0)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return Html.fromHtml(""); } } diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 09ecbc9370..e6cb358ac1 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -61,7 +61,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -98,7 +98,7 @@ public class NSUpload { DbLogger.dbAdd(intent, data.toString()); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -123,7 +123,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -151,7 +151,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -179,7 +179,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -240,7 +240,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, deviceStatus.mongoRecord().toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -264,7 +264,7 @@ public class NSUpload { if (detailedBolusInfo.carbTime != 0) data.put("preBolus", detailedBolusInfo.carbTime); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } uploadCareportalEntryToNS(data); } @@ -286,7 +286,7 @@ public class NSUpload { data.put("enteredBy", MainApp.instance().getString(R.string.app_name)); uploadCareportalEntryToNS(data); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -315,7 +315,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -333,7 +333,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbRemove(intent, _id); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -356,7 +356,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -372,7 +372,7 @@ public class NSUpload { data.put("notes", error); data.put("isAnnouncement", true); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("data", data.toString()); Intent intent = new Intent(Intents.ACTION_DATABASE); @@ -394,7 +394,7 @@ public class NSUpload { data.put("created_at", DateUtil.toISOString(new Date())); data.put("notes", MainApp.sResources.getString(R.string.androidaps_start)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("data", data.toString()); Intent intent = new Intent(Intents.ACTION_DATABASE); diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/utils/TimeListEdit.java index 2ad591b1ef..8a1fac75a3 100644 --- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/utils/TimeListEdit.java @@ -253,7 +253,7 @@ public class TimeListEdit { return item.getInt("timeAsSeconds"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -265,7 +265,7 @@ public class TimeListEdit { return item.getDouble("value"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0d; } @@ -278,7 +278,7 @@ public class TimeListEdit { return item.getDouble("value"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return 0d; @@ -305,7 +305,7 @@ public class TimeListEdit { } if (save != null) save.run(); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -322,7 +322,7 @@ public class TimeListEdit { editItem(index, timeAsSeconds, value1, value2); if (save != null) save.run(); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java index f9df8eb97e..e7b11400ff 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java @@ -507,7 +507,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh try { Thread.sleep(40); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } setIsAnimated(false); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java index ab283e8656..8e810d86ae 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java @@ -430,7 +430,7 @@ public class NOChart extends WatchFace implements SharedPreferences.OnSharedPref try { Thread.sleep(40); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } mSgv.getPaint().setShader(null); From 5c3ec9a0860079959708a7481d28d9b9f0efa03d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 6 Sep 2017 20:00:36 +0200 Subject: [PATCH 17/40] Use SystemClock.sleep instead of Thread.sleep. Gets rid of all those pointless InterruptedException catching. (cherry picked from commit 6acaa2b) --- .../java/info/nightscout/androidaps/MainApp.java | 6 ++---- .../plugins/NSClientInternal/UploadQueue.java | 6 ++---- .../Overview/Dialogs/BolusProgressDialog.java | 7 ++----- .../plugins/PumpDanaR/SerialIOThread.java | 6 ++---- .../services/DanaRExecutionService.java | 7 ++----- .../plugins/PumpDanaRKorean/SerialIOThread.java | 6 ++---- .../services/DanaRKoreanExecutionService.java | 7 ++----- .../plugins/PumpDanaRv2/SerialIOThread.java | 6 ++---- .../services/DanaRv2ExecutionService.java | 7 ++----- .../plugins/PumpVirtual/VirtualPumpPlugin.java | 16 ++++------------ .../java/info/nightscout/utils/OKDialog.java | 11 +++-------- .../androidaps/data/ListenerService.java | 7 ++----- .../androidaps/watchfaces/BIGChart.java | 7 ++----- .../androidaps/watchfaces/CircleWatchface.java | 7 ++----- .../androidaps/watchfaces/NOChart.java | 7 ++----- 15 files changed, 33 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 18727d87f0..fcd92331b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -4,6 +4,7 @@ import android.app.Application; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; +import android.os.SystemClock; import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; @@ -167,10 +168,7 @@ public class MainApp extends Application { Thread t = new Thread(new Runnable() { @Override public void run() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - } + SystemClock.sleep(5000); PumpInterface pump = MainApp.getConfigBuilder(); if (pump != null) pump.refreshDataFromPump("Initialization"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java index 6e1c02db4c..114ace4c30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.NSClientInternal; import android.content.Context; import android.content.Intent; +import android.os.SystemClock; import com.j256.ormlite.dao.CloseableIterator; @@ -35,10 +36,7 @@ public class UploadQueue { if (NSClientService.handler == null) { Context context = MainApp.instance(); context.startService(new Intent(context, NSClientService.class)); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - } + SystemClock.sleep(2000); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index 0977cf3b9a..de0d73e706 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs; import android.app.Activity; import android.os.Bundle; +import android.os.SystemClock; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; @@ -156,11 +157,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL Thread t = new Thread(new Runnable() { @Override public void run() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(5000); BolusProgressDialog.bolusEnded = true; Activity activity = getActivity(); if (activity != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java index 9cac697486..fabda4e26a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpDanaR; import android.bluetooth.BluetoothSocket; +import android.os.SystemClock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -170,10 +171,7 @@ public class SerialIOThread extends Thread { } } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); if (!message.received) { log.warn("Reply not received " + message.getMessageName()); if (message.getCommand() == 0xF0F1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 56d07b1892..3f91fd659a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -11,6 +11,7 @@ import android.content.IntentFilter; import android.os.Binder; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import com.squareup.otto.Subscribe; @@ -552,10 +553,6 @@ public class DanaRExecutionService extends Service { } private void waitMsec(long msecs) { - try { - Thread.sleep(msecs); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(msecs); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java index 2c1cf901d6..5a8b7fe564 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpDanaRKorean; import android.bluetooth.BluetoothSocket; +import android.os.SystemClock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -171,10 +172,7 @@ public class SerialIOThread extends Thread { } } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); if (!message.received) { log.warn("Reply not received " + message.getMessageName()); if (message.getCommand() == 0xF0F1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index 15f8b82c91..648159f214 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -11,6 +11,7 @@ import android.content.IntentFilter; import android.os.Binder; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import com.squareup.otto.Subscribe; @@ -524,10 +525,6 @@ public class DanaRKoreanExecutionService extends Service { } private void waitMsec(long msecs) { - try { - Thread.sleep(msecs); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(msecs); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java index b5a0b4768e..130657b14d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpDanaRv2; import android.bluetooth.BluetoothSocket; +import android.os.SystemClock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -171,10 +172,7 @@ public class SerialIOThread extends Thread { } } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); if (!message.received) { log.warn("Reply not received " + message.getMessageName()); if (message.getCommand() == 0xF0F1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 0a4ebcfac0..e73c9d65f8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -11,6 +11,7 @@ import android.content.IntentFilter; import android.os.Binder; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import com.squareup.otto.Subscribe; @@ -554,10 +555,6 @@ public class DanaRv2ExecutionService extends Service { } private void waitMsec(long msecs) { - try { - Thread.sleep(msecs); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(msecs); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index b87b219556..3f7e689275 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpVirtual; import android.content.SharedPreferences; +import android.os.SystemClock; import android.preference.PreferenceManager; import org.json.JSONException; @@ -222,28 +223,19 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { Double delivering = 0d; while (delivering < detailedBolusInfo.insulin) { - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivering); bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100); MainApp.bus().post(bolusingEvent); delivering += 0.1d; } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivered), detailedBolusInfo.insulin); bolusingEvent.percent = 100; MainApp.bus().post(bolusingEvent); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } + SystemClock.sleep(1000); if (Config.logPumpComm) log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); diff --git a/app/src/main/java/info/nightscout/utils/OKDialog.java b/app/src/main/java/info/nightscout/utils/OKDialog.java index 72e0ddd8d2..6bd84cbe71 100644 --- a/app/src/main/java/info/nightscout/utils/OKDialog.java +++ b/app/src/main/java/info/nightscout/utils/OKDialog.java @@ -2,6 +2,7 @@ package info.nightscout.utils; import android.app.Activity; import android.content.DialogInterface; +import android.os.SystemClock; import android.support.v7.app.AlertDialog; import android.support.v7.view.ContextThemeWrapper; import android.text.Spanned; @@ -28,10 +29,7 @@ public class OKDialog { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (runnable != null) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } + SystemClock.sleep(100); activity.runOnUiThread(runnable); } } @@ -52,10 +50,7 @@ public class OKDialog { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (runnable != null) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } + SystemClock.sleep(100); activity.runOnUiThread(runnable); } } diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java index 711e6a76f4..af1b2f7bac 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.app.NotificationCompat; @@ -400,11 +401,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp @Override public void run() { - try { - Thread.sleep(seconds * 1000); - } catch (InterruptedException e) { - //e.printStackTrace(); - } + SystemClock.sleep(seconds * 1000); synchronized (this) { if(valid) { NotificationManagerCompat notificationManager = diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java index 510382b20b..25fe619b2a 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java @@ -15,6 +15,7 @@ import android.graphics.Rect; import android.graphics.Shader; import android.os.Bundle; import android.os.PowerManager; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; @@ -473,11 +474,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre setIsAnimated(true); for (int i = 0; i <= 8 * 1000 / 40; i++) { updateRainbow(); - try { - Thread.sleep(40); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(40); } mSgv.getPaint().setShader(null); setIsAnimated(false); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java index e7b11400ff..73930d8365 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java @@ -15,6 +15,7 @@ import android.graphics.RectF; import android.graphics.Shader; import android.os.Bundle; import android.os.PowerManager; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.LocalBroadcastManager; import android.support.wearable.watchface.WatchFaceStyle; @@ -504,11 +505,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh setIsAnimated(true); for (int i = 0; i <= 8 * 1000 / 40; i++) { animationStep(); - try { - Thread.sleep(40); - } catch (InterruptedException e) { - log.error("Unhandled exception", e); - } + SystemClock.sleep(40); } setIsAnimated(false); prepareDrawTime(); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java index 8e810d86ae..9bb452c480 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java @@ -15,6 +15,7 @@ import android.graphics.Rect; import android.graphics.Shader; import android.os.Bundle; import android.os.PowerManager; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; @@ -427,11 +428,7 @@ public class NOChart extends WatchFace implements SharedPreferences.OnSharedPref setIsAnimated(true); for (int i = 0; i <= 8 * 1000 / 40; i++) { updateRainbow(); - try { - Thread.sleep(40); - } catch (InterruptedException e) { - log.error("Unhandled exception", e); - } + SystemClock.sleep(40); } mSgv.getPaint().setShader(null); setIsAnimated(false); From c227e0e5faf4319c164ca19df0114ba70cdc7acd Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Sep 2017 00:53:26 +0200 Subject: [PATCH 18/40] Dead code be gone. (cherry picked from commit bb626ce) --- .../plugins/Overview/Dialogs/BolusProgressDialog.java | 8 -------- .../plugins/PumpDanaR/services/DanaRExecutionService.java | 2 -- .../services/DanaRKoreanExecutionService.java | 2 -- .../PumpDanaRv2/services/DanaRv2ExecutionService.java | 2 -- 4 files changed, 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index de0d73e706..192bffba3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -23,7 +23,6 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; public class BolusProgressDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(BolusProgressDialog.class); @@ -37,8 +36,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL public static boolean bolusEnded = false; public static boolean running = true; - boolean started = false; - public BolusProgressDialog() { super(); } @@ -124,11 +121,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL } } - @Subscribe - public void onStatusEvent(final EventDanaRBolusStart ev) { - started = true; - } - @Subscribe public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { if(BolusProgressDialog.running){ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 3f91fd659a..419d5feb2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -76,7 +76,6 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBasic; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -416,7 +415,6 @@ public class DanaRExecutionService extends Service { } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables - MainApp.bus().post(new EventDanaRBolusStart()); long startTime = System.currentTimeMillis(); if (!stop.stopped) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index 648159f214..470d526360 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -67,7 +67,6 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.SerialIOThread; @@ -409,7 +408,6 @@ public class DanaRKoreanExecutionService extends Service { } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables - MainApp.bus().post(new EventDanaRBolusStart()); if (!stop.stopped) { mSerialIOThread.sendMessage(start); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index e73c9d65f8..618549a4ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -38,7 +38,6 @@ import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.*; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread; @@ -413,7 +412,6 @@ public class DanaRv2ExecutionService extends Service { } if (amount > 0) { MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables - MainApp.bus().post(new EventDanaRBolusStart()); if (!stop.stopped) { mSerialIOThread.sendMessage(start); From c11455dff1f72ade66313b7725929141f5689aea Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Sep 2017 01:31:24 +0200 Subject: [PATCH 19/40] Make the BolusProgress dialog a bit more self-contained. (cherry picked from commit 75db72a) --- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 1 - .../plugins/Overview/Dialogs/BolusProgressDialog.java | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index aa603286f4..af5eeb6376 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -455,7 +455,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain result = activePump.deliverTreatment(detailedBolusInfo); - BolusProgressDialog.bolusEnded = true; MainApp.bus().post(new EventDismissBolusprogressIfRunning(result)); mWakeLock.release(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index 192bffba3c..50a2a8b50f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -33,8 +33,8 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL BolusProgressHelperActivity helperActivity; static double amount; - public static boolean bolusEnded = false; - public static boolean running = true; + private static boolean bolusEnded = false; + private static boolean running = true; public BolusProgressDialog() { super(); @@ -124,6 +124,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL @Subscribe public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { if(BolusProgressDialog.running){ + bolusEnded = true; dismiss(); } } From 612efa6a133a9ff2edda71df7a4061d08da3d402 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Sep 2017 18:16:13 +0200 Subject: [PATCH 20/40] Revert "Make the BolusProgress dialog a bit more self-contained." Breaks dismissal of dialog (only one invocation of EventDismissBolusprogressIfRunning also sets bolusEnded=true). This reverts commit c11455dff1f72ade66313b7725929141f5689aea. --- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 1 + .../plugins/Overview/Dialogs/BolusProgressDialog.java | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index af5eeb6376..aa603286f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -455,6 +455,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain result = activePump.deliverTreatment(detailedBolusInfo); + BolusProgressDialog.bolusEnded = true; MainApp.bus().post(new EventDismissBolusprogressIfRunning(result)); mWakeLock.release(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index 50a2a8b50f..192bffba3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -33,8 +33,8 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL BolusProgressHelperActivity helperActivity; static double amount; - private static boolean bolusEnded = false; - private static boolean running = true; + public static boolean bolusEnded = false; + public static boolean running = true; public BolusProgressDialog() { super(); @@ -124,7 +124,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL @Subscribe public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { if(BolusProgressDialog.running){ - bolusEnded = true; dismiss(); } } From 936ce42cc0fb255f383e4438923a42c84ea1af5e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 10 Sep 2017 14:24:00 +0200 Subject: [PATCH 21/40] Remove duplicate logging. --- .../nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java | 2 -- .../androidaps/plugins/PumpDanaRKorean/SerialIOThread.java | 2 -- .../androidaps/plugins/PumpDanaRv2/SerialIOThread.java | 2 -- 3 files changed, 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java index fabda4e26a..af3b852aa6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java @@ -159,7 +159,6 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - log.error("Unhandled exception", e); } synchronized (message) { @@ -167,7 +166,6 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java index 5a8b7fe564..566b32831f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java @@ -160,7 +160,6 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - log.error("Unhandled exception", e); } synchronized (message) { @@ -168,7 +167,6 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java index 130657b14d..244014f3d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java @@ -160,7 +160,6 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - log.error("Unhandled exception", e); } synchronized (message) { @@ -168,7 +167,6 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - log.error("Unhandled exception", e); } } From 07b04b8abfad42a9e13553395b88b7d0069b45ec Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 12 Sep 2017 01:23:38 +0200 Subject: [PATCH 22/40] Use correct units for low/high from TT. --- app/src/main/java/info/nightscout/utils/BolusWizard.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index 984454005c..ec5c0ec02b 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -67,8 +67,8 @@ public class BolusWizard { targetBGLow = specificProfile.getTargetLow(); targetBGHigh = specificProfile.getTargetHigh(); if (tempTarget != null) { - targetBGLow = tempTarget.low; - targetBGHigh = tempTarget.high; + targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, specificProfile.getUnits()); + targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, specificProfile.getUnits()); } if (bg <= targetBGLow) { bgDiff = bg - targetBGLow; From cb3b472488871b08fdf42f5c557f058a5de3f6d9 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 13 Sep 2017 12:59:29 +0200 Subject: [PATCH 23/40] VirtualPump: set PumpEnactResult.enacted. (cherry picked from commit ec49bc3) --- .../androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index c04ec9b12f..3a281d01b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -217,6 +217,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { result.success = true; result.bolusDelivered = detailedBolusInfo.insulin; result.carbsDelivered = detailedBolusInfo.carbs; + result.enacted = result.bolusDelivered > 0 || result.carbsDelivered > 0; result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); Double delivering = 0d; From e350c8c3c3e3e646c6f14471cee3ff98166e24c9 Mon Sep 17 00:00:00 2001 From: Wouter Lagerweij Date: Sun, 17 Sep 2017 00:53:16 +0200 Subject: [PATCH 24/40] Rounding fix --- .../java/info/nightscout/utils/Round.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index 26a4d5abce..d8bc76502b 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -1,15 +1,42 @@ package info.nightscout.utils; +import android.support.annotation.NonNull; +import android.util.Log; + +import java.math.BigDecimal; + /** * Created by mike on 20.06.2016. */ public class Round { - public static Double roundTo(double x, Double step) { + public static Double roundTo(Double x, Double step) { + + if (step > 1) { + return roundToWhole(x, step); + } else { + return roundToNrOfDecimals(x, getDecimalsFromStep(step)); + } + } + + private static int getDecimalsFromStep(Double step) { + String stepString = Double.toString(step); + return stepString.substring(stepString.indexOf('.') + 1).length(); + } + + private static Double roundToNrOfDecimals(Double x, int decimals) { + BigDecimal number = new BigDecimal(Double.toString(x)); + number = number.setScale(decimals, BigDecimal.ROUND_HALF_UP); + + return number.doubleValue(); + } + + private static Double roundToWhole(Double x, Double step) { if (x != 0d) { return Math.round(x / step) * step; } return 0d; } + public static Double floorTo(Double x, Double step) { if (x != 0d) { return Math.floor(x / step) * step; From aaa3f648d071964aab4871bd3593be5a4c7785a1 Mon Sep 17 00:00:00 2001 From: Wouter Lagerweij Date: Sun, 17 Sep 2017 00:56:00 +0200 Subject: [PATCH 25/40] Removed unused imports --- app/src/main/java/info/nightscout/utils/Round.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index d8bc76502b..9cd2ea0acb 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -1,8 +1,5 @@ package info.nightscout.utils; -import android.support.annotation.NonNull; -import android.util.Log; - import java.math.BigDecimal; /** From 4bda2227868eb4f5d4bc67e71ab36364c2b6b73d Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Sat, 16 Sep 2017 19:27:10 -0400 Subject: [PATCH 26/40] Merge branch 'dev' of C:\Users\Dylan\StudioProjects\AndroidAPS fork with conflicts. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1d3591c8a4..6cbe7a6222 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit From 91f0c2130684ad5d50806c9932d062dbed98f8d5 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Sat, 16 Sep 2017 19:30:07 -0400 Subject: [PATCH 27/40] Changed how time strings are parsed to fix a problem where PM times were being saved as the AM version any time toSeconds was called --- app/src/main/java/info/nightscout/utils/DateUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index bf2c1ba1fd..e94188f826 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -85,15 +85,15 @@ public class DateUtil { } public static int toSeconds(String hh_colon_mm) { - Pattern p = Pattern.compile("(\\d+):(\\d+)( a.m.| p.m.|)"); + Pattern p = Pattern.compile("(\\d+):(\\d+)( a.m.| p.m.| AM | PM)"); Matcher m = p.matcher(hh_colon_mm); int retval = 0; if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; - if (m.group(3).equals(" .a.m") && m.group(1).equals("12")) + if (m.group(3).equals(" AM") && m.group(1).equals("12")) retval -= 12 * 60 * 60; - if (m.group(3).equals(" p.m.") && !m.group(1).equals("12")) + if (m.group(3).equals(" PM") && !(m.group(1).equals("12"))) retval += 12 * 60 * 60; } return retval; From db4d203437e82921c0f2f2d0969950dfdb988e97 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Sat, 16 Sep 2017 20:02:08 -0400 Subject: [PATCH 28/40] Revert "Merge branch 'dev' of C:\Users\Dylan\StudioProjects\AndroidAPS fork with conflicts." This reverts commit 4bda2227868eb4f5d4bc67e71ab36364c2b6b73d. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6cbe7a6222..1d3591c8a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit From 02c2213545d703e3a5861b83e54ffad8cc33c310 Mon Sep 17 00:00:00 2001 From: Wouter Lagerweij Date: Sun, 17 Sep 2017 14:27:49 +0200 Subject: [PATCH 29/40] Changed rounding to use BigDecimals to avoid noisy long doubles in output --- .../java/info/nightscout/utils/Round.java | 52 +++++++------------ .../java/info/nightscout/utils/RoundTest.java | 3 +- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index 9cd2ea0acb..a45714ad45 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -7,43 +7,31 @@ import java.math.BigDecimal; */ public class Round { public static Double roundTo(Double x, Double step) { + return round(x, step, BigDecimal.ROUND_HALF_UP); + } - if (step > 1) { - return roundToWhole(x, step); - } else { - return roundToNrOfDecimals(x, getDecimalsFromStep(step)); - } + public static Double floorTo(Double x, Double step) { + return round(x, step, BigDecimal.ROUND_FLOOR); + } + + public static Double ceilTo(Double x, Double step) { + return round(x, step, BigDecimal.ROUND_CEILING); + } + + private static Double round(Double x, Double step, int roundingMode) { + BigDecimal numberToRound = new BigDecimal((Double.toString(x))); + BigDecimal stepSize = new BigDecimal((Double.toString(step))); + int scale = getDecimalsFromStep(step); + + numberToRound.setScale(scale, BigDecimal.ROUND_HALF_UP); + + BigDecimal rounded = numberToRound.divide(stepSize, 0, roundingMode).multiply(stepSize); + + return rounded.doubleValue(); } private static int getDecimalsFromStep(Double step) { String stepString = Double.toString(step); return stepString.substring(stepString.indexOf('.') + 1).length(); } - - private static Double roundToNrOfDecimals(Double x, int decimals) { - BigDecimal number = new BigDecimal(Double.toString(x)); - number = number.setScale(decimals, BigDecimal.ROUND_HALF_UP); - - return number.doubleValue(); - } - - private static Double roundToWhole(Double x, Double step) { - if (x != 0d) { - return Math.round(x / step) * step; - } - return 0d; - } - - public static Double floorTo(Double x, Double step) { - if (x != 0d) { - return Math.floor(x / step) * step; - } - return 0d; - } - public static Double ceilTo(Double x, Double step) { - if (x != 0d) { - return Math.ceil(x / step) * step; - } - return 0d; - } } diff --git a/app/src/test/java/info/nightscout/utils/RoundTest.java b/app/src/test/java/info/nightscout/utils/RoundTest.java index d95ab2b391..4ef1be054c 100644 --- a/app/src/test/java/info/nightscout/utils/RoundTest.java +++ b/app/src/test/java/info/nightscout/utils/RoundTest.java @@ -14,6 +14,8 @@ public class RoundTest { public void roundToTest() throws Exception { assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000001d ); assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000001d ); + assertEquals( 80d, Round.roundTo(65d, 40d), 0.00000001d ); + assertEquals( 0d, Round.roundTo(0d, 0.1d), 0.00000001d); } @Test @@ -27,5 +29,4 @@ public class RoundTest { assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d ); assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d ); } - } \ No newline at end of file From 81aadcc1be5442c533b626f6429c09f5c87171ee Mon Sep 17 00:00:00 2001 From: boysim <18055382+boysim@users.noreply.github.com> Date: Sun, 17 Sep 2017 17:02:27 +0200 Subject: [PATCH 30/40] Update strings.xml --- app/src/main/res/values-nl/strings.xml | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index d35103cb36..e46d349236 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -39,7 +39,7 @@ Wacht op pomp. Klik om te vernieuwen. Wacht op pomp VIRTUELE POMP - Zichtbaar + Toon Upload status naar NS Tijdelijk basaal SQL Storing @@ -79,7 +79,7 @@ Knop 1 Knop 2 Knop 3 - Kalibratie naat xDrip verzonden + Kalibratie naar xDrip verzonden Annuleer Annuleer tijdelijk basaal Koolhydraten @@ -91,12 +91,12 @@ KOOLHYDRATEN & BOLUS Koolhydraten correctie CGM & OPENAPS - CGM Sensor geplaatst - CGM Sensor Start + CGM Sens. ingebracht + CGM Sens. Start Multiwave bolus Correctie bolus Sport - Insuline leeftijd + Ouderdom insuline IAGE Insuline ampul wissel Maaltijd bolus @@ -118,19 +118,19 @@ Splitzen Notitie OpenAPS Offline - Leeftijd batterij + Ouderdom batterij Profiel wissel Pomp - Pomp batterij wissel - Infusieplaats wissel + Pomp bat. wissel + Infuus wissel Vraag - Leeftijd sensor + Ouderdom sensor SAGE CP Snack bolus - Einde tijdelijk basaal - Begin tijdelijk basaal - Tijdelijk streefdoel + Einde tijd. basaal + Start tijd. basaal + Tijd. streefdoel Tijdelijk streefdoel annuleren Wijzig het ingegevene! Kind @@ -143,7 +143,7 @@ BG bron Beperkingen Algemeen - insuline + Insuline curve Ledig wachtrij Loop Nightscout versie: @@ -213,7 +213,7 @@ Om de bolus %.2fU toe te dienen antwoord met de code %s XDrip ontvangt geen callibraties Om calibratie %.2f te verzenden antwoord met de code %s - Callibratie verzonden. Het ontvangen van callibraties moet actief zijn in xDrip. + Kalibratie verzonden. Het ontvangen van kalibraties moet actief zijn in xDrip. 한국어 Taal Lokaal profiel @@ -269,7 +269,7 @@ Eind gebruiker overeenkomst Activeer de superbolus functie in de wizard. Activeer deze niet tot je begrijpt wat dit doet. OVERDOSISEN ZIJN MOGELIJK BIJ ONWETENDHEID Activeer superbolus in de wizard - Geactiveerd + Actief Toon niet opnieuw Eet binnenkort Verander basaal patroon @@ -306,7 +306,7 @@ URL: Nightscout URL ingeven Nightscout URL - Doelstelling + Streefdoel ISF NS API geheim Verkeerde ingave @@ -341,13 +341,13 @@ Nightscout Ok Basaal - Loop gedeactiveerd door beperkingen + Loop gedeactiveerd door doelen tab Loop menu Superbolus (%d m) Loop pauzeren Pauzeer (%d m) Batterij bijna leeg - Maneel + Manueel MDI Afbreken OK @@ -430,17 +430,17 @@ Periode Script debug Maaltijd gegevens - éénheid + Eénheid Doelen - Controleren dat BG beschikbaar is op Nightscout en dat de insulinepomp data is geupload - Opzetten van visualisatie en monitoring eveneens onalyze van basaal en ratio\'s - Werking in Open Loop modus voor enkele dagen, manueel vele tijdelijke basalen instellen + Controleren van beschikbaarheid BG en insuline pomp data op Nightscout + Opzetten van visualisatie en monitoring eveneens analyze van basaal en ratio\'s + In Open Loop modus werken voor enkele dagen, manueel tijdelijke basaal instellen Starten met de Open Loop modus - Gebaseerd op deze ervarinegen beslissen wat het maximale basaal mag zijn en dit in de pomp instellen + Gebaseerd op deze ervaringen beslissen wat het maximale basaal mag zijn en dit in de pomp instellen De Open Loop begrijpen, inclusief de voorgestelde tijdelijke basalen - In gesloten Loop werken met een max. IOB = 0 voor enkele dagen met een beperkt aantal LBG - Starten met gesloten Loop met lage glucose begrenzing - Gebruik enkele dagen en ten miinste 1 naght zonder een laag BG alarm voordat je je BG doel laat dalen + In closed Loop werken met een max. IOB = 0 gedurende enkele dagen met een beperkt aantal lage BG + Starten met closed Loop met bescherming tegen lage BG + Verhoog max. IOB en test enkele dagen alsook minstens 1 nacht zonder een laag BG alarm voordat je jouw BG doel laat dalen BG beschikbaar op NS Pas het basaal en de ratios aan indien nodig, activeer hierna de auto-sens optie Bereken nu @@ -627,7 +627,7 @@ Standaard waarde: 0.7 Dit is de andere kan van de autosens veiligheid limiet. Dit zet een limiet op hoe laag het basaal kan aangepast worden, en hoe hoog het ISF en het BG doel Standaard waarde: 2 Bolus snooze is actief nadat je een maaltijd bolus toegediend hebt, zodat de loop geen tegenvoorstel met een verlaagd tijdelijk basaal doet nadat je gegeten hebt. Het voorbeeld hier van van standaard 2; dus een 3 u DIA betekent dat de bolus snooze gemiddeld 1.5u actief is (3DIA/2). Standaard waarde: 4 Dit is een combinatie van enerzijds het OpenAPS veiligheid limieten en anderzijds van “3 x max dagelijks basaal ; 4x actueel”. Dit betekent dat het basaal niet hoger kan ingesteld worden dan het ingestelde nummer keer het actueel basaal waarbij de limiet in de pomp geen invloed heeft.Dit is een veiligheidsmaatregel om te vermijden dat patiënten in gevaarlijke laag bereik komen zonder te snappen hoe het algoritme werkt. Nogmaals de standaard waarde is 4x; de meeste zullen deze waarde nooit moeten aanpassen maar zullen eerder andere waardes moeten aanpassen als ze tegen een limiet aanstoten. - 1 week succesvol loop gedurende de dag met geregeld KH ingave + Gedurende 1 week succesvol closed loop met KH ingave Synchroniseer profiel met de pomp ACTIVITIJD & FEEDBACK Model: %02X Protokoll: %02X Code: %02X From 3f7819937bed4b5efcb9996c39fdec8b17accbf0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:10:53 +0200 Subject: [PATCH 31/40] split JSON arrays to 50 elements --- .../plugins/NSClientInternal/broadcasts/BroadcastTreatment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 572cf7e055..9dd63a83fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -183,7 +183,7 @@ public class BroadcastTreatment { ret.add(newarr); } newarr = new JSONArray(); - count = 100; + count = 50; } newarr.put(array.get(i)); --count; From 4f5987b72aedde6e4732aba89680aaa16cd5d306 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Mon, 18 Sep 2017 14:20:28 -0400 Subject: [PATCH 32/40] Added cases to accept both a.m./p.m. and AM/PM --- app/src/main/java/info/nightscout/utils/DateUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index e94188f826..ccaae130b7 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -91,9 +91,9 @@ public class DateUtil { if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; - if (m.group(3).equals(" AM") && m.group(1).equals("12")) + if (m.group(3).equals(" a.m.") || m.group(3).equals(" AM") && m.group(1).equals("12")) retval -= 12 * 60 * 60; - if (m.group(3).equals(" PM") && !(m.group(1).equals("12"))) + if (m.group(3).equals(" p.m.") || m.group(3).equals(" PM") && !(m.group(1).equals("12"))) retval += 12 * 60 * 60; } return retval; From 17fa2617f7b4bd7274bcf67c961021eed0e2349d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:23:05 +0200 Subject: [PATCH 33/40] fix null pointer exception --- .../androidaps/plugins/XDripStatusline/StatuslinePlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index 45b5867886..8830ca2f6f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -192,6 +192,10 @@ public class StatuslinePlugin implements PluginBase { + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; } Profile profile = MainApp.getConfigBuilder().getProfile(); + + if (profile == null) + return status; + if (!mPrefs.getBoolean("xdripstatus_showbgi", false)) { return status; } From 8daf9e5c2cf165606840895eae5b84dca47cae89 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:40:03 +0200 Subject: [PATCH 34/40] use notification for bolus delivery failed message when window has been destroyed --- .../plugins/Actions/dialogs/FillDialog.java | 18 +++++++--- .../dialogs/NewExtendedBolusDialog.java | 9 +++++ .../Overview/Dialogs/NewTreatmentDialog.java | 29 +++++++++------- .../Overview/Dialogs/WizardDialog.java | 17 ++++++++-- .../plugins/Overview/Notification.java | 1 + .../plugins/Overview/OverviewFragment.java | 33 +++++++++++-------- 6 files changed, 75 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index f434a08d96..9c6b65acd5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -34,6 +34,8 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SP; @@ -172,11 +174,17 @@ public class FillDialog extends DialogFragment implements OnClickListener { detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - builder.setMessage(result.comment); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - builder.show(); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java index 1bfab76993..4102cb4b1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java @@ -10,6 +10,7 @@ import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; @@ -27,6 +28,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; @@ -103,11 +106,17 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli public void run() { PumpEnactResult result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes); if (!result.success) { + try { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(context.getString(R.string.treatmentdeliveryerror)); builder.setMessage(result.comment); builder.setPositiveButton(context.getString(R.string.ok), null); builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index faa3ff0785..c7845f1f15 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -14,8 +14,6 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.widget.Button; -import android.widget.TextView; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; @@ -34,8 +32,9 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewTreatmentDialog extends DialogFragment implements OnClickListener { @@ -90,7 +89,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs); - confirmMessage += getString(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""; + confirmMessage += getString(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""; confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; if (insulinAfterConstraints - insulin != 0 || !Objects.equals(carbsAfterConstraints, carbs)) confirmMessage += "
" + getString(R.string.constraintapllied); @@ -112,19 +111,27 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene @Override public void run() { DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - if (finalInsulinAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; - if (finalCarbsAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; + if (finalInsulinAfterConstraints == 0) + detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; + if (finalCarbsAfterConstraints == 0) + detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; detailedBolusInfo.insulin = finalInsulinAfterConstraints; detailedBolusInfo.carbs = finalCarbsAfterConstraints; detailedBolusInfo.context = context; detailedBolusInfo.source = Source.USER; PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - builder.setMessage(result.comment); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - builder.show(); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 98428f9493..4751dcbdb3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -57,6 +57,8 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -281,11 +283,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(calculatedTotalInsulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(calculatedCarbs); - confirmMessage += "
" + getString(R.string.bolus) + ": " + "" + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U" + ""; + confirmMessage += "
" + getString(R.string.bolus) + ": " + "" + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U" + ""; confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - if (insulinAfterConstraints - calculatedTotalInsulin != 0 || !carbsAfterConstraints.equals(calculatedCarbs)) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); @@ -336,7 +337,17 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com detailedBolusInfo.source = Source.USER; result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.treatmentdeliveryerror), result.comment, null); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java index 13b85e08fc..0201d9cabe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java @@ -49,6 +49,7 @@ public class Notification { public static final int NSURGENTALARM = 20; public static final int SHORT_DIA = 21; public static final int TOAST_ALARM = 22; + public static final int BOLUS_DELIVERY_ERROR = 24; public int id; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index ac5a57d963..e363158556 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -26,6 +26,7 @@ import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -110,6 +111,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock; import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; @@ -127,9 +129,8 @@ import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; + //Added By Rumen for staledata alarm -import info.nightscout.androidaps.plugins.Overview.Notification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); @@ -707,11 +708,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, detailedBolusInfo.source = Source.USER; PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - builder.setMessage(result.comment); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - builder.show(); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); @@ -1746,7 +1753,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onBindViewHolder(NotificationsViewHolder holder, int position) { Notification notification = notificationsList.get(position); holder.dismiss.setTag(notification); - if(Objects.equals(notification.text, MainApp.sResources.getString(R.string.nsalarm_staledata))) + if (Objects.equals(notification.text, MainApp.sResources.getString(R.string.nsalarm_staledata))) holder.dismiss.setText("snooze"); holder.text.setText(notification.text); holder.time.setText(DateUtil.timeString(notification.date)); @@ -1797,12 +1804,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L); } // Adding current time to snooze if we got staleData - log.debug("Notification text is: "+notification.text); - if(notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))){ + log.debug("Notification text is: " + notification.text); + if (notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))) { NotificationStore nstore = getPlugin().notificationStore; - long msToSnooze = SP.getInt("nsalarm_staledatavalue",15)*60*1000L; - log.debug("snooze nsalarm_staledatavalue in minutes is "+SP.getInt("nsalarm_staledatavalue",15)+"\n in ms is: "+msToSnooze+" currentTimeMillis is: "+System.currentTimeMillis()); - nstore.snoozeTo(System.currentTimeMillis()+(SP.getInt("nsalarm_staledatavalue",15)*60*1000L)); + long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L; + log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis()); + nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L)); } break; } From 8785bc63d5b83e432de3955b21a7d2cc5e269c46 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:54:53 +0200 Subject: [PATCH 35/40] loadEvents after bolus in separate thread --- .../services/DanaRv2ExecutionService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 618549a4ac..0e96987728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -428,9 +428,17 @@ public class DanaRv2ExecutionService extends Service { } } } - waitMsec(3000); bolusingTreatment = null; - loadEvents(); + // run loading history in separate thread and allow bolus dialog to be closed + new Thread(new Runnable() { + @Override + public void run() { + waitMsec(4000); + if (!(isConnected())) + connect("loadEvents"); + loadEvents(); + } + }).start(); return true; } From d8590fe8f14d011007e80d68b647145fc7e730b2 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Mon, 18 Sep 2017 15:04:46 -0400 Subject: [PATCH 36/40] Clarified boolean logic with parentheses :) --- app/src/main/java/info/nightscout/utils/DateUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index ccaae130b7..2410014808 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -91,9 +91,9 @@ public class DateUtil { if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; - if (m.group(3).equals(" a.m.") || m.group(3).equals(" AM") && m.group(1).equals("12")) + if ((m.group(3).equals(" a.m.") || m.group(3).equals(" AM")) && m.group(1).equals("12")) retval -= 12 * 60 * 60; - if (m.group(3).equals(" p.m.") || m.group(3).equals(" PM") && !(m.group(1).equals("12"))) + if ((m.group(3).equals(" p.m.") || m.group(3).equals(" PM")) && !(m.group(1).equals("12"))) retval += 12 * 60 * 60; } return retval; From d7f8d75d06ca82a52cfda3bb59e17387017d0bf2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:24:22 +0200 Subject: [PATCH 37/40] Revert "Rounding issues visible in nightscout insulin field" --- .../java/info/nightscout/utils/Round.java | 38 +++++++------------ .../java/info/nightscout/utils/RoundTest.java | 3 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index a45714ad45..26a4d5abce 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -1,37 +1,25 @@ package info.nightscout.utils; -import java.math.BigDecimal; - /** * Created by mike on 20.06.2016. */ public class Round { - public static Double roundTo(Double x, Double step) { - return round(x, step, BigDecimal.ROUND_HALF_UP); + public static Double roundTo(double x, Double step) { + if (x != 0d) { + return Math.round(x / step) * step; + } + return 0d; } - public static Double floorTo(Double x, Double step) { - return round(x, step, BigDecimal.ROUND_FLOOR); + if (x != 0d) { + return Math.floor(x / step) * step; + } + return 0d; } - public static Double ceilTo(Double x, Double step) { - return round(x, step, BigDecimal.ROUND_CEILING); - } - - private static Double round(Double x, Double step, int roundingMode) { - BigDecimal numberToRound = new BigDecimal((Double.toString(x))); - BigDecimal stepSize = new BigDecimal((Double.toString(step))); - int scale = getDecimalsFromStep(step); - - numberToRound.setScale(scale, BigDecimal.ROUND_HALF_UP); - - BigDecimal rounded = numberToRound.divide(stepSize, 0, roundingMode).multiply(stepSize); - - return rounded.doubleValue(); - } - - private static int getDecimalsFromStep(Double step) { - String stepString = Double.toString(step); - return stepString.substring(stepString.indexOf('.') + 1).length(); + if (x != 0d) { + return Math.ceil(x / step) * step; + } + return 0d; } } diff --git a/app/src/test/java/info/nightscout/utils/RoundTest.java b/app/src/test/java/info/nightscout/utils/RoundTest.java index 4ef1be054c..d95ab2b391 100644 --- a/app/src/test/java/info/nightscout/utils/RoundTest.java +++ b/app/src/test/java/info/nightscout/utils/RoundTest.java @@ -14,8 +14,6 @@ public class RoundTest { public void roundToTest() throws Exception { assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000001d ); assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000001d ); - assertEquals( 80d, Round.roundTo(65d, 40d), 0.00000001d ); - assertEquals( 0d, Round.roundTo(0d, 0.1d), 0.00000001d); } @Test @@ -29,4 +27,5 @@ public class RoundTest { assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d ); assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d ); } + } \ No newline at end of file From d2815e404578d8eb5bb063ff368e0806a684e2b1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:52:06 +0200 Subject: [PATCH 38/40] check for NaN --- .../SensitivityWeightedAveragePlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java index b957e21bda..a10905dbc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java @@ -172,6 +172,10 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity weightedsum += weight * value; } + if (weights == 0) { + return new AutosensResult(); + } + Profile profile = MainApp.getConfigBuilder().getProfile(); double sens = profile.getIsf(); From b797530c9d817f2835855d19254367c3d398ade6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:57:35 +0200 Subject: [PATCH 39/40] BG & IOB contribution on by default in wizard --- .../plugins/Overview/Dialogs/WizardDialog.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 6892d8859b..b1b629d339 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -268,19 +268,19 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } private void saveCheckedStates() { - SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); + //SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked()); - SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); - SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked()); + //SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); + //SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked()); } private void loadCheckedStates() { - bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); + //bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false)); cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false)); - bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); - basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true)); + //bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); + //basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true)); } @Override From cd7c7733ea5c0b88e8ef66dcf63e05d87d92cbb8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:59:01 +0200 Subject: [PATCH 40/40] bump 1.53 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 8d62dbe7f3..e39d8beca9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,7 @@ android { minSdkVersion 21 targetSdkVersion 23 versionCode 1500 - version "1.52" + version "1.53" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild() }