use of com.health.openscale.core.evaluation.EvaluationSheet in project openScale by oliexdev.
the class FloatMeasurementView method appendDiffValue.
@Override
public void appendDiffValue(SpannableStringBuilder text, boolean newLine) {
if (previousValue < 0.0f) {
return;
}
char symbol;
int color;
final float diff = value - previousValue;
if (diff > 0.0f) {
symbol = SYMBOL_UP;
color = Color.GREEN;
} else if (diff < 0.0f) {
symbol = SYMBOL_DOWN;
color = Color.RED;
} else {
symbol = SYMBOL_NEUTRAL;
color = Color.GRAY;
}
// change color depending on if you are going towards or away from your weight goal
if (this instanceof WeightMeasurementView) {
if (diff > 0.0f) {
color = (value > getScaleUser().getGoalWeight()) ? Color.RED : Color.GREEN;
} else if (diff < 0.0f) {
color = (value < getScaleUser().getGoalWeight()) ? Color.RED : Color.GREEN;
}
}
final float evalValue = maybeConvertToOriginalValue(value);
EvaluationSheet evalSheet = new EvaluationSheet(getScaleUser(), dateTime);
evaluationResult = evaluateSheet(evalSheet, evalValue);
if (evaluationResult != null) {
switch(evaluationResult.eval_state) {
case LOW:
color = (diff > 0.0f) ? Color.GREEN : Color.RED;
break;
case HIGH:
color = (diff < 0.0f) ? Color.GREEN : Color.RED;
break;
case NORMAL:
color = Color.GREEN;
break;
}
}
if (newLine) {
text.append('\n');
}
int start = text.length();
text.append(symbol);
text.setSpan(new ForegroundColorSpan(color), start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.append(' ');
start = text.length();
text.append(formatValue(diff));
text.setSpan(new RelativeSizeSpan(0.8f), start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
use of com.health.openscale.core.evaluation.EvaluationSheet in project openScale by oliexdev.
the class FloatMeasurementView method setValueInner.
private void setValueInner(float newValue, String suffix, boolean callListener) {
value = newValue;
evaluationResult = null;
if (!getUpdateViews()) {
return;
}
if (value == AUTO_VALUE) {
setValueView(getContext().getString(R.string.label_automatic), false);
} else {
setValueView(formatValue(value) + suffix, callListener);
if (getMeasurementMode() != MeasurementViewMode.ADD) {
EvaluationSheet evalSheet = new EvaluationSheet(getScaleUser(), dateTime);
float evalValue = value;
if (shouldConvertPercentageToAbsoluteWeight()) {
evalValue = makeRelativeWeight(value);
}
evaluationResult = evaluateSheet(evalSheet, evalValue);
if (shouldConvertPercentageToAbsoluteWeight()) {
evaluationResult.value = value;
evaluationResult.lowLimit = makeAbsoluteWeight(evaluationResult.lowLimit);
evaluationResult.highLimit = makeAbsoluteWeight(evaluationResult.highLimit);
}
}
}
setEvaluationView(evaluationResult);
}
use of com.health.openscale.core.evaluation.EvaluationSheet in project openScale by oliexdev.
the class FloatMeasurementView method setValueInner.
private void setValueInner(float newValue, boolean callListener) {
value = newValue;
evaluationResult = null;
if (!getUpdateViews()) {
return;
}
if (value == AUTO_VALUE) {
setValueView(getContext().getString(R.string.label_automatic), false);
} else {
setValueView(formatValue(value, true), callListener);
if (getMeasurementMode() != MeasurementViewMode.ADD) {
final float evalValue = maybeConvertToOriginalValue(value);
EvaluationSheet evalSheet = new EvaluationSheet(getScaleUser(), dateTime);
evaluationResult = evaluateSheet(evalSheet, evalValue);
if (evaluationResult != null) {
evaluationResult.value = value;
evaluationResult.lowLimit = maybeConvertValue(evaluationResult.lowLimit);
evaluationResult.highLimit = maybeConvertValue(evaluationResult.highLimit);
}
}
}
setEvaluationView(evaluationResult);
}
Aggregations