default grouping separator + degree is closed

This commit is contained in:
serso 2011-10-23 20:36:32 +04:00
parent c8eda5176e
commit 9cb7adbd27
4 changed files with 32 additions and 7 deletions

View File

@ -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"/>

View File

@ -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);

View File

@ -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;

View File

@ -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";