Settings
This commit is contained in:
parent
d9aeb54d71
commit
9e2a653549
@ -29,10 +29,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.ColorRes;
|
import android.support.annotation.*;
|
||||||
import android.support.annotation.LayoutRes;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.StyleRes;
|
|
||||||
import android.support.v7.view.ContextThemeWrapper;
|
import android.support.v7.view.ContextThemeWrapper;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import jscl.AngleUnit;
|
import jscl.AngleUnit;
|
||||||
@ -77,7 +74,6 @@ public final class Preferences {
|
|||||||
if (!Gui.vibrateOnKeypress.isSet(preferences)) {
|
if (!Gui.vibrateOnKeypress.isSet(preferences)) {
|
||||||
Gui.vibrateOnKeypress.putPreference(editor, Deleted.hapticFeedback.getPreference(preferences) > 0);
|
Gui.vibrateOnKeypress.putPreference(editor, Deleted.hapticFeedback.getPreference(preferences) > 0);
|
||||||
}
|
}
|
||||||
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.theme);
|
migratePreference(preferences, editor, Gui.theme, Deleted.theme);
|
||||||
migratePreference(preferences, editor, Gui.layout, Deleted.layout);
|
migratePreference(preferences, editor, Gui.layout, Deleted.layout);
|
||||||
@ -282,10 +278,8 @@ public final class Preferences {
|
|||||||
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> showReleaseNotes = BooleanPreference.of("gui.showReleaseNotes", true);
|
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("gui.showReleaseNotes", true);
|
||||||
public static final Preference<Boolean> useBackAsPrevious = BooleanPreference.of("gui.useBackAsPrevious", false);
|
public static final Preference<Boolean> useBackAsPrevious = BooleanPreference.of("gui.useBackAsPrevious", false);
|
||||||
public static final Preference<Boolean> showEqualsButton = BooleanPreference.of("gui.showEqualsButton", true);
|
|
||||||
public static final Preference<Boolean> rotateScreen = BooleanPreference.of("gui.rotateScreen", true);
|
public static final Preference<Boolean> rotateScreen = BooleanPreference.of("gui.rotateScreen", 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> vibrateOnKeypress = BooleanPreference.of("gui.vibrateOnKeypress", true);
|
public static final Preference<Boolean> vibrateOnKeypress = BooleanPreference.of("gui.vibrateOnKeypress", true);
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -303,14 +297,16 @@ public final class Preferences {
|
|||||||
default_theme(R.style.Cpp_Theme_Gray),
|
default_theme(R.style.Cpp_Theme_Gray),
|
||||||
violet_theme(R.style.Cpp_Theme_Violet),
|
violet_theme(R.style.Cpp_Theme_Violet),
|
||||||
light_blue_theme(R.style.Cpp_Theme_Blue),
|
light_blue_theme(R.style.Cpp_Theme_Blue),
|
||||||
metro_blue_theme(R.style.Cpp_Theme_Metro_Blue, R.style.Cpp_Theme_Metro_Blue_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Blue_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
metro_blue_theme(R.string.p_metro_blue_theme, R.style.Cpp_Theme_Metro_Blue, R.style.Cpp_Theme_Metro_Blue_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Blue_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
||||||
metro_purple_theme(R.style.Cpp_Theme_Metro_Purple, R.style.Cpp_Theme_Metro_Purple_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Purple_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
metro_purple_theme(R.string.p_metro_purple_theme, R.style.Cpp_Theme_Metro_Purple, R.style.Cpp_Theme_Metro_Purple_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Purple_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
||||||
metro_green_theme(R.style.Cpp_Theme_Metro_Green, R.style.Cpp_Theme_Metro_Green_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Green_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
metro_green_theme(R.string.p_metro_green_theme, R.style.Cpp_Theme_Metro_Green, R.style.Cpp_Theme_Metro_Green_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Green_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
||||||
material_theme(R.style.Cpp_Theme_Material, R.style.Cpp_Theme_Material_Calculator),
|
material_theme(R.string.cpp_theme_dark, R.style.Cpp_Theme_Material, R.style.Cpp_Theme_Material_Calculator),
|
||||||
material_light_theme(R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Material_Light_Dialog, R.style.Cpp_Theme_Material_Light_Dialog_Alert);
|
material_light_theme(R.string.cpp_theme_light, R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Material_Light_Dialog, R.style.Cpp_Theme_Material_Light_Dialog_Alert);
|
||||||
|
|
||||||
private static final SparseArray<TextColor> textColors = new SparseArray<>();
|
private static final SparseArray<TextColor> textColors = new SparseArray<>();
|
||||||
|
|
||||||
|
@StringRes
|
||||||
|
public final int name;
|
||||||
@StyleRes
|
@StyleRes
|
||||||
public final int theme;
|
public final int theme;
|
||||||
@StyleRes
|
@StyleRes
|
||||||
@ -324,14 +320,15 @@ public final class Preferences {
|
|||||||
public final boolean light;
|
public final boolean light;
|
||||||
|
|
||||||
Theme(@StyleRes int theme) {
|
Theme(@StyleRes int theme) {
|
||||||
this(theme, theme);
|
this(R.string.cpp_theme_dark, theme, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
Theme(@StyleRes int theme, @StyleRes int calculatorTheme) {
|
Theme(@StringRes int name, @StyleRes int theme, @StyleRes int calculatorTheme) {
|
||||||
this(theme, calculatorTheme, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Material_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert);
|
this(name, theme, calculatorTheme, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Material_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert);
|
||||||
}
|
}
|
||||||
|
|
||||||
Theme(@StyleRes int theme, @StyleRes int calculatorTheme, @StyleRes int wizardTheme, @StyleRes int dialogTheme, @StyleRes int alertDialogTheme) {
|
Theme(@StringRes int name, @StyleRes int theme, @StyleRes int calculatorTheme, @StyleRes int wizardTheme, @StyleRes int dialogTheme, @StyleRes int alertDialogTheme) {
|
||||||
|
this.name = name;
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
this.calculatorTheme = calculatorTheme;
|
this.calculatorTheme = calculatorTheme;
|
||||||
this.wizardTheme = wizardTheme;
|
this.wizardTheme = wizardTheme;
|
||||||
@ -386,18 +383,25 @@ public final class Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Layout {
|
public enum Layout {
|
||||||
main_calculator,
|
main_calculator(R.string.p_layout_calculator),
|
||||||
simple,
|
simple(R.string.p_layout_simple),
|
||||||
|
|
||||||
// not used anymore
|
// not used anymore
|
||||||
@Deprecated
|
@Deprecated
|
||||||
main_cellphone,
|
main_cellphone(R.string.p_layout_simple),
|
||||||
// not used anymore
|
// not used anymore
|
||||||
@Deprecated
|
@Deprecated
|
||||||
main_calculator_mobile,
|
main_calculator_mobile(R.string.p_layout_simple),
|
||||||
// not used anymore
|
// not used anymore
|
||||||
@Deprecated
|
@Deprecated
|
||||||
simple_mobile;
|
simple_mobile(R.string.p_layout_simple);
|
||||||
|
|
||||||
|
@StringRes
|
||||||
|
public final int name;
|
||||||
|
|
||||||
|
Layout(@StringRes int name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class TextColor {
|
public static final class TextColor {
|
||||||
|
@ -107,6 +107,8 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepareLanguagePreference(preference);
|
prepareLanguagePreference(preference);
|
||||||
|
prepareLayoutPreference(preference);
|
||||||
|
prepareThemePreference(preference);
|
||||||
|
|
||||||
getCheckout().whenReady(new Checkout.ListenerAdapter() {
|
getCheckout().whenReady(new Checkout.ListenerAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@ -132,6 +134,36 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
|
|||||||
onSharedPreferenceChanged(preferences, Engine.Preferences.Output.round.getKey());
|
onSharedPreferenceChanged(preferences, Engine.Preferences.Output.round.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareLayoutPreference(int preference) {
|
||||||
|
if (preference != R.xml.preferences_appearance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ListPreference layout = (ListPreference) preferenceManager.findPreference(Preferences.Gui.layout.getKey());
|
||||||
|
layout.setSummary(Preferences.Gui.getLayout(preferences).name);
|
||||||
|
layout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
layout.setSummary(Preferences.Gui.Layout.valueOf((String) newValue).name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareThemePreference(int preference) {
|
||||||
|
if (preference != R.xml.preferences_appearance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ListPreference theme = (ListPreference) preferenceManager.findPreference(Preferences.Gui.theme.getKey());
|
||||||
|
theme.setSummary(Preferences.Gui.getTheme(preferences).name);
|
||||||
|
theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
theme.setSummary(Preferences.Gui.Theme.valueOf((String) newValue).name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void prepareLanguagePreference(int preference) {
|
private void prepareLanguagePreference(int preference) {
|
||||||
if (preference != R.xml.preferences_appearance) {
|
if (preference != R.xml.preferences_appearance) {
|
||||||
return;
|
return;
|
||||||
|
@ -14,8 +14,6 @@ import static org.solovyev.android.calculator.Preferences.Gui.theme;
|
|||||||
|
|
||||||
public final class EditorTextProcessor implements TextProcessor<TextProcessorEditorResult, String>, SharedPreferences.OnSharedPreferenceChangeListener {
|
public final class EditorTextProcessor implements TextProcessor<TextProcessorEditorResult, String>, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private boolean highlightText = true;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private TextHighlighter textHighlighter;
|
private TextHighlighter textHighlighter;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -30,15 +28,11 @@ public final class EditorTextProcessor implements TextProcessor<TextProcessorEdi
|
|||||||
this.preferences = preferences;
|
this.preferences = preferences;
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
onSharedPreferenceChanged(preferences, Preferences.Gui.highlightText.getKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public TextProcessorEditorResult process(@Nonnull String text) {
|
public TextProcessorEditorResult process(@Nonnull String text) {
|
||||||
if (!highlightText) {
|
|
||||||
return new TextProcessorEditorResult(text, 0);
|
|
||||||
}
|
|
||||||
final TextProcessorEditorResult processesText = getTextHighlighter().process(text);
|
final TextProcessorEditorResult processesText = getTextHighlighter().process(text);
|
||||||
return new TextProcessorEditorResult(processesText.getCharSequence(), processesText.getOffset());
|
return new TextProcessorEditorResult(processesText.getCharSequence(), processesText.getOffset());
|
||||||
}
|
}
|
||||||
@ -51,15 +45,9 @@ public final class EditorTextProcessor implements TextProcessor<TextProcessorEdi
|
|||||||
return textHighlighter;
|
return textHighlighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHighlightText(boolean highlightText) {
|
|
||||||
this.highlightText = highlightText;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (Preferences.Gui.highlightText.isSameKey(key)) {
|
if (theme.isSameKey(key)) {
|
||||||
setHighlightText(Preferences.Gui.highlightText.getPreference(preferences));
|
|
||||||
} else if (theme.isSameKey(key)) {
|
|
||||||
final int color = getTextColor(preferences);
|
final int color = getTextColor(preferences);
|
||||||
textHighlighter = new TextHighlighter(color, true, engine);
|
textHighlighter = new TextHighlighter(color, true, engine);
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,6 @@
|
|||||||
a:title="@string/cpp_language"
|
a:title="@string/cpp_language"
|
||||||
m:materialColor="@color/material_text_selector" />
|
m:materialColor="@color/material_text_selector" />
|
||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
|
||||||
a:key="gui.highlightText"
|
|
||||||
a:summary="@string/c_calc_color_display_summary"
|
|
||||||
a:title="@string/c_calc_color_display_title" />
|
|
||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
<android.preference.CheckBoxPreference
|
||||||
a:key="gui.vibrateOnKeypress"
|
a:key="gui.vibrateOnKeypress"
|
||||||
a:title="@string/cpp_prefs_vibrate_on_keypress" />
|
a:title="@string/cpp_prefs_vibrate_on_keypress" />
|
||||||
|
Loading…
Reference in New Issue
Block a user