<commit_before>package info.nightscout.androidaps.plugins.general.automation.elements;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.LinearLayout;

import java.text.DecimalFormat;

import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.utils.NumberPicker;

public class InputTempTarget extends Element {

    private String units = Constants.MGDL;
    private double value;
    double minValue;
    private double maxValue;
    private double step;
    private DecimalFormat decimalFormat;

    private 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());
        if (getUnits().equals(Constants.MMOL))
            value = Constants.MIN_TT_MMOL;
        else
            value = Constants.MIN_TT_MGDL;
    }

    public InputTempTarget(InputTempTarget another) {
        super();
        value = another.getValue();
        setUnits(another.getUnits());
    }


    @Override
    public void addToLayout(LinearLayout root) {
        NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
        numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, textWatcher);
        numberPicker.setOnValueChangedListener(value -> this.value = value);
        root.addView(numberPicker);
    }

    public String getUnits() {
        return units;
    }

    public InputTempTarget setUnits(String units) {
        // set default initial value
        if (units.equals(Constants.MMOL)) {
            // mmol
            minValue = Constants.MIN_TT_MMOL;
            maxValue = Constants.MAX_TT_MMOL;
            step = 0.1;
            decimalFormat = new DecimalFormat("0.0");
        } else {
            // mg/dL
            minValue = Constants.MIN_TT_MGDL;
            maxValue = Constants.MAX_TT_MGDL;
            step = 1;
            decimalFormat = new DecimalFormat("0");
        }

        this.units = units;
        return this;
    }

    public InputTempTarget setValue(double value) {
        this.value = value;
        return this;
    }

    public double getValue() {
        return value;
    }

}
<commit_msg>safer default TT value in automation<commit_after>package info.nightscout.androidaps.plugins.general.automation.elements;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.LinearLayout;

import java.text.DecimalFormat;

import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.utils.NumberPicker;

public class InputTempTarget extends Element {

    private String units = Constants.MGDL;
    private double value;
    double minValue;
    private double maxValue;
    private double step;
    private DecimalFormat decimalFormat;

    private 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());
        if (getUnits().equals(Constants.MMOL))
            value = 6;
        else
            value = 110;
    }

    public InputTempTarget(InputTempTarget another) {
        super();
        value = another.getValue();
        setUnits(another.getUnits());
    }


    @Override
    public void addToLayout(LinearLayout root) {
        NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
        numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, textWatcher);
        numberPicker.setOnValueChangedListener(value -> this.value = value);
        root.addView(numberPicker);
    }

    public String getUnits() {
        return units;
    }

    public InputTempTarget setUnits(String units) {
        // set default initial value
        if (units.equals(Constants.MMOL)) {
            // mmol
            minValue = Constants.MIN_TT_MMOL;
            maxValue = Constants.MAX_TT_MMOL;
            step = 0.1;
            decimalFormat = new DecimalFormat("0.0");
        } else {
            // mg/dL
            minValue = Constants.MIN_TT_MGDL;
            maxValue = Constants.MAX_TT_MGDL;
            step = 1;
            decimalFormat = new DecimalFormat("0");
        }

        this.units = units;
        return this;
    }

    public InputTempTarget setValue(double value) {
        this.value = value;
        return this;
    }

    public double getValue() {
        return value;
    }

}

{'fraction_non_alphanumeric': 0.08882363736465407, 'fraction_numerical': 0.0029363185905670764, 'mean_word_length': 2.3977556109725686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2898631', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1476, 'n_words': 347}