Minus button fix

This commit is contained in:
serso 2015-02-10 11:37:14 +01:00
parent 3d1731995a
commit d82d6f947d
7 changed files with 51 additions and 27 deletions

View File

@ -26,21 +26,10 @@ import android.content.Context;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.R;
import java.util.HashMap;
import java.util.Map;
import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_left;
import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_right;
import static org.solovyev.android.calculator.CalculatorSpecialButton.functions_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.history_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.like;
import static org.solovyev.android.calculator.CalculatorSpecialButton.open_app;
import static org.solovyev.android.calculator.CalculatorSpecialButton.operators_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.settings_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.vars_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.*;
/**
* User: serso
@ -80,7 +69,7 @@ public enum CalculatorButton {
multiplication(R.id.cpp_button_multiplication, "*"),
division(R.id.cpp_button_division, "/"),
plus(R.id.cpp_button_plus, "+"),
subtraction(R.id.cpp_button_subtraction, "-"),
subtraction(R.id.cpp_button_subtraction, ""),
percent(R.id.cpp_button_percent, "%"),
power(R.id.cpp_button_power, "^"),

View File

@ -24,4 +24,6 @@
<Button a:id="@id/cpp_button_subtraction"
style="@style/cpp_simple_metro_blue_operation_button_style"
xmlns:a="http://schemas.android.com/apk/res/android"
a:text="-" />
xmlns:tools="http://schemas.android.com/tools"
a:text=""
tools:ignore="HardcodedText" />

View File

@ -95,7 +95,7 @@
<include layout="@layout/cpp_simple_button_dot" />
<include layout="@layout/cpp_simple_button_subtraction" />
<include layout="@layout/cpp_simple_button_minus" />
<include layout="@layout/cpp_simple_button_app" />

View File

@ -95,7 +95,7 @@
<include layout="@layout/cpp_simple_button_dot" />
<include layout="@layout/cpp_simple_button_subtraction" />
<include layout="@layout/cpp_simple_button_minus" />
<include layout="@layout/cpp_simple_button_right" />

View File

@ -59,7 +59,7 @@
<include layout="@layout/cpp_simple_button_division" />
<include layout="@layout/cpp_simple_button_subtraction" />
<include layout="@layout/cpp_simple_button_minus" />
<include layout="@layout/cpp_simple_button_erase" />

View File

@ -66,7 +66,7 @@
<include layout="@layout/cpp_simple_button_dot" />
<include layout="@layout/cpp_simple_button_subtraction" />
<include layout="@layout/cpp_simple_button_minus" />
<include layout="@layout/cpp_simple_button_app" />

View File

@ -25,15 +25,13 @@ package org.solovyev.android.calculator.math;
import jscl.JsclMathEngine;
import jscl.NumeralBase;
import jscl.math.function.Constants;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.Locator;
import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.Collections;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@ -82,16 +80,51 @@ public enum MathType {
}
},
unary_operation(500, false, false, MathGroupType.operation, "-", "="),
binary_operation(600, false, false, MathGroupType.operation, "-", "+", "*", "×", "", "/", "^") {
unary_operation(500, false, false, MathGroupType.operation, "", "-", "=") {
@Nullable
@Override
protected String getSubstituteToJscl(@Nonnull String match) {
if (match.equals("×") || match.equals("")) {
return "*";
if (match.equals("")) {
return "-";
} else {
return null;
}
}
@Nullable
@Override
protected String getSubstituteFromJscl(@Nonnull String match) {
if (match.equals("-")) {
return "";
} else {
return null;
}
}
},
binary_operation(600, false, false, MathGroupType.operation, "", "-", "+", "*", "×", "", "/", "^") {
@Nullable
@Override
protected String getSubstituteFromJscl(@Nonnull String match) {
if (match.equals("-")) {
return "";
} else {
return null;
}
}
@Override
protected String getSubstituteToJscl(@Nonnull String match) {
switch (match) {
case "×":
case "":
return "*";
case "":
return "-";
default:
return null;
}
}
},
open_group_symbol(800, true, false, MathGroupType.other, "[", "(", "{") {
@ -149,7 +182,7 @@ public enum MathType {
digit(1125, true, true, MathGroupType.number) {
private final List<String> tokens = new ArrayList<String>(16);
private final List<String> tokens = new ArrayList<>(16);
{
for (Character character : NumeralBase.hex.getAcceptableCharacters()) {
tokens.add(character.toString());