From 9cb7adbd272597d05b88d4ec061901581cdc027e Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 23 Oct 2011 20:36:32 +0400 Subject: [PATCH] default grouping separator + degree is closed --- res/layout/calc_plus_button.xml | 1 - .../calculator/CalculatorActivity.java | 28 ++++++++++++++++--- .../android/calculator/math/MathType.java | 8 +++++- .../calculator/model/CalculatorEngine.java | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/res/layout/calc_plus_button.xml b/res/layout/calc_plus_button.xml index 17c9dbe6..3c976b70 100644 --- a/res/layout/calc_plus_button.xml +++ b/res/layout/calc_plus_button.xml @@ -9,7 +9,6 @@ xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator" a:id="@+id/plusButton" calc:directionTextScale="0.5" - calc:textUp="°" a:text="+" style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index c01aefd6..4df26af9 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -23,6 +23,7 @@ import android.widget.TextView; import bsh.EvalError; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.model.CalculatorEngine; import org.solovyev.android.msg.AndroidMessageRegistry; import org.solovyev.android.view.FontSizeAdjuster; @@ -33,10 +34,8 @@ import org.solovyev.common.utils.history.HistoryAction; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.text.DecimalFormatSymbols; +import java.util.*; public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { @@ -68,6 +67,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); + setDefaultValues(preferences); + setTheme(preferences); super.onCreate(savedInstanceState); setContentView(R.layout.main); @@ -96,6 +97,25 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh preferences.registerOnSharedPreferenceChangeListener(this); } + private void setDefaultValues(@NotNull SharedPreferences preferences) { + if ( !preferences.contains(CalculatorEngine.GROUPING_SEPARATOR_P_KEY) ) { + final Locale locale = Locale.getDefault(); + if ( locale != null ) { + final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale); + int index = MathType.grouping_separator.getTokens().indexOf(String.valueOf(decimalFormatSymbols.getGroupingSeparator())); + final String groupingSeparator; + if ( index >= 0 ) { + groupingSeparator = MathType.grouping_separator.getTokens().get(index); + } else { + groupingSeparator = " "; + } + final SharedPreferences.Editor editor = preferences.edit(); + editor.putString(CalculatorEngine.GROUPING_SEPARATOR_P_KEY, groupingSeparator); + editor.commit(); + } + } + } + private synchronized void setOnDragListeners(@NotNull SimpleOnDragListener.Preferences dragPreferences) { final SimpleOnDragListener onDragListener = new SimpleOnDragListener(new DigitButtonDragProcessor(calculatorModel), dragPreferences); dpclRegister.addListener(onDragListener); diff --git a/src/main/java/org/solovyev/android/calculator/math/MathType.java b/src/main/java/org/solovyev/android/calculator/math/MathType.java index 078b964f..159192a4 100644 --- a/src/main/java/org/solovyev/android/calculator/math/MathType.java +++ b/src/main/java/org/solovyev/android/calculator/math/MathType.java @@ -37,7 +37,12 @@ public enum MathType { } }, - grouping_separator(250, false, false, "'", " "), + grouping_separator(250, false, false, "'", " "){ + @Override + public int processToJscl(@NotNull StringBuilder result, int i, @NotNull String match) throws ParseException { + return i; + } + }, power_10(300, true, false, "E") { @Override @@ -47,6 +52,7 @@ public enum MathType { }, postfix_function(400, true, true, Functions.allPostfix) { + @Override protected String getSubstituteToJscl(@NotNull String match) { final String result; diff --git a/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java b/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java index 88589b7c..72eda675 100644 --- a/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java +++ b/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java @@ -41,7 +41,7 @@ public enum CalculatorEngine { instance; - private 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"; private static final String GROUPING_SEPARATOR_DEFAULT = " "; private static final String RESULT_PRECISION_P_KEY = "org.solovyev.android.calculator.CalculatorModel_result_precision";