low_mark, high_mark to setup wizard

This commit is contained in:
Milos Kozak 2019-12-02 00:07:08 +01:00
parent 36b009d56c
commit 87d3c43a33
7 changed files with 131 additions and 4 deletions

View file

@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment;
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
import info.nightscout.androidaps.setupwizard.elements.SWBreak; import info.nightscout.androidaps.setupwizard.elements.SWBreak;
import info.nightscout.androidaps.setupwizard.elements.SWButton; 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.SWEditString;
import info.nightscout.androidaps.setupwizard.elements.SWEditUrl; import info.nightscout.androidaps.setupwizard.elements.SWEditUrl;
import info.nightscout.androidaps.setupwizard.elements.SWFragment; import info.nightscout.androidaps.setupwizard.elements.SWFragment;
@ -116,6 +117,21 @@ public class SWDefinition {
.comment(R.string.setupwizard_units_prompt)) .comment(R.string.setupwizard_units_prompt))
.validator(() -> SP.contains(R.string.key_units)); .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) private SWScreen screenPermissionBattery = new SWScreen(R.string.permission)
.skippable(false) .skippable(false)
.add(new SWInfotext() .add(new SWInfotext()
@ -421,6 +437,7 @@ public class SWDefinition {
.add(screenPermissionStore) .add(screenPermissionStore)
.add(screenImport) .add(screenImport)
.add(screenUnits) .add(screenUnits)
.add(displaySettings)
.add(screenNsClient) .add(screenNsClient)
.add(screenAge) .add(screenAge)
.add(screenInsulin) .add(screenInsulin)
@ -448,6 +465,7 @@ public class SWDefinition {
.add(screenPermissionStore) .add(screenPermissionStore)
.add(screenImport) .add(screenImport)
.add(screenUnits) .add(screenUnits)
.add(displaySettings)
.add(screenNsClient) .add(screenNsClient)
.add(screenAge) .add(screenAge)
.add(screenInsulin) .add(screenInsulin)
@ -470,6 +488,7 @@ public class SWDefinition {
.add(screenPermissionStore) .add(screenPermissionStore)
.add(screenImport) .add(screenImport)
.add(screenUnits) .add(screenUnits)
.add(displaySettings)
.add(screenNsClient) .add(screenNsClient)
.add(screenBgSource) .add(screenBgSource)
.add(screenAge) .add(screenAge)

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.setupwizard;
public interface SWNumberValidator {
boolean isValid(double value);
}

View file

@ -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;
}
}

View file

@ -5,6 +5,7 @@ import android.graphics.Typeface;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -31,19 +32,19 @@ public class SWEditString extends SWItem {
Context context = layout.getContext(); Context context = layout.getContext();
TextView l = new TextView(context); TextView l = new TextView(context);
l.setId(layout.generateViewId()); l.setId(View.generateViewId());
l.setText(label); l.setText(label);
l.setTypeface(l.getTypeface(), Typeface.BOLD); l.setTypeface(l.getTypeface(), Typeface.BOLD);
layout.addView(l); layout.addView(l);
TextView c = new TextView(context); TextView c = new TextView(context);
c.setId(layout.generateViewId()); c.setId(View.generateViewId());
c.setText(comment); c.setText(comment);
c.setTypeface(c.getTypeface(), Typeface.ITALIC); c.setTypeface(c.getTypeface(), Typeface.ITALIC);
layout.addView(c); layout.addView(c);
EditText editText = new EditText(context); EditText editText = new EditText(context);
editText.setId(layout.generateViewId()); editText.setId(View.generateViewId());
editText.setInputType(InputType.TYPE_CLASS_TEXT); editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.setMaxLines(1); editText.setMaxLines(1);
editText.setText(SP.getString(preferenceId, "")); editText.setText(SP.getString(preferenceId, ""));

View file

@ -38,7 +38,8 @@ public class SWItem {
RADIOBUTTON, RADIOBUTTON,
PLUGIN, PLUGIN,
BUTTON, BUTTON,
FRAGMENT FRAGMENT,
UNITNUMBER
} }
Type type; Type type;

View file

@ -86,6 +86,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
public NumberPicker(Context context) { public NumberPicker(Context context) {
super(context, null); super(context, null);
this.initialize(context);
} }
public NumberPicker(Context context, AttributeSet attrs) { public NumberPicker(Context context, AttributeSet attrs) {

View file

@ -1658,5 +1658,7 @@
<string name="deletecurrentprofile">Delete current profile?</string> <string name="deletecurrentprofile">Delete current profile?</string>
<string name="copytolocalprofile">Create new local profile from this profile switch?</string> <string name="copytolocalprofile">Create new local profile from this profile switch?</string>
<string name="profilenamecontainsdot">Profile name contains dots.\nThis is not supported by NS.\nProfile is not uploaded to NS.</string> <string name="profilenamecontainsdot">Profile name contains dots.\nThis is not supported by NS.\nProfile is not uploaded to NS.</string>
<string name="low_mark_comment">Lower value of in range area (display only)</string>
<string name="high_mark_comment">Higher value of in range area (display only)</string>
</resources> </resources>