From c848095060ab66464de036708fcc866400b93840 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 4 Sep 2019 11:30:55 +0200 Subject: [PATCH] add automation TT action TextWatcher --- .../actions/ActionStartTempTarget.java | 2 +- .../automation/elements/InputTempTarget.java | 20 ++++++++++++++++++- .../automation/elements/LabelWithElement.java | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java index 05d06f0b3a..659bb508eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java @@ -71,7 +71,7 @@ public class ActionStartTempTarget extends Action { int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol; new LayoutBuilder() - .add(new LabelWithElement(MainApp.gs(R.string.careportal_temporarytarget), MainApp.gs(unitResId), value)) + .add(new LabelWithElement(MainApp.gs(R.string.careportal_temporarytarget) + " [" + MainApp.gs(unitResId) + "]", "", value)) .add(new LabelWithElement(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "", duration)) .build(root); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java index 8175c496a5..509eb05853 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements; +import android.text.Editable; +import android.text.TextWatcher; import android.widget.LinearLayout; import java.text.DecimalFormat; @@ -17,6 +19,22 @@ public class InputTempTarget extends Element { private double step; private DecimalFormat decimalFormat; + final TextWatcher textWatcher = new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + value = Math.max(minValue, value); + value = Math.min(maxValue, value); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }; + public InputTempTarget() { super(); setUnits(ProfileFunctions.getInstance().getProfileUnits()); @@ -36,7 +54,7 @@ public class InputTempTarget extends Element { @Override public void addToLayout(LinearLayout root) { NumberPicker numberPicker = new NumberPicker(root.getContext(), null); - numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, null); + numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, textWatcher); numberPicker.setOnValueChangedListener(value -> this.value = value); root.addView(numberPicker); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java index 2531d56e6c..145d8c2d2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements; import android.graphics.Typeface; import android.view.ViewGroup; import android.widget.LinearLayout; +import android.widget.TableLayout; import android.widget.TextView; import info.nightscout.androidaps.MainApp; @@ -37,6 +38,10 @@ public class LabelWithElement extends Element { textViewPre.setTypeface(textViewPre.getTypeface(), Typeface.BOLD); layout.addView(textViewPre); + TextView spacer = new TextView(root.getContext()); + spacer.setLayoutParams(new TableLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); + layout.addView(spacer); + // add element to layout element.addToLayout(layout);