fixes
This commit is contained in:
+1
-2
@@ -57,6 +57,7 @@ public class CalculatorApplication extends android.app.Application {
|
||||
ACRA.init(this);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
CalculatorPreferences.setDefaultValues(preferences);
|
||||
|
||||
setTheme(preferences);
|
||||
|
||||
@@ -84,8 +85,6 @@ public class CalculatorApplication extends android.app.Application {
|
||||
return CalculatorSecurity.getPK();
|
||||
}
|
||||
});
|
||||
|
||||
CalculatorPreferences.setDefaultValues(preferences);
|
||||
}
|
||||
|
||||
private void setTheme(@NotNull SharedPreferences preferences) {
|
||||
|
||||
+164
-142
@@ -1,142 +1,164 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.plot.GraphLineColor;
|
||||
import org.solovyev.android.prefs.BooleanPreference;
|
||||
import org.solovyev.android.prefs.IntegerPreference;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
import org.solovyev.android.prefs.StringPreference;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/20/12
|
||||
* Time: 12:42 PM
|
||||
*/
|
||||
public final class CalculatorPreferences {
|
||||
|
||||
private CalculatorPreferences() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final Preference<Integer> appVersion = new IntegerPreference("application.version", -1);
|
||||
public static final Preference<Integer> appOpenedCounter = new IntegerPreference("app_opened_counter", 0);
|
||||
|
||||
public static class Gui {
|
||||
|
||||
public static final Preference<Theme> theme = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class);
|
||||
public static final Preference<Layout> layout = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.main_calculator, Layout.class);
|
||||
public static final Preference<Boolean> feedbackWindowShown = new BooleanPreference("feedback_window_shown", false);
|
||||
public static final Preference<Boolean> notesppAnnounceShown = new BooleanPreference("notespp_announce_shown", false);
|
||||
public static final Preference<Boolean> showReleaseNotes = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
|
||||
public static final Preference<Boolean> usePrevAsBack = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
|
||||
public static final Preference<Boolean> showEqualsButton = new BooleanPreference("showEqualsButton", true);
|
||||
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
|
||||
public static final Preference<Boolean> hideNumeralBaseDigits = new BooleanPreference("hideNumeralBaseDigits", true);
|
||||
|
||||
@NotNull
|
||||
public static Theme getTheme(@NotNull SharedPreferences preferences) {
|
||||
return theme.getPreferenceNoError(preferences);
|
||||
}
|
||||
|
||||
public static enum Theme {
|
||||
|
||||
default_theme(ThemeType.other, R.style.default_theme),
|
||||
violet_theme(ThemeType.other, R.style.violet_theme),
|
||||
light_blue_theme(ThemeType.other, R.style.light_blue_theme),
|
||||
metro_blue_theme(ThemeType.metro, R.style.metro_blue_theme),
|
||||
metro_purple_theme(ThemeType.metro, R.style.metro_purple_theme),
|
||||
metro_green_theme(ThemeType.metro, R.style.metro_green_theme);
|
||||
|
||||
@NotNull
|
||||
private final ThemeType themeType;
|
||||
|
||||
@NotNull
|
||||
private final Integer themeId;
|
||||
|
||||
Theme(@NotNull ThemeType themeType, Integer themeId) {
|
||||
this.themeType = themeType;
|
||||
this.themeId = themeId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ThemeType getThemeType() {
|
||||
return themeType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Integer getThemeId() {
|
||||
return themeId;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ThemeType {
|
||||
metro,
|
||||
other
|
||||
}
|
||||
|
||||
public static enum Layout {
|
||||
main_calculator(R.layout.main_calculator),
|
||||
main_cellphone(R.layout.main_cellphone),
|
||||
simple(R.layout.main_calculator);
|
||||
|
||||
private final int layoutId;
|
||||
|
||||
Layout(int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
}
|
||||
|
||||
public int getLayoutId() {
|
||||
return layoutId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Graph {
|
||||
public static final Preference<Boolean> interpolate = new BooleanPreference("graph_interpolate", true);
|
||||
public static final Preference<GraphLineColor> lineColorReal = StringPreference.newInstance("graph_line_color_real", GraphLineColor.white, GraphLineColor.class);
|
||||
public static final Preference<GraphLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", GraphLineColor.blue, GraphLineColor.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void setDefaultValues(@NotNull SharedPreferences preferences) {
|
||||
if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
if (locale != null) {
|
||||
final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
|
||||
int index = MathType.grouping_separator.getTokens().indexOf(String.valueOf(decimalFormatSymbols.getGroupingSeparator()));
|
||||
final String groupingSeparator;
|
||||
if (index >= 0) {
|
||||
groupingSeparator = MathType.grouping_separator.getTokens().get(index);
|
||||
} else {
|
||||
groupingSeparator = " ";
|
||||
}
|
||||
|
||||
AndroidCalculatorEngine.Preferences.groupingSeparator.putPreference(preferences, groupingSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.angleUnit.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.numeralBase.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.numeralBase.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.multiplicationSign.isSet(preferences)) {
|
||||
if ( AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s) || AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s_2) ) {
|
||||
// workaround ofr samsung galaxy s phones
|
||||
AndroidCalculatorEngine.Preferences.multiplicationSign.putPreference(preferences, "*");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.plot.GraphLineColor;
|
||||
import org.solovyev.android.prefs.BooleanPreference;
|
||||
import org.solovyev.android.prefs.IntegerPreference;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
import org.solovyev.android.prefs.StringPreference;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/20/12
|
||||
* Time: 12:42 PM
|
||||
*/
|
||||
public final class CalculatorPreferences {
|
||||
|
||||
private CalculatorPreferences() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final Preference<Integer> appVersion = new IntegerPreference("application.version", -1);
|
||||
public static final Preference<Integer> appOpenedCounter = new IntegerPreference("app_opened_counter", 0);
|
||||
|
||||
public static class Gui {
|
||||
|
||||
public static final Preference<Theme> theme = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class);
|
||||
public static final Preference<Layout> layout = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.main_calculator, Layout.class);
|
||||
public static final Preference<Boolean> feedbackWindowShown = new BooleanPreference("feedback_window_shown", false);
|
||||
public static final Preference<Boolean> notesppAnnounceShown = new BooleanPreference("notespp_announce_shown", false);
|
||||
public static final Preference<Boolean> showReleaseNotes = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
|
||||
public static final Preference<Boolean> usePrevAsBack = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
|
||||
public static final Preference<Boolean> showEqualsButton = new BooleanPreference("showEqualsButton", true);
|
||||
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
|
||||
public static final Preference<Boolean> hideNumeralBaseDigits = new BooleanPreference("hideNumeralBaseDigits", true);
|
||||
|
||||
@NotNull
|
||||
public static Theme getTheme(@NotNull SharedPreferences preferences) {
|
||||
return theme.getPreferenceNoError(preferences);
|
||||
}
|
||||
|
||||
public static enum Theme {
|
||||
|
||||
default_theme(ThemeType.other, R.style.default_theme),
|
||||
violet_theme(ThemeType.other, R.style.violet_theme),
|
||||
light_blue_theme(ThemeType.other, R.style.light_blue_theme),
|
||||
metro_blue_theme(ThemeType.metro, R.style.metro_blue_theme),
|
||||
metro_purple_theme(ThemeType.metro, R.style.metro_purple_theme),
|
||||
metro_green_theme(ThemeType.metro, R.style.metro_green_theme);
|
||||
|
||||
@NotNull
|
||||
private final ThemeType themeType;
|
||||
|
||||
@NotNull
|
||||
private final Integer themeId;
|
||||
|
||||
Theme(@NotNull ThemeType themeType, Integer themeId) {
|
||||
this.themeType = themeType;
|
||||
this.themeId = themeId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ThemeType getThemeType() {
|
||||
return themeType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Integer getThemeId() {
|
||||
return themeId;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ThemeType {
|
||||
metro,
|
||||
other
|
||||
}
|
||||
|
||||
public static enum Layout {
|
||||
main_calculator(R.layout.main_calculator),
|
||||
main_cellphone(R.layout.main_cellphone),
|
||||
simple(R.layout.main_calculator);
|
||||
|
||||
private final int layoutId;
|
||||
|
||||
Layout(int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
}
|
||||
|
||||
public int getLayoutId() {
|
||||
return layoutId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Graph {
|
||||
public static final Preference<Boolean> interpolate = new BooleanPreference("graph_interpolate", true);
|
||||
public static final Preference<GraphLineColor> lineColorReal = StringPreference.newInstance("graph_line_color_real", GraphLineColor.white, GraphLineColor.class);
|
||||
public static final Preference<GraphLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", GraphLineColor.blue, GraphLineColor.class);
|
||||
}
|
||||
|
||||
|
||||
static void setDefaultValues(@NotNull SharedPreferences preferences) {
|
||||
if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
if (locale != null) {
|
||||
final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
|
||||
int index = MathType.grouping_separator.getTokens().indexOf(String.valueOf(decimalFormatSymbols.getGroupingSeparator()));
|
||||
final String groupingSeparator;
|
||||
if (index >= 0) {
|
||||
groupingSeparator = MathType.grouping_separator.getTokens().get(index);
|
||||
} else {
|
||||
groupingSeparator = " ";
|
||||
}
|
||||
|
||||
AndroidCalculatorEngine.Preferences.groupingSeparator.putPreference(preferences, groupingSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.angleUnit.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.numeralBase.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.numeralBase.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.multiplicationSign.isSet(preferences)) {
|
||||
if ( AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s) || AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s_2) ) {
|
||||
// workaround ofr samsung galaxy s phones
|
||||
AndroidCalculatorEngine.Preferences.multiplicationSign.putPreference(preferences, "*");
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultPreference(preferences, Gui.theme);
|
||||
applyDefaultPreference(preferences, Gui.layout);
|
||||
applyDefaultPreference(preferences, Gui.feedbackWindowShown);
|
||||
applyDefaultPreference(preferences, Gui.notesppAnnounceShown);
|
||||
applyDefaultPreference(preferences, Gui.showReleaseNotes);
|
||||
applyDefaultPreference(preferences, Gui.usePrevAsBack);
|
||||
applyDefaultPreference(preferences, Gui.showEqualsButton);
|
||||
applyDefaultPreference(preferences, Gui.autoOrientation);
|
||||
applyDefaultPreference(preferences, Gui.hideNumeralBaseDigits);
|
||||
applyDefaultPreference(preferences, Gui.theme);
|
||||
applyDefaultPreference(preferences, Gui.theme);
|
||||
|
||||
applyDefaultPreference(preferences, Graph.interpolate);
|
||||
applyDefaultPreference(preferences, Graph.lineColorImag);
|
||||
applyDefaultPreference(preferences, Graph.lineColorReal);
|
||||
|
||||
}
|
||||
|
||||
private static void applyDefaultPreference(@NotNull SharedPreferences preferences, @NotNull Preference<?> preference) {
|
||||
if (!preference.isSet(preferences)) {
|
||||
preference.putDefault(preferences);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.CalculatorActivity;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
@@ -50,9 +50,9 @@ public class CalculatorReleaseNotesFragment extends CalculatorFragment {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
final String releaseNotesForTitle = context.getString(R.string.c_release_notes_for_title);
|
||||
final int version = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
|
||||
final int version = AndroidUtils.getAppVersionCode(context, CalculatorApplication.class.getPackage().getName());
|
||||
|
||||
final TextHelper textHelper = new TextHelper(context.getResources(), R.class.getPackage().getName());
|
||||
final TextHelper textHelper = new TextHelper(context.getResources(), CalculatorApplication.class.getPackage().getName());
|
||||
|
||||
boolean first = true;
|
||||
for ( int i = version; i >= minVersion; i-- ) {
|
||||
|
||||
+8
-5
@@ -6,12 +6,15 @@ import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.ToJsclTextProcessor;
|
||||
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
|
||||
import org.solovyev.math.units.Unit;
|
||||
import org.solovyev.math.units.UnitImpl;
|
||||
import org.solovyev.common.MutableObject;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
import org.solovyev.math.units.Unit;
|
||||
import org.solovyev.math.units.UnitImpl;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -64,8 +67,8 @@ public class NumeralBaseConverterDialog {
|
||||
public void onClick(@NotNull Unit<String> fromUnits, @NotNull Unit<String> toUnits) {
|
||||
String toUnitsValue = toUnits.getValue();
|
||||
|
||||
if (!toUnits.getUnitType().equals(AndroidNumeralBase.valueOf(CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase()))) {
|
||||
toUnitsValue = ((AndroidNumeralBase) toUnits.getUnitType()).getNumeralBase().getJsclPrefix() + toUnitsValue;
|
||||
if (!toUnits.getUnitType().equals(CalculatorNumeralBase.valueOf(CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase()))) {
|
||||
toUnitsValue = ((CalculatorNumeralBase) toUnits.getUnitType()).getNumeralBase().getJsclPrefix() + toUnitsValue;
|
||||
}
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(toUnitsValue);
|
||||
|
||||
Reference in New Issue
Block a user