multiplication sign fix

This commit is contained in:
Sergey Solovyev 2011-12-15 23:17:34 +04:00
parent 68a7c2c4c3
commit 69e49b2c84
11 changed files with 59 additions and 15 deletions

View File

@ -127,6 +127,8 @@
<string name="p_grouping_separator_space">Пробел ( )</string> <string name="p_grouping_separator_space">Пробел ( )</string>
<string name="c_calc_grouping_separator">Разделитель разрядов</string> <string name="c_calc_grouping_separator">Разделитель разрядов</string>
<string name="c_calc_grouping_separator_summary">Устанавливает разделитель разрядов числа</string> <string name="c_calc_grouping_separator_summary">Устанавливает разделитель разрядов числа</string>
<string name="c_calc_multiplication_sign">Знак произведения</string>
<string name="c_calc_multiplication_sign_summary">Устанавливает знак произведения</string>
<string name="c_calc_layout">Раскладка</string> <string name="c_calc_layout">Раскладка</string>
<string name="p_layout_cellphone">Телефон</string> <string name="p_layout_cellphone">Телефон</string>

View File

@ -27,6 +27,12 @@
<item>" "</item> <item>" "</item>
</string-array> </string-array>
<string-array name="p_multiplication_sign_values">
<item>"*"</item>
<item>"×"</item>
<item>"∙"</item>
</string-array>
<string-array name="p_layout_names"> <string-array name="p_layout_names">
<item>@string/p_layout_cellphone</item> <item>@string/p_layout_cellphone</item>
<item>@string/p_layout_calculator</item> <item>@string/p_layout_calculator</item>

View File

@ -44,6 +44,9 @@
<string name="p_calc_grouping_separator_key">org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator</string> <string name="p_calc_grouping_separator_key">org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator</string>
<string name="p_calc_grouping_separator">" "</string> <string name="p_calc_grouping_separator">" "</string>
<string name="p_calc_multiplication_sign_key">org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign</string>
<string name="p_calc_multiplication_sign">"×"</string>
<string name="p_calc_haptic_feedback_duration_key">org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key</string> <string name="p_calc_haptic_feedback_duration_key">org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key</string>
<string name="p_calc_haptic_feedback_duration">" "</string> <string name="p_calc_haptic_feedback_duration">" "</string>

View File

@ -128,6 +128,8 @@
<string name="p_grouping_separator_space">Space ( )</string> <string name="p_grouping_separator_space">Space ( )</string>
<string name="c_calc_grouping_separator">Grouping separator</string> <string name="c_calc_grouping_separator">Grouping separator</string>
<string name="c_calc_grouping_separator_summary">Sets grouping separator</string> <string name="c_calc_grouping_separator_summary">Sets grouping separator</string>
<string name="c_calc_multiplication_sign">Multiplication sign</string>
<string name="c_calc_multiplication_sign_summary">Sets multiplication sign</string>
<string name="c_calc_layout">Layout</string> <string name="c_calc_layout">Layout</string>
<string name="p_layout_cellphone">Cellphone</string> <string name="p_layout_cellphone">Cellphone</string>

View File

@ -23,6 +23,12 @@
a:summary="@string/c_calc_grouping_separator_summary" a:summary="@string/c_calc_grouping_separator_summary"
a:entryValues="@array/p_grouping_separator_values"/> a:entryValues="@array/p_grouping_separator_values"/>
<ListPreference a:key="@string/p_calc_multiplication_sign_key"
a:title="@string/c_calc_multiplication_sign"
a:entries="@array/p_multiplication_sign_values"
a:summary="@string/c_calc_multiplication_sign_summary"
a:entryValues="@array/p_multiplication_sign_values"/>
<ListPreference a:key="@string/p_calc_angle_units_key" <ListPreference a:key="@string/p_calc_angle_units_key"
a:title="@string/c_calc_angle_units" a:title="@string/c_calc_angle_units"
a:entries="@array/p_angle_units_names" a:entries="@array/p_angle_units_names"

View File

