Decrease precision in ENG mode and migrate the settings

This commit is contained in:
serso 2017-07-26 10:07:32 +02:00
parent fa9288ada1
commit 3c03f3948d
3 changed files with 23 additions and 10 deletions

View File

@ -31,6 +31,7 @@ import android.text.TextUtils;
import com.squareup.otto.Bus;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.Preferences.Gui;
import org.solovyev.android.calculator.functions.FunctionsRegistry;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.operators.OperatorsRegistry;
@ -211,7 +212,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
if (preferences.contains("org.solovyev.android.calculator.CalculatorModel_round_result")) {
final boolean round = preferences.getBoolean("org.solovyev.android.calculator.CalculatorModel_round_result", true);
if (!round) {
Preferences.Output.precision.putPreference(editor, NumberFormatter.MAX_PRECISION);
Preferences.Output.precision.putPreference(editor, NumberFormatter.ENG_PRECISION);
}
}
// #initPreferences rely on all changes to be committed
@ -226,7 +227,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
if (preferences.contains("engine.output.round")) {
final boolean round = preferences.getBoolean("engine.output.round", true);
if (!round) {
Preferences.Output.precision.putPreference(editor, NumberFormatter.MAX_PRECISION);
Preferences.Output.precision.putPreference(editor, NumberFormatter.ENG_PRECISION);
}
}
// #initPreferences rely on all changes to be committed
@ -235,6 +236,16 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
// 1. It was forgotten for 0 version
// 2. There is a bunch of new preferences
initPreferences(editor);
} else if (oldVersion == 2) {
final Integer precision = Preferences.Output.precision.getPreference(preferences);
final Gui.Mode mode = Gui.mode.getPreference(preferences);
if (precision == NumberFormatter.MAX_PRECISION && mode == Gui.Mode.engineer) {
// this might reset a user set value but:
// 1. It's done only once
// 2. Most of the people will be happy with this change (worst case scenario -
// precision is set back to MAX_PRECISION again)
Preferences.Output.precision.putPreference(editor, NumberFormatter.ENG_PRECISION);
}
}
Preferences.version.putDefault(editor);
editor.apply();
@ -322,7 +333,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
public static final StringPreference<String> multiplicationSign = StringPreference.of("engine.multiplicationSign", "×");
public static final StringPreference<NumeralBase> numeralBase = StringPreference.ofTypedValue("engine.numeralBase", "dec", EnumMapper.of(NumeralBase.class));
public static final StringPreference<AngleUnit> angleUnit = StringPreference.ofTypedValue("engine.angleUnit", "deg", EnumMapper.of(AngleUnit.class));
public static final Preference<Integer> version = IntegerPreference.of("engine.version", 2);
public static final Preference<Integer> version = IntegerPreference.of("engine.version", 3);
private static final List<String> preferenceKeys = new ArrayList<>();
static {

View File

@ -56,7 +56,7 @@ enum CalculatorMode {
Preferences.Gui.mode.putPreference(editor, Preferences.Gui.Mode.engineer);
Engine.Preferences.angleUnit.putPreference(editor, AngleUnit.rad);
Engine.Preferences.Output.notation.putPreference(editor, Engine.Notation.eng);
Engine.Preferences.Output.precision.putPreference(editor, NumberFormatter.MAX_PRECISION);
Engine.Preferences.Output.precision.putPreference(editor, NumberFormatter.ENG_PRECISION);
editor.apply();
}

View File

@ -1,5 +1,12 @@
package org.solovyev.common;
import static java.lang.Math.pow;
import static midpcalc.Real.NumberFormat.FSE_ENG;
import static midpcalc.Real.NumberFormat.FSE_FIX;
import static midpcalc.Real.NumberFormat.FSE_NONE;
import static midpcalc.Real.NumberFormat.FSE_SCI;
import java.math.BigDecimal;
import java.math.BigInteger;
@ -7,12 +14,6 @@ import javax.annotation.Nonnull;
import midpcalc.Real;
import static java.lang.Math.pow;
import static midpcalc.Real.NumberFormat.FSE_ENG;
import static midpcalc.Real.NumberFormat.FSE_FIX;
import static midpcalc.Real.NumberFormat.FSE_NONE;
import static midpcalc.Real.NumberFormat.FSE_SCI;
public class NumberFormatter {
public static final char NO_GROUPING = 0;
@ -20,6 +21,7 @@ public class NumberFormatter {
public static final int DEFAULT_MAGNITUDE = 5;
public static final int MIN_PRECISION = 1;
public static final int MAX_PRECISION = 15;
public static final int ENG_PRECISION = 10;
private final Real.NumberFormat numberFormat = new Real.NumberFormat();
private final Real real = new Real();