android-calculatorpp-114: "Calculator while typing" option is ignored

Fixes#114
This commit is contained in:
serso 2015-02-12 12:18:34 +01:00
parent f1d944a297
commit 9d99863752
4 changed files with 19 additions and 0 deletions

View File

@ -104,6 +104,11 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
return calculator.evaluate(operation, expression, sequenceId); return calculator.evaluate(operation, expression, sequenceId);
} }
@Override
public boolean isCalculateOnFly() {
return calculator.isCalculateOnFly();
}
@Override @Override
public boolean isConversionPossible(@Nonnull Generic generic, @Nonnull NumeralBase from, @Nonnull NumeralBase to) { public boolean isConversionPossible(@Nonnull Generic generic, @Nonnull NumeralBase from, @Nonnull NumeralBase to) {
return calculator.isConversionPossible(generic, from, to); return calculator.isConversionPossible(generic, from, to);

View File

@ -64,6 +64,8 @@ public interface Calculator extends CalculatorEventContainer, HistoryControl<Cal
@Nonnull String expression, @Nonnull String expression,
@Nonnull Long sequenceId); @Nonnull Long sequenceId);
boolean isCalculateOnFly();
/* /*
********************************************************************** **********************************************************************
* *

View File

@ -211,6 +211,11 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
this.calculateOnFly = calculateOnFly; this.calculateOnFly = calculateOnFly;
} }
@Override
public boolean isCalculateOnFly() {
return calculateOnFly;
}
@Nonnull @Nonnull
private CalculatorConversionEventData newConversionEventData(@Nonnull Long sequenceId, private CalculatorConversionEventData newConversionEventData(@Nonnull Long sequenceId,
@Nonnull Generic value, @Nonnull Generic value,

View File

@ -102,6 +102,13 @@ public enum CalculatorSpecialButton {
equals("=") { equals("=") {
@Override @Override
public void onClick(@Nonnull CalculatorKeyboard keyboard) { public void onClick(@Nonnull CalculatorKeyboard keyboard) {
final Calculator calculator = Locator.getInstance().getCalculator();
if (!calculator.isCalculateOnFly()) {
// no automatic calculations are => equals button must be used to calculate
calculator.evaluate();
return;
}
final CalculatorDisplayViewState displayViewState = Locator.getInstance().getDisplay().getViewState(); final CalculatorDisplayViewState displayViewState = Locator.getInstance().getDisplay().getViewState();
if (displayViewState.isValid()) { if (displayViewState.isValid()) {
final CharSequence text = displayViewState.getText(); final CharSequence text = displayViewState.getText();