diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java
index db211ce09c..37cfe695b4 100644
--- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java
+++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java
@@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment;
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
import info.nightscout.androidaps.setupwizard.elements.SWBreak;
import info.nightscout.androidaps.setupwizard.elements.SWButton;
+import info.nightscout.androidaps.setupwizard.elements.SWEditNumberWithUnits;
import info.nightscout.androidaps.setupwizard.elements.SWEditString;
import info.nightscout.androidaps.setupwizard.elements.SWEditUrl;
import info.nightscout.androidaps.setupwizard.elements.SWFragment;
@@ -116,6 +117,21 @@ public class SWDefinition {
.comment(R.string.setupwizard_units_prompt))
.validator(() -> SP.contains(R.string.key_units));
+ private SWScreen displaySettings = new SWScreen(R.string.wear_display_settings)
+ .skippable(false)
+ .add(new SWEditNumberWithUnits(4d, 3d, 8d)
+ .preferenceId(R.string.key_low_mark)
+ .updateDelay(5)
+ .label(R.string.low_mark)
+ .comment(R.string.low_mark_comment))
+ .add(new SWBreak())
+ .add(new SWEditNumberWithUnits(10d, 5d, 20d)
+ .preferenceId(R.string.key_high_mark)
+ .updateDelay(5)
+ .label(R.string.high_mark)
+ .comment(R.string.high_mark_comment))
+ .validator(() -> SP.contains(R.string.key_low_mark) && SP.contains(R.string.key_high_mark));
+
private SWScreen screenPermissionBattery = new SWScreen(R.string.permission)
.skippable(false)
.add(new SWInfotext()
@@ -421,6 +437,7 @@ public class SWDefinition {
.add(screenPermissionStore)
.add(screenImport)
.add(screenUnits)
+ .add(displaySettings)
.add(screenNsClient)
.add(screenAge)
.add(screenInsulin)
@@ -448,6 +465,7 @@ public class SWDefinition {
.add(screenPermissionStore)
.add(screenImport)
.add(screenUnits)
+ .add(displaySettings)
.add(screenNsClient)
.add(screenAge)
.add(screenInsulin)
@@ -470,6 +488,7 @@ public class SWDefinition {
.add(screenPermissionStore)
.add(screenImport)
.add(screenUnits)
+ .add(displaySettings)
.add(screenNsClient)
.add(screenBgSource)
.add(screenAge)
diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWNumberValidator.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWNumberValidator.java
new file mode 100644
index 0000000000..a71da1dea7
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWNumberValidator.java
@@ -0,0 +1,5 @@
+package info.nightscout.androidaps.setupwizard;
+
+public interface SWNumberValidator {
+ boolean isValid(double value);
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumberWithUnits.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumberWithUnits.java
new file mode 100644
index 0000000000..6816b6fa1f
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumberWithUnits.java
@@ -0,0 +1,98 @@
+package info.nightscout.androidaps.setupwizard.elements;
+
+import android.content.Context;
+import android.graphics.Typeface;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import java.text.DecimalFormat;
+
+import info.nightscout.androidaps.Constants;
+import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
+import info.nightscout.androidaps.setupwizard.SWNumberValidator;
+import info.nightscout.androidaps.utils.NumberPicker;
+import info.nightscout.androidaps.utils.SP;
+import info.nightscout.androidaps.utils.SafeParse;
+
+
+public class SWEditNumberWithUnits extends SWItem {
+
+ private SWNumberValidator validator = new SWNumberValidator() {
+ @Override
+ public boolean isValid(double value) {
+ return value >= min && value <= max;
+ }
+ };
+ private int updateDelay = 0;
+ private double init, min, max;
+
+ public SWEditNumberWithUnits(double defaultMMOL, double minMMOL, double maxMMOL) {
+ super(Type.UNITNUMBER);
+ init = defaultMMOL;
+ min = minMMOL;
+ max = maxMMOL;
+ }
+
+ @Override
+ public void generateDialog(LinearLayout layout) {
+ Context context = layout.getContext();
+
+ TextWatcher watcher = new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ if (validator != null && validator.isValid(SafeParse.stringToDouble(s.toString())))
+ save(s.toString(), updateDelay);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+ };
+
+ TextView l = new TextView(context);
+ l.setId(View.generateViewId());
+ l.setText(label);
+ l.setTypeface(l.getTypeface(), Typeface.BOLD);
+ layout.addView(l);
+
+ double initValue = SP.getDouble(preferenceId, init);
+ initValue = Profile.toCurrentUnits(initValue);
+
+ NumberPicker numberPicker = new NumberPicker(context);
+ if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL))
+ numberPicker.setParams(initValue, min, max, 0.1d, new DecimalFormat("0.0"), false, null, watcher);
+ else
+ numberPicker.setParams(initValue, min * 18, max * 18, 1d, new DecimalFormat("0"), false, null, watcher);
+
+// LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) numberPicker.getLayoutParams();
+// ll.gravity = Gravity.CENTER;
+// numberPicker.setLayoutParams(ll);
+ layout.addView(numberPicker);
+
+ TextView c = new TextView(context);
+ c.setId(View.generateViewId());
+ c.setText(comment);
+ c.setTypeface(c.getTypeface(), Typeface.ITALIC);
+ layout.addView(c);
+
+ super.generateDialog(layout);
+ }
+
+ public SWEditNumberWithUnits preferenceId(int preferenceId) {
+ this.preferenceId = preferenceId;
+ return this;
+ }
+
+ public SWEditNumberWithUnits updateDelay(int updateDelay) {
+ this.updateDelay = updateDelay;
+ return this;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java
index 50e851ed6b..b16164c064 100644
--- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java
+++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditString.java
@@ -5,6 +5,7 @@ import android.graphics.Typeface;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
+import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -31,19 +32,19 @@ public class SWEditString extends SWItem {
Context context = layout.getContext();
TextView l = new TextView(context);
- l.setId(layout.generateViewId());
+ l.setId(View.generateViewId());
l.setText(label);
l.setTypeface(l.getTypeface(), Typeface.BOLD);
layout.addView(l);
TextView c = new TextView(context);
- c.setId(layout.generateViewId());
+ c.setId(View.generateViewId());
c.setText(comment);
c.setTypeface(c.getTypeface(), Typeface.ITALIC);
layout.addView(c);
EditText editText = new EditText(context);
- editText.setId(layout.generateViewId());
+ editText.setId(View.generateViewId());
editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.setMaxLines(1);
editText.setText(SP.getString(preferenceId, ""));
diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java
index 6931344acf..720d00d4b7 100644
--- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java
+++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java
@@ -38,7 +38,8 @@ public class SWItem {
RADIOBUTTON,
PLUGIN,
BUTTON,
- FRAGMENT
+ FRAGMENT,
+ UNITNUMBER
}
Type type;
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java b/app/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java
index f47122e0c9..54e676a52d 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java
+++ b/app/src/main/java/info/nightscout/androidaps/utils/NumberPicker.java
@@ -86,6 +86,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
public NumberPicker(Context context) {
super(context, null);
+ this.initialize(context);
}
public NumberPicker(Context context, AttributeSet attrs) {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5353bdedd2..f5d78bc687 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1658,5 +1658,7 @@
Delete current profile?
Create new local profile from this profile switch?
Profile name contains dots.\nThis is not supported by NS.\nProfile is not uploaded to NS.
+ Lower value of in range area (display only)
+ Higher value of in range area (display only)