diff --git a/res/values-ru/text_strings.xml b/res/values-ru/text_strings.xml
index 62619a59..b94f07cd 100644
--- a/res/values-ru/text_strings.xml
+++ b/res/values-ru/text_strings.xml
@@ -45,6 +45,8 @@
Результат в научной форме
Если включено - результат будет всегда записан в научной форме (12.34E-12)
Точность результата
+ Максимальное время вычисления
+ Если вычисления превысят установленный предел - калькулятор остановится с ошибкой
Выход
Добавить
Отмена
diff --git a/res/values/preferences.xml b/res/values/preferences.xml
index cc02369c..96e357f0 100644
--- a/res/values/preferences.xml
+++ b/res/values/preferences.xml
@@ -18,6 +18,9 @@
org.solovyev.android.calculator.CalculatorModel_result_precision
5
+ calculation.max_calculation_time
+ 5
+
org.solovyev.android.calculator.CalculatorModel_color_display
true
diff --git a/res/values/text_strings.xml b/res/values/text_strings.xml
index 5c54c916..41ca065f 100644
--- a/res/values/text_strings.xml
+++ b/res/values/text_strings.xml
@@ -45,6 +45,8 @@
Always scientific notation
If turned on forces to use only scientific notation of output (12.34E-12)
Precision of result
+ Maximum calculation time
+ If calculations exceed specified limit - calculator halts with error
Exit
Add
Cancel
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index ef3d6ce1..4a64e430 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -53,6 +53,13 @@
a:summary="@string/c_numeral_bases_summary"
a:entryValues="@array/p_numeral_bases"/>
+
+
numeralBase = StringPreference.newInstance(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.newInstance(NumeralBase.class));
public static final Preference angleUnit = StringPreference.newInstance(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.newInstance(AngleUnit.class));
public static final Preference scienceNotation = new BooleanPreference(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
+ public static final Preference maxCalculationTime = StringPreference.newInstance(MAX_CALCULATION_TIME_P_KEY, MAX_CALCULATION_TIME_DEFAULT, new NumberMapper(Integer.class));
private static final List preferenceKeys = new ArrayList();
@@ -81,6 +85,7 @@ public enum CalculatorEngine {
preferenceKeys.add(numeralBase.getKey());
preferenceKeys.add(angleUnit.getKey());
preferenceKeys.add(scienceNotation.getKey());
+ preferenceKeys.add(maxCalculationTime.getKey());
}
@NotNull
@@ -89,9 +94,6 @@ public enum CalculatorEngine {
}
}
-
- public static final int DEFAULT_TIMEOUT = 3000;
-
@NotNull
private final Object lock = new Object();
@@ -115,8 +117,8 @@ public enum CalculatorEngine {
@NotNull
private ThreadKiller threadKiller = new AndroidThreadKiller();
- // calculation thread timeout in milliseconds, after timeout thread would be interrupted
- private int timeout = DEFAULT_TIMEOUT;
+ // calculation thread timeout in seconds, after timeout thread would be interrupted
+ private int timeout = Integer.valueOf(MAX_CALCULATION_TIME_DEFAULT);
@NotNull
private String multiplicationSign = MULTIPLICATION_SIGN_DEFAULT;
@@ -245,7 +247,7 @@ public enum CalculatorEngine {
try {
//Log.d(CalculatorEngine.class.getName(), "Main thread is waiting: " + Thread.currentThread().getName());
- latch.await(timeout, TimeUnit.MILLISECONDS);
+ latch.await(timeout, TimeUnit.SECONDS);
//Log.d(CalculatorEngine.class.getName(), "Main thread got up: " + Thread.currentThread().getName());
final CalculatorParseException parseExceptionObject = parseException.getObject();
@@ -320,6 +322,7 @@ public enum CalculatorEngine {
this.setNumeralBase(getNumeralBaseFromPrefs(preferences));
this.setMultiplicationSign(Preferences.multiplicationSign.getPreference(preferences));
this.setScienceNotation(Preferences.scienceNotation.getPreference(preferences));
+ this.setTimeout(Preferences.maxCalculationTime.getPreference(preferences));
final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences);
if (StringUtils.isEmpty(groupingSeparator)) {
@@ -375,7 +378,7 @@ public enum CalculatorEngine {
return engine;
}
- // for tests
+ // package protected for tests
void setTimeout(int timeout) {
this.timeout = timeout;
}