@ -19,6 +19,7 @@ import android.text.method.LinkMovementMethod;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.*; import android.view.*;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import jscl.AngleUnit; import jscl.AngleUnit;
@ -141,6 +142,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
CalculatorEngine.instance.reset(this, preferences); CalculatorEngine.instance.reset(this, preferences);
initMultiplicationButton();
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
@ -410,7 +413,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void digitButtonClickHandler(@NotNull View v) { public void digitButtonClickHandler(@NotNull View v) {
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed()); 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"}) @SuppressWarnings({"UnusedDeclaration"})
@ -561,6 +564,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this)); dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this));
if (CalculatorEngine.GROUPING_SEPARATOR_P_KEY.equals(key) || if (CalculatorEngine.GROUPING_SEPARATOR_P_KEY.equals(key) ||
CalculatorEngine.MULTIPLICATION_SIGN_P_KEY.equals(key) ||
CalculatorEngine.ROUND_RESULT_P_KEY.equals(key) || CalculatorEngine.ROUND_RESULT_P_KEY.equals(key) ||
CalculatorEngine.RESULT_PRECISION_P_KEY.equals(key) || CalculatorEngine.RESULT_PRECISION_P_KEY.equals(key) ||
CalculatorEngine.ANGLE_UNITS_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); CalculatorEngine.instance.reset(this, preferences);
this.calculatorModel.evaluate(); 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 * @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) { 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) { 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 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 String ROUND_RESULT_P_KEY = "org.solovyev.android.calculator.CalculatorModel_round_result";
public static final boolean ROUND_RESULT_DEFAULT = true; 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_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_angle_units";
public static final String ANGLE_UNITS_DEFAULT = "deg"; public static final String ANGLE_UNITS_DEFAULT = "deg";
public static final int DEFAULT_TIMEOUT = 3000; public static final int DEFAULT_TIMEOUT = 3000;
@NotNull @NotNull
@ -76,11 +80,23 @@ public enum CalculatorEngine {
// calculation thread timeout in milliseconds, after timeout thread would be interrupted // calculation thread timeout in milliseconds, after timeout thread would be interrupted
private int timeout = DEFAULT_TIMEOUT; private int timeout = DEFAULT_TIMEOUT;
@NotNull
private String multiplicationSign = MULTIPLICATION_SIGN_DEFAULT;
CalculatorEngine() { CalculatorEngine() {
this.engine.setRoundResult(true); this.engine.setRoundResult(true);
this.engine.setUseGroupingSeparator(true); this.engine.setUseGroupingSeparator(true);
} }
@NotNull
public String getMultiplicationSign() {
return multiplicationSign;
}
public void setMultiplicationSign(@NotNull String multiplicationSign) {
this.multiplicationSign = multiplicationSign;
}
public static class Result { public static class Result {
@NotNull @NotNull
@ -256,6 +272,7 @@ public enum CalculatorEngine {
this.setRoundResult(preferences.getBoolean(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT)); this.setRoundResult(preferences.getBoolean(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT));
this.setAngleUnits(getAngleUnitsFromPrefs(preferences)); this.setAngleUnits(getAngleUnitsFromPrefs(preferences));
this.setNumeralBase(getNumeralBaseFromPrefs(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); final String groupingSeparator = preferences.getString(GROUPING_SEPARATOR_P_KEY, JsclMathEngine.GROUPING_SEPARATOR_DEFAULT);
if (StringUtils.isEmpty(groupingSeparator)) { 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())) { if (needMultiplicationSign(mathTypeBefore == null ? null : mathTypeBefore.getMathType(), mathTypeAfter == null ? null : mathTypeAfter.getMathType())) {
sb.append("×"); sb.append(CalculatorEngine.instance.getMultiplicationSign());
} }
} else { } else {

View File

@ -90,7 +90,7 @@ public class ColorButton extends Button {
feedbackPaint.setStrokeWidth(2); 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)); getPaint().setColor(resources.getColor(R.color.button_operator_text_color));
} else if (getText().toString().equals("C")) { } else if (getText().toString().equals("C")) {
getPaint().setColor(resources.getColor(R.color.button_ce_text_color)); getPaint().setColor(resources.getColor(R.color.button_ce_text_color));

View File

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