android_calculator-34: Calculation of iterative data is too slow
This commit is contained in:
parent
8b23c532da
commit
9fcbda6458
@ -45,6 +45,8 @@
|
||||
<string name="c_calc_science_notation_title">Результат в научной форме</string>
|
||||
<string name="c_calc_science_notation_summary">Если включено - результат будет всегда записан в научной форме (12.34E-12)</string>
|
||||
<string name="p_calc_result_precision_title">Точность результата</string>
|
||||
<string name="p_calc_max_calculation_time_title">Максимальное время вычисления</string>
|
||||
<string name="p_calc_max_calculation_time_summary">Если вычисления превысят установленный предел - калькулятор остановится с ошибкой</string>
|
||||
<string name="c_exit">Выход</string>
|
||||
<string name="c_add">Добавить</string>
|
||||
<string name="c_cancel">Отмена</string>
|
||||
|
@ -18,6 +18,9 @@
|
||||
<string name="p_calc_result_precision_key">org.solovyev.android.calculator.CalculatorModel_result_precision</string>
|
||||
<string name="p_calc_result_precision">5</string>
|
||||
|
||||
<string name="p_calc_max_calculation_time_key">calculation.max_calculation_time</string>
|
||||
<string name="p_calc_max_calculation_time">5</string>
|
||||
|
||||
<string name="p_calc_color_display_key">org.solovyev.android.calculator.CalculatorModel_color_display</string>
|
||||
<string name="p_calc_color_display">true</string>
|
||||
|
||||
|
@ -45,6 +45,8 @@
|
||||
<string name="c_calc_science_notation_title">Always scientific notation</string>
|
||||
<string name="c_calc_science_notation_summary">If turned on forces to use only scientific notation of output (12.34E-12)</string>
|
||||
<string name="p_calc_result_precision_title">Precision of result</string>
|
||||
<string name="p_calc_max_calculation_time_title">Maximum calculation time</string>
|
||||
<string name="p_calc_max_calculation_time_summary">If calculations exceed specified limit - calculator halts with error</string>
|
||||
<string name="c_exit">Exit</string>
|
||||
<string name="c_add">Add</string>
|
||||
<string name="c_cancel">Cancel</string>
|
||||
|
@ -53,6 +53,13 @@
|
||||
a:summary="@string/c_numeral_bases_summary"
|
||||
a:entryValues="@array/p_numeral_bases"/>
|
||||
|
||||
<org.solovyev.android.prefs.NumberPickerDialogPreference
|
||||
a:key="@string/p_calc_max_calculation_time_key"
|
||||
a:title="@string/p_calc_max_calculation_time_title"
|
||||
a:summary="@string/p_calc_max_calculation_time_summary"
|
||||
a:defaultValue="5"
|
||||
range:boundaries="3;1000"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
|
@ -793,7 +793,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
if (CalculatorEngine.Preferences.getPreferenceKeys().contains(key)) {
|
||||
CalculatorEngine.instance.softReset(this, preferences);
|
||||
this.calculatorModel.evaluate();
|
||||
//this.calculatorModel.evaluate();
|
||||
}
|
||||
|
||||
if ( USE_BACK_AS_PREV_P_KEY.equals(key) ) {
|
||||
|
@ -47,6 +47,9 @@ public enum CalculatorEngine {
|
||||
private static final String MULTIPLICATION_SIGN_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign";
|
||||
private static final String MULTIPLICATION_SIGN_DEFAULT = "×";
|
||||
|
||||
private static final String MAX_CALCULATION_TIME_P_KEY = "calculation.max_calculation_time";
|
||||
private static final String MAX_CALCULATION_TIME_DEFAULT = "5";
|
||||
|
||||
private static final String SCIENCE_NOTATION_P_KEY = "calculation.output.science_notation";
|
||||
private static final boolean SCIENCE_NOTATION_DEFAULT = false;
|
||||
|
||||
@ -70,6 +73,7 @@ public enum CalculatorEngine {
|
||||
public static final Preference<NumeralBase> numeralBase = StringPreference.newInstance(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.newInstance(NumeralBase.class));
|
||||
public static final Preference<AngleUnit> angleUnit = StringPreference.newInstance(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.newInstance(AngleUnit.class));
|
||||
public static final Preference<Boolean> scienceNotation = new BooleanPreference(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
|
||||
public static final Preference<Integer> maxCalculationTime = StringPreference.newInstance(MAX_CALCULATION_TIME_P_KEY, MAX_CALCULATION_TIME_DEFAULT, new NumberMapper<Integer>(Integer.class));
|
||||
|
||||
private static final List<String> preferenceKeys = new ArrayList<String>();
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user