multiplication sign fix

This commit is contained in:
serso
2011-12-15 23:17:34 +04:00
parent 602a626420
commit 69a25604a3
11 changed files with 59 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.util.TypedValue;
import android.view.*;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import jscl.AngleUnit;
@@ -141,6 +142,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
CalculatorEngine.instance.reset(this, preferences);
initMultiplicationButton();
preferences.registerOnSharedPreferenceChangeListener(this);
}
@@ -410,7 +413,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@SuppressWarnings({"UnusedDeclaration"})
public void digitButtonClickHandler(@NotNull View v) {
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
calculatorModel.processDigitButtonAction(((DirectionDragButton) v).getTextMiddle());
calculatorModel.processDigitButtonAction(((DirectionDragButton) v).getText().toString());
}
@SuppressWarnings({"UnusedDeclaration"})
@@ -561,6 +564,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this));
if (CalculatorEngine.GROUPING_SEPARATOR_P_KEY.equals(key) ||
CalculatorEngine.MULTIPLICATION_SIGN_P_KEY.equals(key) ||
CalculatorEngine.ROUND_RESULT_P_KEY.equals(key) ||
CalculatorEngine.RESULT_PRECISION_P_KEY.equals(key) ||
CalculatorEngine.ANGLE_UNITS_P_KEY.equals(key) ||
@@ -568,5 +572,16 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
CalculatorEngine.instance.reset(this, preferences);
this.calculatorModel.evaluate();
}
if ( CalculatorEngine.MULTIPLICATION_SIGN_P_KEY.equals(key) ) {
initMultiplicationButton();
}
}
private void initMultiplicationButton() {
final View multiplicationButton = findViewById(R.id.multiplicationButton);
if ( multiplicationButton instanceof Button) {
((Button) multiplicationButton).setText(CalculatorEngine.instance.getMultiplicationSign());
}
}
}

View File

@@ -40,7 +40,11 @@ public abstract class AbstractNumberBuilder {
* @return true if we can continue of processing of current number, if false - new number should be constructed
*/
protected boolean canContinue(@NotNull MathType.Result mathTypeResult) {
return ((mathTypeResult.getMathType().getGroupType() == MathType.MathGroupType.number && numeralBaseCheck(mathTypeResult) && numeralBaseInTheStart(mathTypeResult.getMathType()) || isSignAfterE(mathTypeResult)));
return ((mathTypeResult.getMathType().getGroupType() == MathType.MathGroupType.number && !spaceBefore(mathTypeResult) && numeralBaseCheck(mathTypeResult) && numeralBaseInTheStart(mathTypeResult.getMathType()) || isSignAfterE(mathTypeResult)));
}
private boolean spaceBefore(@NotNull MathType.Result mathTypeResult) {
return numberBuilder == null && mathTypeResult.getMatch().trim().isEmpty();
}
private boolean numeralBaseInTheStart(@NotNull MathType mathType) {

View File

@@ -36,6 +36,9 @@ public enum CalculatorEngine {
public static final String GROUPING_SEPARATOR_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator";
public static final String MULTIPLICATION_SIGN_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign";
public static final String MULTIPLICATION_SIGN_DEFAULT = "×";
public static final String ROUND_RESULT_P_KEY = "org.solovyev.android.calculator.CalculatorModel_round_result";
public static final boolean ROUND_RESULT_DEFAULT = true;
@@ -48,6 +51,7 @@ public enum CalculatorEngine {
public static final String ANGLE_UNITS_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_angle_units";
public static final String ANGLE_UNITS_DEFAULT = "deg";
public static final int DEFAULT_TIMEOUT = 3000;
@NotNull
@@ -76,11 +80,23 @@ public enum CalculatorEngine {
// calculation thread timeout in milliseconds, after timeout thread would be interrupted
private int timeout = DEFAULT_TIMEOUT;
@NotNull
private String multiplicationSign = MULTIPLICATION_SIGN_DEFAULT;
CalculatorEngine() {
this.engine.setRoundResult(true);
this.engine.setUseGroupingSeparator(true);
}
@NotNull
public String getMultiplicationSign() {
return multiplicationSign;
}
public void setMultiplicationSign(@NotNull String multiplicationSign) {
this.multiplicationSign = multiplicationSign;
}
public static class Result {
@NotNull
@@ -256,6 +272,7 @@ public enum CalculatorEngine {
this.setRoundResult(preferences.getBoolean(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT));
this.setAngleUnits(getAngleUnitsFromPrefs(preferences));
this.setNumeralBase(getNumeralBaseFromPrefs(preferences));
this.setMultiplicationSign(preferences.getString(MULTIPLICATION_SIGN_P_KEY, MULTIPLICATION_SIGN_DEFAULT));
final String groupingSeparator = preferences.getString(GROUPING_SEPARATOR_P_KEY, JsclMathEngine.GROUPING_SEPARATOR_DEFAULT);
if (StringUtils.isEmpty(groupingSeparator)) {

View File

@@ -53,7 +53,7 @@ public class FromJsclSimplifyTextProcessor implements TextProcessor<String, Gene
}
if (needMultiplicationSign(mathTypeBefore == null ? null : mathTypeBefore.getMathType(), mathTypeAfter == null ? null : mathTypeAfter.getMathType())) {
sb.append("×");
sb.append(CalculatorEngine.instance.getMultiplicationSign());
}
} else {

View File

@@ -90,7 +90,7 @@ public class ColorButton extends Button {
feedbackPaint.setStrokeWidth(2);
if (CollectionsUtils.contains(getText().toString(), Arrays.asList("+", "-", "/", "×"))) {
if (CollectionsUtils.contains(getText().toString(), Arrays.asList("+", "-", "/", "×", "*", ""))) {
getPaint().setColor(resources.getColor(R.color.button_operator_text_color));
} else if (getText().toString().equals("C")) {
getPaint().setColor(resources.getColor(R.color.button_ce_text_color));

View File

@@ -38,9 +38,6 @@ public class DirectionDragButton extends DragButton {
@NotNull
private final static String DEFAULT_DIRECTION_TEXT_SCALE = "0.33;0.33;0.33;0.33";
@Nullable
private String textMiddle;
protected static class DirectionTextData {
@NotNull
@@ -258,9 +255,6 @@ public class DirectionDragButton extends DragButton {
}
}
// backup text
this.textMiddle = String.valueOf(getText());
super.init(context);
initialized = true;
}
@@ -327,11 +321,6 @@ public class DirectionDragButton extends DragButton {
return getText(GuiDragDirection.down);
}
@Nullable
public String getTextMiddle() {
return textMiddle;
}
@Nullable
public String getText(@NotNull DragDirection direction) {
final GuiDragDirection guiDragDirection = GuiDragDirection.valueOf(direction);