From 47080454edeff44b6b5c37bbe5e63202a1e55aac Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 6 Dec 2011 16:32:10 +0400 Subject: [PATCH] android_calculator-15: Add numeral systems --- res/values-ru/strings.xml | 9 ++++++++- res/values/arrays.xml | 13 +++++++++++++ res/values/default_values.xml | 3 +++ res/values/strings.xml | 7 +++++++ res/xml/main_preferences.xml | 6 ++++++ .../android/calculator/model/CalculatorEngine.java | 14 ++++++++++++-- .../android/view/widgets/AngleUnitsButton.java | 2 +- 7 files changed, 50 insertions(+), 4 deletions(-) diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml index 7e5d5a91..bf20fde7 100644 --- a/res/values-ru/strings.xml +++ b/res/values-ru/strings.xml @@ -102,7 +102,14 @@ Радианы Грады Обороты - Определяет единицы измерения углов. + Устанавливает единицы измерения углов. + + Системы счичления + Устанавливает систему счисления для всех вводимых чисел. + Десятичная + Шестнадцатеричная + Восьмиричная + Бинарная Тема оформления По умолчанию diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 889dad94..83dd1ce1 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -60,4 +60,17 @@ turns + + @string/p_dec + @string/p_hex + @string/p_oct + @string/p_bin + + + dec + hex + oct + bin + + \ No newline at end of file diff --git a/res/values/default_values.xml b/res/values/default_values.xml index e50b56ad..fb28c9bc 100644 --- a/res/values/default_values.xml +++ b/res/values/default_values.xml @@ -30,6 +30,9 @@ org.solovyev.android.calculator.CalculatorActivity_angle_units deg + org.solovyev.android.calculator.CalculatorActivity_numeral_bases + dec + org.solovyev.android.calculator.CalculatorActivity_calc_theme default_theme diff --git a/res/values/strings.xml b/res/values/strings.xml index aef26ab0..c55ab36c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -105,6 +105,13 @@ Turns Defines the default units for angles. + Numeral systems + Defines the default numeral system for all input numbers. + Decimal + Hexadecimal + Octal + Binary + Theme Default Violet diff --git a/res/xml/main_preferences.xml b/res/xml/main_preferences.xml index ea7bd32c..ceb9c06e 100644 --- a/res/xml/main_preferences.xml +++ b/res/xml/main_preferences.xml @@ -29,6 +29,12 @@ a:summary="@string/c_angle_units_summary" a:entryValues="@array/p_angle_units"/> + + 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 f98d89ac..ae689bbb 100644 --- a/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java +++ b/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java @@ -10,6 +10,7 @@ import android.content.SharedPreferences; import jscl.AngleUnit; import jscl.JsclMathEngine; import jscl.MathEngine; +import jscl.NumeralBase; import jscl.math.Generic; import jscl.math.function.Function; import jscl.math.operator.Operator; @@ -48,8 +49,12 @@ 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 NUMERAL_BASES_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_numeral_bases"; + public static final String NUMERAL_BASES_DEFAULT = "dec"; + 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 @@ -285,7 +290,8 @@ 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(AngleUnit.valueOf(preferences.getString(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT))); + this.setAngleUnits(AngleUnit.valueOf(preferences.getString(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT))); + this.setNumeralBase(NumeralBase.valueOf(preferences.getString(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT))); final String groupingSeparator = preferences.getString(GROUPING_SEPARATOR_P_KEY, GROUPING_SEPARATOR_DEFAULT); if (StringUtils.isEmpty(groupingSeparator)) { @@ -337,10 +343,14 @@ public enum CalculatorEngine { this.timeout = timeout; } - public void setDefaultAngleUnits(@NotNull AngleUnit angleUnits) { + public void setAngleUnits(@NotNull AngleUnit angleUnits) { getEngine().setAngleUnits(angleUnits); } + public void setNumeralBase(@NotNull NumeralBase numeralBase) { + getEngine().setNumeralBase(numeralBase); + } + // for tests only void setThreadKiller(@NotNull ThreadKiller threadKiller) { this.threadKiller = threadKiller; diff --git a/src/main/java/org/solovyev/android/view/widgets/AngleUnitsButton.java b/src/main/java/org/solovyev/android/view/widgets/AngleUnitsButton.java index 1b606431..e8fdc727 100644 --- a/src/main/java/org/solovyev/android/view/widgets/AngleUnitsButton.java +++ b/src/main/java/org/solovyev/android/view/widgets/AngleUnitsButton.java @@ -34,7 +34,7 @@ public class AngleUnitsButton extends DirectionDragButton { if (result != null) { final Resources resources = getResources(); - if ( CalculatorEngine.instance.getEngine().getDefaultAngleUnit().name().equals(getDirectionText(direction)) ) { + if ( CalculatorEngine.instance.getEngine().getAngleUnits().name().equals(getDirectionText(direction)) ) { result.setColor(resources.getColor(R.color.selected_angle_unit_text_color)); } else { result.setColor(resources.getColor(R.color.default_text_color));