From e87ac84323abf198a6ef070050730cbbda44e378 Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 29 Feb 2016 19:41:35 +0100 Subject: [PATCH] Preferences migrated --- .../calculator/CalculatorActivity.java | 27 +++------ .../android/calculator/Preferences.java | 55 +++++++++---------- .../calculator/keyboard/KeyboardUi.java | 16 ++---- .../keyboard/PartialKeyboardUi.java | 2 +- app/src/main/res/values/preferences.xml | 11 ---- app/src/main/res/xml/preferences_other.xml | 6 +- 6 files changed, 43 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 258e401c..bce4ee96 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -33,15 +33,11 @@ import android.support.v7.app.AlertDialog; import android.support.v7.widget.CardView; import android.support.v7.widget.Toolbar; import android.text.method.LinkMovementMethod; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; +import android.view.*; import android.widget.FrameLayout; import android.widget.TextView; - +import butterknife.Bind; +import butterknife.ButterKnife; import org.solovyev.android.Activities; import org.solovyev.android.Android; import org.solovyev.android.calculator.converter.ConverterFragment; @@ -57,17 +53,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; -import butterknife.Bind; -import butterknife.ButterKnife; - import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; import static org.solovyev.android.calculator.Preferences.Gui.keepScreenOn; import static org.solovyev.android.calculator.release.ReleaseNotes.hasReleaseNotes; -import static org.solovyev.android.wizard.WizardUi.continueWizard; -import static org.solovyev.android.wizard.WizardUi.createLaunchIntent; -import static org.solovyev.android.wizard.WizardUi.startWizard; +import static org.solovyev.android.wizard.WizardUi.*; public class CalculatorActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener, Toolbar.OnMenuItemClickListener { @@ -190,7 +181,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference toolbar.inflateMenu(R.menu.main); toolbar.setOnMenuItemClickListener(this); - useBackAsPrev = Preferences.Gui.usePrevAsBack.getPreference(preferences); + useBackAsPrev = Preferences.Gui.useBackAsPrevious.getPreference(preferences); if (savedInstanceState == null) { firstTimeInit(preferences, this); } @@ -260,17 +251,17 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference @Override public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) { - if (Preferences.Gui.usePrevAsBack.getKey().equals(key)) { - useBackAsPrev = Preferences.Gui.usePrevAsBack.getPreference(preferences); + if (Preferences.Gui.useBackAsPrevious.getKey().equals(key)) { + useBackAsPrev = Preferences.Gui.useBackAsPrevious.getPreference(preferences); } - if (Preferences.Gui.autoOrientation.getKey().equals(key)) { + if (Preferences.Gui.rotateScreen.getKey().equals(key)) { toggleOrientationChange(); } } private void toggleOrientationChange() { - if (Preferences.Gui.autoOrientation.getPreference(preferences)) { + if (Preferences.Gui.rotateScreen.getPreference(preferences)) { setRequestedOrientation(SCREEN_ORIENTATION_UNSPECIFIED); } else { setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT); diff --git a/app/src/main/java/org/solovyev/android/calculator/Preferences.java b/app/src/main/java/org/solovyev/android/calculator/Preferences.java index b6b41890..92c9569a 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Preferences.java +++ b/app/src/main/java/org/solovyev/android/calculator/Preferences.java @@ -35,7 +35,8 @@ import android.support.annotation.NonNull; import android.support.annotation.StyleRes; import android.util.SparseArray; import android.view.ContextThemeWrapper; - +import jscl.AngleUnit; +import jscl.NumeralBase; import org.solovyev.android.Check; import org.solovyev.android.calculator.about.AboutActivity; import org.solovyev.android.calculator.functions.FunctionsActivity; @@ -46,23 +47,15 @@ import org.solovyev.android.calculator.operators.OperatorsActivity; import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.variables.VariablesActivity; import org.solovyev.android.calculator.wizard.WizardActivity; -import org.solovyev.android.prefs.BooleanPreference; -import org.solovyev.android.prefs.IntegerPreference; -import org.solovyev.android.prefs.NumberToStringPreference; -import org.solovyev.android.prefs.Preference; -import org.solovyev.android.prefs.StringPreference; +import org.solovyev.android.prefs.*; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.text.DecimalFormatSymbols; import java.util.EnumMap; import java.util.Locale; import java.util.Map; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import jscl.AngleUnit; -import jscl.NumeralBase; - import static org.solovyev.android.Android.isPhoneModel; import static org.solovyev.android.DeviceModel.samsung_galaxy_s; import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2; @@ -82,8 +75,7 @@ public final class Preferences { final SharedPreferences.Editor editor = preferences.edit(); setInitialDefaultValues(application, preferences, editor); editor.apply(); - } else if (version > 143) { - // FIXME: 2016-02-20 use correct version + } else if (version <= 143) { final SharedPreferences.Editor editor = preferences.edit(); if (!Gui.vibrateOnKeypress.isSet(preferences)) { //noinspection deprecation @@ -91,9 +83,13 @@ public final class Preferences { } migratePreference(preferences, editor, Gui.highlightText, Deleted.colorDisplay); migratePreference(preferences, editor, Gui.keepScreenOn, Deleted.preventScreenFromFading); - migratePreference(preferences, editor, Gui.theme, Deleted.oldTheme); - migratePreference(preferences, editor, Gui.layout, Deleted.oldLayout); - final Gui.Layout layout = Deleted.oldLayout.getPreference(preferences); + migratePreference(preferences, editor, Gui.theme, Deleted.theme); + migratePreference(preferences, editor, Gui.layout, Deleted.layout); + migratePreference(preferences, editor, Gui.useBackAsPrevious, Deleted.usePrevAsBack); + migratePreference(preferences, editor, Gui.showReleaseNotes, Deleted.showReleaseNotes); + migratePreference(preferences, editor, Gui.showEqualsButton, Deleted.showEqualsButton); + migratePreference(preferences, editor, Gui.rotateScreen, Deleted.autoOrientation); + final Gui.Layout layout = Deleted.layout.getPreference(preferences); if (layout == Gui.Layout.main_cellphone) { Gui.layout.putDefault(editor); } else if (layout == Gui.Layout.main_calculator_mobile) { @@ -142,10 +138,9 @@ public final class Preferences { Gui.layout.tryPutDefault(preferences, editor); Gui.feedbackWindowShown.tryPutDefault(preferences, editor); Gui.showReleaseNotes.tryPutDefault(preferences, editor); - Gui.usePrevAsBack.tryPutDefault(preferences, editor); + Gui.useBackAsPrevious.tryPutDefault(preferences, editor); Gui.showEqualsButton.tryPutDefault(preferences, editor); - Gui.autoOrientation.tryPutDefault(preferences, editor); - Gui.hideNumeralBaseDigits.tryPutDefault(preferences, editor); + Gui.rotateScreen.tryPutDefault(preferences, editor); Gui.keepScreenOn.tryPutDefault(preferences, editor); Gui.language.tryPutDefault(preferences, editor); @@ -275,12 +270,9 @@ public final class Preferences { } public static class Calculations { - public static final Preference calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true); - public static final Preference preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", Engine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class); public static final Preference preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", Engine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class); - } public static class Gui { @@ -289,11 +281,10 @@ public final class Preferences { public static final Preference layout = StringPreference.ofEnum("gui.layout", Layout.simple, Layout.class); public static final Preference language = StringPreference.of("gui.language", Languages.SYSTEM_LANGUAGE_CODE); public static final Preference feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false); - public static final Preference showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true); - public static final Preference usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false); - public static final Preference showEqualsButton = BooleanPreference.of("showEqualsButton", true); - public static final Preference autoOrientation = BooleanPreference.of("autoOrientation", true); - public static final Preference hideNumeralBaseDigits = BooleanPreference.of("hideNumeralBaseDigits", true); + public static final Preference showReleaseNotes = BooleanPreference.of("gui.showReleaseNotes", true); + public static final Preference useBackAsPrevious = BooleanPreference.of("gui.useBackAsPrevious", false); + public static final Preference showEqualsButton = BooleanPreference.of("gui.showEqualsButton", true); + public static final Preference rotateScreen = BooleanPreference.of("gui.rotateScreen", true); public static final Preference keepScreenOn = BooleanPreference.of("gui.keepScreenOn", true); public static final Preference highlightText = BooleanPreference.of("gui.highlightText", true); public static final Preference vibrateOnKeypress = BooleanPreference.of("gui.vibrateOnKeypress", true); @@ -419,7 +410,11 @@ public final class Preferences { static final Preference hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class); static final Preference colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true); static final Preference preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true); - static final Preference oldTheme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Gui.Theme.material_theme, Gui.Theme.class); - static final Preference oldLayout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Gui.Layout.simple, Gui.Layout.class); + static final Preference theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Gui.Theme.material_theme, Gui.Theme.class); + static final Preference layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Gui.Layout.simple, Gui.Layout.class); + static final Preference showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true); + static final Preference usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false); + static final Preference showEqualsButton = BooleanPreference.of("showEqualsButton", true); + static final Preference autoOrientation = BooleanPreference.of("autoOrientation", true); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java index 365fdd54..813b7a18 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java @@ -15,7 +15,10 @@ import butterknife.Bind; import butterknife.ButterKnife; import jscl.AngleUnit; import jscl.NumeralBase; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.ActivityLauncher; +import org.solovyev.android.calculator.CppNumeralBase; +import org.solovyev.android.calculator.Engine; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.history.History; import org.solovyev.android.calculator.view.AngleUnitsButton; @@ -26,9 +29,7 @@ import org.solovyev.android.views.dragbutton.DragDirection; import javax.annotation.Nonnull; import javax.inject.Inject; -import static jscl.NumeralBase.hex; import static org.solovyev.android.calculator.Engine.Preferences.*; -import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits; import static org.solovyev.android.views.dragbutton.DragDirection.*; public class KeyboardUi extends BaseKeyboardUi { @@ -96,12 +97,7 @@ public class KeyboardUi extends BaseKeyboardUi { } public void toggleNumericDigits() { - if (hideNumeralBaseDigits.getPreference(preferences)) { - toggleNumericDigits(numeralBase.getPreference(preferences)); - } else { - // set HEX to show all digits - CppNumeralBase.valueOf(hex).toggleButtons(true, this); - } + toggleNumericDigits(numeralBase.getPreference(preferences)); } public void toggleNumericDigits(@Nonnull NumeralBase currentNumeralBase) { @@ -177,7 +173,7 @@ public class KeyboardUi extends BaseKeyboardUi { if (angleUnit.isSameKey(key)) { button6.setAngleUnit(angleUnit.getPreference(preferences)); } - if (numeralBase.isSameKey(key) || hideNumeralBaseDigits.isSameKey(key)) { + if (numeralBase.isSameKey(key)) { toggleNumericDigits(); } if (multiplicationSign.isSameKey(key)) { diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java index 571298fe..fd1014f2 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java @@ -87,7 +87,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi { if (equalsButton == null) { return; } - if (orientation != Configuration.ORIENTATION_PORTRAIT && Preferences.Gui.autoOrientation.getPreference(preferences)) { + if (orientation != Configuration.ORIENTATION_PORTRAIT && Preferences.Gui.rotateScreen.getPreference(preferences)) { return; } diff --git a/app/src/main/res/values/preferences.xml b/app/src/main/res/values/preferences.xml index 0cd8421d..e4c814fc 100644 --- a/app/src/main/res/values/preferences.xml +++ b/app/src/main/res/values/preferences.xml @@ -21,17 +21,6 @@ --> - - org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev - - false - - org.solovyev.android.calculator.CalculatorActivity_show_release_notes - - true - org.solovyev.android.calculator.CalculatorModel_history - false - \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_other.xml b/app/src/main/res/xml/preferences_other.xml index 45f41cf2..a9926667 100644 --- a/app/src/main/res/xml/preferences_other.xml +++ b/app/src/main/res/xml/preferences_other.xml @@ -25,14 +25,12 @@