Preferences migrated

This commit is contained in:
serso 2016-02-29 19:41:35 +01:00
parent 1ac6b6dfb0
commit e87ac84323
6 changed files with 43 additions and 74 deletions

View File

@ -33,15 +33,11 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.KeyEvent; import android.view.*;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.Activities; import org.solovyev.android.Activities;
import org.solovyev.android.Android; import org.solovyev.android.Android;
import org.solovyev.android.calculator.converter.ConverterFragment; import org.solovyev.android.calculator.converter.ConverterFragment;
@ -57,17 +53,12 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; 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_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; 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.Preferences.Gui.keepScreenOn;
import static org.solovyev.android.calculator.release.ReleaseNotes.hasReleaseNotes; import static org.solovyev.android.calculator.release.ReleaseNotes.hasReleaseNotes;
import static org.solovyev.android.wizard.WizardUi.continueWizard; import static org.solovyev.android.wizard.WizardUi.*;
import static org.solovyev.android.wizard.WizardUi.createLaunchIntent;
import static org.solovyev.android.wizard.WizardUi.startWizard;
public class CalculatorActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener, Toolbar.OnMenuItemClickListener { 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.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(this); toolbar.setOnMenuItemClickListener(this);
useBackAsPrev = Preferences.Gui.usePrevAsBack.getPreference(preferences); useBackAsPrev = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
if (savedInstanceState == null) { if (savedInstanceState == null) {
firstTimeInit(preferences, this); firstTimeInit(preferences, this);
} }
@ -260,17 +251,17 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
if (Preferences.Gui.usePrevAsBack.getKey().equals(key)) { if (Preferences.Gui.useBackAsPrevious.getKey().equals(key)) {
useBackAsPrev = Preferences.Gui.usePrevAsBack.getPreference(preferences); useBackAsPrev = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
} }
if (Preferences.Gui.autoOrientation.getKey().equals(key)) { if (Preferences.Gui.rotateScreen.getKey().equals(key)) {
toggleOrientationChange(); toggleOrientationChange();
} }
} }
private void toggleOrientationChange() { private void toggleOrientationChange() {
if (Preferences.Gui.autoOrientation.getPreference(preferences)) { if (Preferences.Gui.rotateScreen.getPreference(preferences)) {
setRequestedOrientation(SCREEN_ORIENTATION_UNSPECIFIED); setRequestedOrientation(SCREEN_ORIENTATION_UNSPECIFIED);
} else { } else {
setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT); setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT);

View File

@ -35,7 +35,8 @@ import android.support.annotation.NonNull;
import android.support.annotation.StyleRes; import android.support.annotation.StyleRes;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.about.AboutActivity; import org.solovyev.android.calculator.about.AboutActivity;
import org.solovyev.android.calculator.functions.FunctionsActivity; 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.preferences.PreferencesActivity;
import org.solovyev.android.calculator.variables.VariablesActivity; import org.solovyev.android.calculator.variables.VariablesActivity;
import org.solovyev.android.calculator.wizard.WizardActivity; import org.solovyev.android.calculator.wizard.WizardActivity;
import org.solovyev.android.prefs.BooleanPreference; import org.solovyev.android.prefs.*;
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 javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; 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.Android.isPhoneModel;
import static org.solovyev.android.DeviceModel.samsung_galaxy_s; import static org.solovyev.android.DeviceModel.samsung_galaxy_s;
import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2; import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
@ -82,8 +75,7 @@ public final class Preferences {
final SharedPreferences.Editor editor = preferences.edit(); final SharedPreferences.Editor editor = preferences.edit();
setInitialDefaultValues(application, preferences, editor); setInitialDefaultValues(application, preferences, editor);
editor.apply(); editor.apply();
} else if (version > 143) { } else if (version <= 143) {
// FIXME: 2016-02-20 use correct version
final SharedPreferences.Editor editor = preferences.edit(); final SharedPreferences.Editor editor = preferences.edit();
if (!Gui.vibrateOnKeypress.isSet(preferences)) { if (!Gui.vibrateOnKeypress.isSet(preferences)) {
//noinspection deprecation //noinspection deprecation
@ -91,9 +83,13 @@ public final class Preferences {
} }
migratePreference(preferences, editor, Gui.highlightText, Deleted.colorDisplay); migratePreference(preferences, editor, Gui.highlightText, Deleted.colorDisplay);
migratePreference(preferences, editor, Gui.keepScreenOn, Deleted.preventScreenFromFading); migratePreference(preferences, editor, Gui.keepScreenOn, Deleted.preventScreenFromFading);
migratePreference(preferences, editor, Gui.theme, Deleted.oldTheme); migratePreference(preferences, editor, Gui.theme, Deleted.theme);
migratePreference(preferences, editor, Gui.layout, Deleted.oldLayout); migratePreference(preferences, editor, Gui.layout, Deleted.layout);
final Gui.Layout layout = Deleted.oldLayout.getPreference(preferences); 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) { if (layout == Gui.Layout.main_cellphone) {
Gui.layout.putDefault(editor); Gui.layout.putDefault(editor);
} else if (layout == Gui.Layout.main_calculator_mobile) { } else if (layout == Gui.Layout.main_calculator_mobile) {
@ -142,10 +138,9 @@ public final class Preferences {
Gui.layout.tryPutDefault(preferences, editor); Gui.layout.tryPutDefault(preferences, editor);
Gui.feedbackWindowShown.tryPutDefault(preferences, editor); Gui.feedbackWindowShown.tryPutDefault(preferences, editor);
Gui.showReleaseNotes.tryPutDefault(preferences, editor); Gui.showReleaseNotes.tryPutDefault(preferences, editor);
Gui.usePrevAsBack.tryPutDefault(preferences, editor); Gui.useBackAsPrevious.tryPutDefault(preferences, editor);
Gui.showEqualsButton.tryPutDefault(preferences, editor); Gui.showEqualsButton.tryPutDefault(preferences, editor);
Gui.autoOrientation.tryPutDefault(preferences, editor); Gui.rotateScreen.tryPutDefault(preferences, editor);
Gui.hideNumeralBaseDigits.tryPutDefault(preferences, editor);
Gui.keepScreenOn.tryPutDefault(preferences, editor); Gui.keepScreenOn.tryPutDefault(preferences, editor);
Gui.language.tryPutDefault(preferences, editor); Gui.language.tryPutDefault(preferences, editor);
@ -275,12 +270,9 @@ public final class Preferences {
} }
public static class Calculations { public static class Calculations {
public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true); public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true);
public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", Engine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class); public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", Engine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class);
public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", Engine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class); public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", Engine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class);
} }
public static class Gui { public static class Gui {
@ -289,11 +281,10 @@ public final class Preferences {
public static final Preference<Layout> layout = StringPreference.ofEnum("gui.layout", Layout.simple, Layout.class); public static final Preference<Layout> layout = StringPreference.ofEnum("gui.layout", Layout.simple, Layout.class);
public static final Preference<String> language = StringPreference.of("gui.language", Languages.SYSTEM_LANGUAGE_CODE); public static final Preference<String> language = StringPreference.of("gui.language", Languages.SYSTEM_LANGUAGE_CODE);
public static final Preference<Boolean> feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false); public static final Preference<Boolean> feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false);
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true); public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("gui.showReleaseNotes", true);
public static final Preference<Boolean> usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false); public static final Preference<Boolean> useBackAsPrevious = BooleanPreference.of("gui.useBackAsPrevious", false);
public static final Preference<Boolean> showEqualsButton = BooleanPreference.of("showEqualsButton", true); public static final Preference<Boolean> showEqualsButton = BooleanPreference.of("gui.showEqualsButton", true);
public static final Preference<Boolean> autoOrientation = BooleanPreference.of("autoOrientation", true); public static final Preference<Boolean> rotateScreen = BooleanPreference.of("gui.rotateScreen", true);
public static final Preference<Boolean> hideNumeralBaseDigits = BooleanPreference.of("hideNumeralBaseDigits", true);
public static final Preference<Boolean> keepScreenOn = BooleanPreference.of("gui.keepScreenOn", true); public static final Preference<Boolean> keepScreenOn = BooleanPreference.of("gui.keepScreenOn", true);
public static final Preference<Boolean> highlightText = BooleanPreference.of("gui.highlightText", true); public static final Preference<Boolean> highlightText = BooleanPreference.of("gui.highlightText", true);
public static final Preference<Boolean> vibrateOnKeypress = BooleanPreference.of("gui.vibrateOnKeypress", true); public static final Preference<Boolean> vibrateOnKeypress = BooleanPreference.of("gui.vibrateOnKeypress", true);
@ -419,7 +410,11 @@ public final class Preferences {
static final Preference<Long> hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class); static final Preference<Long> hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class);
static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true); static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true);
static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true); static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true);
static final Preference<Gui.Theme> oldTheme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Gui.Theme.material_theme, Gui.Theme.class); static final Preference<Gui.Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Gui.Theme.material_theme, Gui.Theme.class);
static final Preference<Gui.Layout> oldLayout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Gui.Layout.simple, Gui.Layout.class); static final Preference<Gui.Layout> layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Gui.Layout.simple, Gui.Layout.class);
static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
static final Preference<Boolean> usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
static final Preference<Boolean> showEqualsButton = BooleanPreference.of("showEqualsButton", true);
static final Preference<Boolean> autoOrientation = BooleanPreference.of("autoOrientation", true);
} }
} }

