Haptic feedback default value

This commit is contained in:
Sergey Solovyev 2012-10-10 00:35:10 +04:00
parent ac411a549f
commit 577fac76f8

View File

@ -1,174 +1,183 @@
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);
}
@NotNull
public static Layout getLayout(@NotNull SharedPreferences preferences) {
return layout.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),
// not used anymore
@Deprecated
main_cellphone(R.layout.main_calculator),
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);
if ( Gui.layout.getPreference(preferences) == Gui.Layout.main_cellphone ) {
Gui.layout.putDefault(preferences);
}
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, 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);
}
}
}
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 org.solovyev.android.view.VibratorContainer;
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);
}
@NotNull
public static Layout getLayout(@NotNull SharedPreferences preferences) {
return layout.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),
// not used anymore
@Deprecated
main_cellphone(R.layout.main_calculator),
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);
if ( Gui.layout.getPreference(preferences) == Gui.Layout.main_cellphone ) {
Gui.layout.putDefault(preferences);
}
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, Graph.interpolate);
applyDefaultPreference(preferences, Graph.lineColorImag);
applyDefaultPreference(preferences, Graph.lineColorReal);
if ( !VibratorContainer.Preferences.hapticFeedbackEnabled.isSet(preferences) ) {
VibratorContainer.Preferences.hapticFeedbackEnabled.putPreference(preferences, true);
}
if ( !VibratorContainer.Preferences.hapticFeedbackDuration.isSet(preferences) ) {
VibratorContainer.Preferences.hapticFeedbackDuration.putPreference(preferences, 60L);
}
}
private static void applyDefaultPreference(@NotNull SharedPreferences preferences, @NotNull Preference<?> preference) {
if (!preference.isSet(preferences)) {
preference.putDefault(preferences);
}
}
}