angle units
This commit is contained in:
@@ -37,7 +37,10 @@ import org.solovyev.common.utils.history.HistoryAction;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@@ -164,6 +167,12 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
if (!preferences.contains(CalculatorEngine.ANGLE_UNITS_P_KEY)) {
|
||||
final SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putString(CalculatorEngine.ANGLE_UNITS_P_KEY, CalculatorEngine.ANGLE_UNITS_DEFAULT);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void setOnDragListeners(@NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
|
||||
@@ -491,7 +500,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
if (CalculatorEngine.GROUPING_SEPARATOR_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.instance.reset(this, preferences);
|
||||
this.calculatorModel.evaluate();
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ package org.solovyev.android.calculator.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import jscl.AngleUnits;
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.MathEngine;
|
||||
import jscl.math.function.Function;
|
||||
@@ -47,6 +48,9 @@ public enum CalculatorEngine {
|
||||
public static final String RESULT_PRECISION_P_KEY = "org.solovyev.android.calculator.CalculatorModel_result_precision";
|
||||
public static final String RESULT_PRECISION_DEFAULT = "5";
|
||||
|
||||
public static final String ANGLE_UNITS_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_angle_units";
|
||||
public static final String ANGLE_UNITS_DEFAULT = "deg";
|
||||
|
||||
@NotNull
|
||||
private final Object lock = new Object();
|
||||
|
||||
@@ -55,7 +59,7 @@ public enum CalculatorEngine {
|
||||
private int precision = 5;
|
||||
|
||||
@NotNull
|
||||
private MathEngine engine = new JsclMathEngine();
|
||||
private MathEngine engine = JsclMathEngine.instance;
|
||||
|
||||
@NotNull
|
||||
public final TextProcessor<PreparedExpression> preprocessor = new ToJsclTextProcessor();
|
||||
@@ -270,6 +274,7 @@ public enum CalculatorEngine {
|
||||
//noinspection ConstantConditions
|
||||
this.setPrecision(integerNumberMapper.parseValue(preferences.getString(RESULT_PRECISION_P_KEY, RESULT_PRECISION_DEFAULT)));
|
||||
this.setRoundResult(preferences.getBoolean(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT));
|
||||
this.setDefaultAngleUnits(AngleUnits.valueOf(preferences.getString(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT)));
|
||||
|
||||
final String groupingSeparator = preferences.getString(GROUPING_SEPARATOR_P_KEY, GROUPING_SEPARATOR_DEFAULT);
|
||||
if (StringUtils.isEmpty(groupingSeparator)) {
|
||||
@@ -321,6 +326,10 @@ public enum CalculatorEngine {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public void setDefaultAngleUnits(@NotNull AngleUnits angleUnits) {
|
||||
getEngine().setDefaultAngleUnits(angleUnits);
|
||||
}
|
||||
|
||||
// for tests only
|
||||
void setThreadKiller(@NotNull ThreadKiller threadKiller) {
|
||||
this.threadKiller = threadKiller;
|
||||
|
Reference in New Issue
Block a user