View File

@ -15,7 +15,10 @@ import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import jscl.AngleUnit; import jscl.AngleUnit;
import jscl.NumeralBase; 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.buttons.CppSpecialButton;
import org.solovyev.android.calculator.history.History; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.AngleUnitsButton;
@ -26,9 +29,7 @@ import org.solovyev.android.views.dragbutton.DragDirection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import static jscl.NumeralBase.hex;
import static org.solovyev.android.calculator.Engine.Preferences.*; 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.*; import static org.solovyev.android.views.dragbutton.DragDirection.*;
public class KeyboardUi extends BaseKeyboardUi { public class KeyboardUi extends BaseKeyboardUi {
@ -96,12 +97,7 @@ public class KeyboardUi extends BaseKeyboardUi {
} }
public void toggleNumericDigits() { public void toggleNumericDigits() {
if (hideNumeralBaseDigits.getPreference(preferences)) {
toggleNumericDigits(numeralBase.getPreference(preferences)); toggleNumericDigits(numeralBase.getPreference(preferences));
} else {
// set HEX to show all digits
CppNumeralBase.valueOf(hex).toggleButtons(true, this);
}
} }
public void toggleNumericDigits(@Nonnull NumeralBase currentNumeralBase) { public void toggleNumericDigits(@Nonnull NumeralBase currentNumeralBase) {
@ -177,7 +173,7 @@ public class KeyboardUi extends BaseKeyboardUi {
if (angleUnit.isSameKey(key)) { if (angleUnit.isSameKey(key)) {
button6.setAngleUnit(angleUnit.getPreference(preferences)); button6.setAngleUnit(angleUnit.getPreference(preferences));
} }
if (numeralBase.isSameKey(key) || hideNumeralBaseDigits.isSameKey(key)) { if (numeralBase.isSameKey(key)) {
toggleNumericDigits(); toggleNumericDigits();
} }
if (multiplicationSign.isSameKey(key)) { if (multiplicationSign.isSameKey(key)) {

View File

@ -87,7 +87,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
if (equalsButton == null) { if (equalsButton == null) {
return; return;
} }
if (orientation != Configuration.ORIENTATION_PORTRAIT && Preferences.Gui.autoOrientation.getPreference(preferences)) { if (orientation != Configuration.ORIENTATION_PORTRAIT && Preferences.Gui.rotateScreen.getPreference(preferences)) {
return; return;
} }

View File

@ -21,17 +21,6 @@
--> -->
<resources> <resources>
<string name="p_calc_use_back_button_as_prev_key" translatable="false">
org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev
</string>
<string name="p_calc_use_back_button_as_prev" translatable="false">false</string>
<string name="p_calc_show_release_notes_key" translatable="false">org.solovyev.android.calculator.CalculatorActivity_show_release_notes
</string>
<string name="p_calc_show_release_notes" translatable="false">true</string>
<string name="p_calc_history" translatable="false">org.solovyev.android.calculator.CalculatorModel_history</string> <string name="p_calc_history" translatable="false">org.solovyev.android.calculator.CalculatorModel_history</string>
<string name="p_calc_ad_free" translatable="false">false</string> <string name="p_calc_ad_free" translatable="false">false</string>
</resources> </resources>

View File

@ -25,14 +25,12 @@
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android">
<android.preference.CheckBoxPreference <android.preference.CheckBoxPreference
a:defaultValue="true" a:key="gui.showReleaseNotes"
a:key="@string/p_calc_show_release_notes_key"
a:summary="@string/c_calc_show_release_notes_summary" a:summary="@string/c_calc_show_release_notes_summary"
a:title="@string/c_calc_show_release_notes_title" /> a:title="@string/c_calc_show_release_notes_title" />
<android.preference.CheckBoxPreference <android.preference.CheckBoxPreference
a:defaultValue="false" a:key="gui.useBackAsPrevious"
a:key="@string/p_calc_use_back_button_as_prev_key"
a:summary="@string/c_calc_use_back_button_as_prev_summary" a:summary="@string/c_calc_use_back_button_as_prev_summary"
a:title="@string/c_calc_use_back_button_as_prev_title" /> a:title="@string/c_calc_use_back_button_as_prev_title" />