add automation TT action TextWatcher

This commit is contained in:
Milos Kozak 2019-09-04 11:30:55 +02:00
parent 84bec28699
commit c848095060
3 changed files with 25 additions and 2 deletions

View file

@ -71,7 +71,7 @@ public class ActionStartTempTarget extends Action {
int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol; int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol;
new LayoutBuilder() 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)) .add(new LabelWithElement(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "", duration))
.build(root); .build(root);
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.general.automation.elements; package info.nightscout.androidaps.plugins.general.automation.elements;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -17,6 +19,22 @@ public class InputTempTarget extends Element {
private double step; private double step;
private DecimalFormat decimalFormat; 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() { public InputTempTarget() {
super(); super();
setUnits(ProfileFunctions.getInstance().getProfileUnits()); setUnits(ProfileFunctions.getInstance().getProfileUnits());
@ -36,7 +54,7 @@ public class InputTempTarget extends Element {
@Override @Override
public void addToLayout(LinearLayout root) { public void addToLayout(LinearLayout root) {
NumberPicker numberPicker = new NumberPicker(root.getContext(), null); 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); numberPicker.setOnValueChangedListener(value -> this.value = value);
root.addView(numberPicker); root.addView(numberPicker);
} }

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TextView; import android.widget.TextView;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
@ -37,6 +38,10 @@ public class LabelWithElement extends Element {
textViewPre.setTypeface(textViewPre.getTypeface(), Typeface.BOLD); textViewPre.setTypeface(textViewPre.getTypeface(), Typeface.BOLD);
layout.addView(textViewPre); 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 // add element to layout
element.addToLayout(layout); element.addToLayout(layout);