diff --git a/res/drawable/metro_button_dark.xml b/res/drawable/metro_button_dark.xml new file mode 100644 index 00000000..5076b74e --- /dev/null +++ b/res/drawable/metro_button_dark.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/res/drawable/metro_button_dark_shape.xml b/res/drawable/metro_button_dark_shape.xml new file mode 100644 index 00000000..f72faa85 --- /dev/null +++ b/res/drawable/metro_button_dark_shape.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/res/drawable/metro_button_focused.xml b/res/drawable/metro_button_focused.xml new file mode 100644 index 00000000..0e91626c --- /dev/null +++ b/res/drawable/metro_button_focused.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/res/drawable/metro_button_light.xml b/res/drawable/metro_button_light.xml new file mode 100644 index 00000000..8c5544dd --- /dev/null +++ b/res/drawable/metro_button_light.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/res/drawable/metro_button_light_shape.xml b/res/drawable/metro_button_light_shape.xml new file mode 100644 index 00000000..62df777b --- /dev/null +++ b/res/drawable/metro_button_light_shape.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/res/layout-port/main_calculator.xml b/res/layout-port/main_calculator.xml index 4776a3bb..5883edcf 100644 --- a/res/layout-port/main_calculator.xml +++ b/res/layout-port/main_calculator.xml @@ -24,13 +24,13 @@ diff --git a/res/values-ru/text_strings.xml b/res/values-ru/text_strings.xml index 1be27645..88f58c12 100644 --- a/res/values-ru/text_strings.xml +++ b/res/values-ru/text_strings.xml @@ -90,6 +90,7 @@ По умолчанию Фиолетовая Голубая + Метро Точность результата(все вычисления производятся максимально точно) Включает/выключает подсветку синтаксиса в поле редактирования калькулятора Устанавливает тему оформления приложения diff --git a/res/values/arrays.xml b/res/values/arrays.xml index dae0ab1c..e2fa04c0 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -9,13 +9,13 @@ @string/p_default_theme @string/p_violet_theme @string/p_light_blue_theme - @string/p_windows_theme + @string/p_metro_theme default_theme violet_theme light_blue_theme - windows_theme + metro_theme diff --git a/res/values/styles-metro-theme.xml b/res/values/styles-metro-theme.xml new file mode 100644 index 00000000..9b0f6922 --- /dev/null +++ b/res/values/styles-metro-theme.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/styles-windows-theme.xml b/res/values/styles-windows-theme.xml deleted file mode 100644 index c27614e6..00000000 --- a/res/values/styles-windows-theme.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/res/values/text_strings.xml b/res/values/text_strings.xml index b019a73d..366ac9ba 100644 --- a/res/values/text_strings.xml +++ b/res/values/text_strings.xml @@ -90,7 +90,7 @@ Default Violet Light Blue - Windows Metro + Metro Precision of result value (all calculations are done with maximum precision regardless of the value of this option) Toggles colouring and styling in calculator editor Sets the theme for calculator diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 80808267..dbe7a05b 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -41,6 +41,8 @@ import org.solovyev.android.history.HistoryDragProcessor; 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.ColorButton; import org.solovyev.android.view.VibratorContainer; import org.solovyev.android.view.drag.*; import org.solovyev.common.utils.Announcer; @@ -59,6 +61,40 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh @Nullable private IBillingObserver billingObserver; + 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_theme(ThemeType.metro, R.style.metro_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 class Preferences { @NotNull private static final String APP_VERSION_P_KEY = "application.version"; @@ -67,15 +103,17 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private static final Preference appOpenedCounter = new IntegerPreference(APP_OPENED_COUNTER_P_KEY, APP_OPENED_COUNTER_P_DEFAULT); private static final Preference feedbackWindowShown = new BooleanPreference(FEEDBACK_WINDOW_SHOWN_P_KEY, FEEDBACK_WINDOW_SHOWN_P_DEFAULT); + private static final Preference theme = StringPreference.newInstance(THEME_P_KEY, THEME_P_DEFAULT, Theme.class); } + @NotNull + private static final String THEME_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_theme"; + private static final Theme THEME_P_DEFAULT = Theme.default_theme; + @NotNull private static final String APP_OPENED_COUNTER_P_KEY = "app_opened_counter"; private static final Integer APP_OPENED_COUNTER_P_DEFAULT = 0; - - - @NotNull public static final String FEEDBACK_WINDOW_SHOWN_P_KEY = "feedback_window_shown"; public static final boolean FEEDBACK_WINDOW_SHOWN_P_DEFAULT = false; @@ -97,7 +135,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private volatile boolean initialized; @NotNull - private String themeName; + private Theme theme; @NotNull private String layoutName; @@ -210,6 +248,16 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh initMultiplicationButton(); + if (theme.getThemeType() == ThemeType.metro) { + // for metro themes we should turn off magic flames + AndroidUtils.processViewsOfType(this.getWindow().getDecorView(), ColorButton.class, new AndroidUtils.ViewProcessor() { + @Override + public void process(@NotNull ColorButton colorButton) { + colorButton.setDrawMagicFlame(false); + } + }); + } + preferences.registerOnSharedPreferenceChangeListener(this); } @@ -386,19 +434,14 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh } private synchronized void setTheme(@NotNull SharedPreferences preferences) { - final Map styles = ResourceCache.instance.getNameToIdCache(R.style.class); - themeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme)); - - Integer styleId = styles.get(themeName); - if (styleId == null) { - Log.d(this.getClass().getName(), "No saved theme found => applying default theme: " + R.style.default_theme); - styleId = R.style.default_theme; - } else { - Log.d(this.getClass().getName(), "Saved theme found: " + styleId); + try { + theme = Preferences.theme.getPreference(preferences); + } catch (IllegalArgumentException e) { + theme = Theme.default_theme; } - setTheme(styleId); + setTheme(theme.getThemeId()); } private synchronized void firstTimeInit(@NotNull SharedPreferences preferences) { @@ -630,8 +673,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final String newLayoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout)); - final String newThemeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme)); - if (!themeName.equals(newThemeName) || !layoutName.equals(newLayoutName)) { + final Theme newTheme = Preferences.theme.getPreference(preferences); + if (!theme.equals(newTheme) || !layoutName.equals(newLayoutName)) { AndroidUtils.restartActivity(this); }