AS value in %
This commit is contained in:
parent
e220a42e4b
commit
5d86ca742a
|
@ -10,19 +10,18 @@ import info.nightscout.androidaps.utils.NumberPicker;
|
|||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
public class InputAutosens extends Element {
|
||||
|
||||
private double value;
|
||||
double minValue = SP.getDouble("key_openapsama_autosens_min", 0.7d);
|
||||
double maxValue = SP.getDouble("key_openapsama_autosens_max", 1.2d);
|
||||
private double step = 0.01d;
|
||||
private DecimalFormat decimalFormat = new DecimalFormat("0.00");;
|
||||
private int value;
|
||||
int minValue = (int) (SP.getDouble("openapsama_autosens_min", 0.7d) * 100);
|
||||
int maxValue = (int) (SP.getDouble("openapsama_autosens_max", 1.2d) * 100);
|
||||
private double step = 1;
|
||||
private DecimalFormat decimalFormat = new DecimalFormat("1");;
|
||||
|
||||
NumberPicker numberPicker;
|
||||
final TextWatcher textWatcher = new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
value = Math.max(value, 0.7d);
|
||||
value = Math.min(value, 2d);
|
||||
value = Math.max(value, 70);
|
||||
value = Math.min(value, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,9 +42,9 @@ public class InputAutosens extends Element {
|
|||
|
||||
public InputAutosens(double value, double minValue, double maxValue, double step, DecimalFormat decimalFormat) {
|
||||
super();
|
||||
this.value = value;
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
this.value = (int) value;
|
||||
this.minValue = (int) ( minValue * 100 );
|
||||
this.maxValue = (int) (maxValue * 100 );
|
||||
this.step = step;
|
||||
this.decimalFormat = decimalFormat;
|
||||
}
|
||||
|
@ -62,26 +61,32 @@ public class InputAutosens extends Element {
|
|||
|
||||
@Override
|
||||
public void addToLayout(LinearLayout root) {
|
||||
minValue = (int) (SP.getDouble("openapsama_autosens_min", 0.7d) * 100);
|
||||
maxValue = (int) (SP.getDouble("openapsama_autosens_max", 1.2d) * 100);
|
||||
if (value > maxValue)
|
||||
value = Math.max(value, this.maxValue);
|
||||
if (value < minValue)
|
||||
value = minValue;
|
||||
numberPicker = new NumberPicker(root.getContext(), null);
|
||||
numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, textWatcher);
|
||||
numberPicker.setOnValueChangedListener(value -> this.value = value);
|
||||
numberPicker.setParams((double) value, (double) minValue, (double) maxValue, step, decimalFormat, true, textWatcher);
|
||||
numberPicker.setOnValueChangedListener(value -> this.value = (int) value);
|
||||
root.addView(numberPicker);
|
||||
}
|
||||
|
||||
public InputAutosens setValue(double value) {
|
||||
minValue = SP.getDouble("key_openapsama_autosens_min", 0.7d);
|
||||
maxValue = SP.getDouble("key_openapsama_autosens_max", 1.2d);
|
||||
public InputAutosens setValue(int value) {
|
||||
minValue = (int) (SP.getDouble("openapsama_autosens_min", 0.7d) * 100);
|
||||
maxValue = (int) (SP.getDouble("openapsama_autosens_max", 1.2d) * 100);
|
||||
if (value > maxValue)
|
||||
value = Math.max(value, this.maxValue);
|
||||
if (value < minValue)
|
||||
value = minValue;
|
||||
this.value = value;
|
||||
if (numberPicker != null)
|
||||
numberPicker.setValue(value);
|
||||
numberPicker.setValue((double) value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public class TriggerAutosensValue extends Trigger {
|
|||
lastRun = triggerAutosensValue.lastRun;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
public int getValue() {
|
||||
return value.getValue();
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class TriggerAutosensValue extends Trigger {
|
|||
return true;
|
||||
}
|
||||
|
||||
boolean doRun = comparator.getValue().check((autosensData.autosensResult.ratio), getValue());
|
||||
boolean doRun = comparator.getValue().check((autosensData.autosensResult.ratio), (double) (getValue() / 100d));
|
||||
if (doRun) {
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.debug("Ready for execution: " + friendlyDescription());
|
||||
|
@ -93,7 +93,7 @@ public class TriggerAutosensValue extends Trigger {
|
|||
Trigger fromJSON(String data) {
|
||||
try {
|
||||
JSONObject d = new JSONObject(data);
|
||||
value.setValue(JsonHelper.safeGetDouble(d, "value"));
|
||||
value.setValue(JsonHelper.safeGetInt(d, "value"));
|
||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||
} catch (Exception e) {
|
||||
|
@ -122,7 +122,7 @@ public class TriggerAutosensValue extends Trigger {
|
|||
return new TriggerAutosensValue(this);
|
||||
}
|
||||
|
||||
TriggerAutosensValue setValue(double requestedValue) {
|
||||
TriggerAutosensValue setValue(int requestedValue) {
|
||||
this.value.setValue(requestedValue);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1400,8 +1400,8 @@
|
|||
<string name="notexists">not exists</string>
|
||||
<string name="temptargetcompared">Temp target %1$s</string>
|
||||
<string name="wifissidcompared">WiFi SSID %1$s %2$s</string>
|
||||
<string name="autosenscompared">Autosens %1$s %2$s</string>
|
||||
<string name="autosenslabel">Autosens ratio</string>
|
||||
<string name="autosenscompared">Autosens %1$s %2$s %%</string>
|
||||
<string name="autosenslabel">Autosens %</string>
|
||||
<string name="currentlocation">Current Location</string>
|
||||
<string name="location">Location</string>
|
||||
<string name="latitude_short">Lat:</string>
|
||||
|
|
Loading…
Reference in a new issue