From ba7207d0e6787634193f64b471e90a5407d9b874 Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 16 Apr 2016 20:51:18 +0200 Subject: [PATCH] AMOLED-friendly theme added --- .../android/calculator/Preferences.java | 26 +++++- .../android/calculator/language/Language.java | 15 +++- .../preferences/PreferenceEntry.java | 12 +++ .../preferences/PreferencesFragment.java | 45 ++++++++--- .../wizard/ChooseThemeWizardStep.java | 16 ++-- .../drawable-v21/material_button_black.xml | 32 ++++++++ .../material_button_black_lighter.xml | 32 ++++++++ .../material_button_deep_blue.xml | 32 ++++++++ .../material_button_deep_blue_lighter.xml | 32 ++++++++ .../res/drawable/material_button_black.xml | 35 ++++++++ .../material_button_black_lighter.xml | 35 ++++++++ .../drawable/material_button_deep_blue.xml | 39 +++++++++ .../material_button_deep_blue_lighter.xml | 39 +++++++++ app/src/main/res/values/arrays.xml | 15 ---- app/src/main/res/values/colors.xml | 5 ++ .../main/res/values/text_non_translatable.xml | 1 + .../main/res/values/theme_material_black.xml | 79 +++++++++++++++++++ .../main/res/xml/preferences_appearance.xml | 2 - 18 files changed, 447 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/org/solovyev/android/calculator/preferences/PreferenceEntry.java create mode 100644 app/src/main/res/drawable-v21/material_button_black.xml create mode 100644 app/src/main/res/drawable-v21/material_button_black_lighter.xml create mode 100644 app/src/main/res/drawable-v21/material_button_deep_blue.xml create mode 100644 app/src/main/res/drawable-v21/material_button_deep_blue_lighter.xml create mode 100644 app/src/main/res/drawable/material_button_black.xml create mode 100644 app/src/main/res/drawable/material_button_black_lighter.xml create mode 100644 app/src/main/res/drawable/material_button_deep_blue.xml create mode 100644 app/src/main/res/drawable/material_button_deep_blue_lighter.xml create mode 100644 app/src/main/res/values/theme_material_black.xml 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 95a4c794..0622d50e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Preferences.java +++ b/app/src/main/java/org/solovyev/android/calculator/Preferences.java @@ -33,8 +33,6 @@ import android.support.annotation.*; import android.support.v7.view.ContextThemeWrapper; import android.text.TextUtils; import android.util.SparseArray; -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; @@ -42,6 +40,7 @@ import org.solovyev.android.calculator.history.HistoryActivity; import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.operators.OperatorsActivity; +import org.solovyev.android.calculator.preferences.PreferenceEntry; import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.variables.VariablesActivity; import org.solovyev.android.calculator.wizard.WizardActivity; @@ -285,7 +284,7 @@ public final class Preferences { return mode.getPreferenceNoError(preferences); } - public enum Theme { + public enum Theme implements PreferenceEntry { default_theme(R.style.Cpp_Theme_Gray), violet_theme(R.style.Cpp_Theme_Violet), @@ -294,12 +293,19 @@ public final class Preferences { 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.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.string.cpp_theme_dark, R.style.Cpp_Theme_Material, R.style.Cpp_Theme_Material_Calculator), + material_black_theme(R.string.cpp_theme_black, R.style.Cpp_Theme_Material_Black, R.style.Cpp_Theme_Material_Black_Calculator) { + @NonNull + @Override + public String getName(@NonNull Context context) { + return context.getString(name, material_theme.getName(context)); + } + }, material_light_theme(R.string.cpp_theme_light, R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Material_Light_Calculator, 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 textColors = new SparseArray<>(); @StringRes - public final int name; + protected final int name; @StyleRes public final int theme; @StyleRes @@ -373,6 +379,18 @@ public final class Preferences { } return textColor; } + + @Override + @NonNull + public String getName(@NonNull Context context) { + return context.getString(name); + } + + @NonNull + @Override + public CharSequence getId() { + return name(); + } } public enum Mode { diff --git a/app/src/main/java/org/solovyev/android/calculator/language/Language.java b/app/src/main/java/org/solovyev/android/calculator/language/Language.java index dab1dfb9..21d0a2a0 100644 --- a/app/src/main/java/org/solovyev/android/calculator/language/Language.java +++ b/app/src/main/java/org/solovyev/android/calculator/language/Language.java @@ -1,15 +1,15 @@ package org.solovyev.android.calculator.language; import android.content.Context; +import android.support.annotation.NonNull; import android.text.TextUtils; - import org.solovyev.android.calculator.R; - -import java.util.Locale; +import org.solovyev.android.calculator.preferences.PreferenceEntry; import javax.annotation.Nonnull; +import java.util.Locale; -public final class Language { +public final class Language implements PreferenceEntry{ @Nonnull public final String code; @@ -39,6 +39,7 @@ public final class Language { return locale.getDisplayName(locale); } + @Override @Nonnull public String getName(@Nonnull Context context) { if (!isSystem()) { @@ -48,6 +49,12 @@ public final class Language { } } + @NonNull + @Override + public CharSequence getId() { + return code; + } + public boolean isSystem() { return code.equals(Languages.SYSTEM_LANGUAGE_CODE); } diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferenceEntry.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferenceEntry.java new file mode 100644 index 00000000..21aebcb2 --- /dev/null +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferenceEntry.java @@ -0,0 +1,12 @@ +package org.solovyev.android.calculator.preferences; + +import android.content.Context; +import android.support.annotation.NonNull; + +public interface PreferenceEntry { + @NonNull + CharSequence getName(@NonNull Context context); + + @NonNull + CharSequence getId(); +} diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java index c40ae3f3..e18bd7cf 100644 --- a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java @@ -1,5 +1,6 @@ package org.solovyev.android.calculator.preferences; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; @@ -13,6 +14,7 @@ import android.widget.ListView; import org.solovyev.android.calculator.AdView; import org.solovyev.android.calculator.Engine; import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.Preferences.Gui.Theme; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Languages; @@ -25,6 +27,7 @@ import org.solovyev.android.wizard.Wizards; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; +import java.util.Arrays; import java.util.List; import static org.solovyev.android.calculator.App.cast; @@ -154,32 +157,50 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc return; } final ListPreference theme = (ListPreference) preferenceManager.findPreference(Preferences.Gui.theme.getKey()); - theme.setSummary(Preferences.Gui.getTheme(preferences).name); + final FragmentActivity context = getActivity(); + populate(theme, + Theme.material_theme, + Theme.material_black_theme, + Theme.material_light_theme, + Theme.metro_blue_theme, + Theme.metro_green_theme, + Theme.metro_purple_theme); + theme.setSummary(Preferences.Gui.getTheme(preferences).getName(context)); theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - theme.setSummary(Preferences.Gui.Theme.valueOf((String) newValue).name); + final Theme newTheme = Theme.valueOf((String) newValue); + theme.setSummary(newTheme.getName(context)); return true; } }); } + private static void populate(@Nonnull ListPreference preference, @Nonnull PreferenceEntry... entries) { + populate(preference, Arrays.asList(entries)); + } + + private static void populate(@Nonnull ListPreference preference, @Nonnull List entries) { + final int size = entries.size(); + final CharSequence[] e = new CharSequence[size]; + final CharSequence[] v = new CharSequence[size]; + final Context context = preference.getContext(); + for (int i = 0; i < size; i++) { + final PreferenceEntry entry = entries.get(i); + e[i] = entry.getName(context); + v[i] = entry.getId(); + } + preference.setEntries(e); + preference.setEntryValues(v); + } + private void prepareLanguagePreference(int preference) { if (preference != R.xml.preferences_appearance) { return; } final ListPreference language = (ListPreference) preferenceManager.findPreference(Preferences.Gui.language.getKey()); - final List languagesList = languages.getList(); - final CharSequence[] entries = new CharSequence[languagesList.size()]; - final CharSequence[] entryValues = new CharSequence[languagesList.size()]; - for (int i = 0; i < languagesList.size(); i++) { - final Language l = languagesList.get(i); - entries[i] = l.getName(getActivity()); - entryValues[i] = l.code; - } - language.setEntries(entries); - language.setEntryValues(entryValues); + populate(language, languages.getList()); language.setSummary(languages.getCurrent().getName(getActivity())); language.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java b/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java index f29670a8..78244e8b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java +++ b/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java @@ -23,7 +23,6 @@ package org.solovyev.android.calculator.wizard; import android.os.Bundle; -import android.support.annotation.StringRes; import android.support.v7.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -58,11 +57,12 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences); final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_theme_spinner); themes.clear(); - themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme, R.string.cpp_theme_dark)); - themes.add(new ThemeUi(Preferences.Gui.Theme.material_light_theme, R.string.cpp_theme_light)); - themes.add(new ThemeUi(Preferences.Gui.Theme.metro_blue_theme, R.string.p_metro_blue_theme)); - themes.add(new ThemeUi(Preferences.Gui.Theme.metro_green_theme, R.string.p_metro_green_theme)); - themes.add(new ThemeUi(Preferences.Gui.Theme.metro_purple_theme, R.string.p_metro_purple_theme)); + themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme)); + themes.add(new ThemeUi(Preferences.Gui.Theme.material_black_theme)); + themes.add(new ThemeUi(Preferences.Gui.Theme.material_light_theme)); + themes.add(new ThemeUi(Preferences.Gui.Theme.metro_blue_theme)); + themes.add(new ThemeUi(Preferences.Gui.Theme.metro_green_theme)); + themes.add(new ThemeUi(Preferences.Gui.Theme.metro_purple_theme)); adapter = new WizardArrayAdapter<>(getActivity(), themes); spinner.setAdapter(adapter); spinner.setSelection(findPosition(theme)); @@ -111,9 +111,9 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView @Nonnull final String name; - public ThemeUi(@Nonnull Preferences.Gui.Theme theme, @StringRes int name) { + public ThemeUi(@Nonnull Preferences.Gui.Theme theme) { this.theme = theme; - this.name = getString(name); + this.name = theme.getName(getActivity()); } @Override diff --git a/app/src/main/res/drawable-v21/material_button_black.xml b/app/src/main/res/drawable-v21/material_button_black.xml new file mode 100644 index 00000000..360413b6 --- /dev/null +++ b/app/src/main/res/drawable-v21/material_button_black.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/material_button_black_lighter.xml b/app/src/main/res/drawable-v21/material_button_black_lighter.xml new file mode 100644 index 00000000..d7fc0204 --- /dev/null +++ b/app/src/main/res/drawable-v21/material_button_black_lighter.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/material_button_deep_blue.xml b/app/src/main/res/drawable-v21/material_button_deep_blue.xml new file mode 100644 index 00000000..68efa4b2 --- /dev/null +++ b/app/src/main/res/drawable-v21/material_button_deep_blue.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable-v21/material_button_deep_blue_lighter.xml b/app/src/main/res/drawable-v21/material_button_deep_blue_lighter.xml new file mode 100644 index 00000000..e4679c5b --- /dev/null +++ b/app/src/main/res/drawable-v21/material_button_deep_blue_lighter.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/material_button_black.xml b/app/src/main/res/drawable/material_button_black.xml new file mode 100644 index 00000000..5d7dd74b --- /dev/null +++ b/app/src/main/res/drawable/material_button_black.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/material_button_black_lighter.xml b/app/src/main/res/drawable/material_button_black_lighter.xml new file mode 100644 index 00000000..610a3db0 --- /dev/null +++ b/app/src/main/res/drawable/material_button_black_lighter.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/material_button_deep_blue.xml b/app/src/main/res/drawable/material_button_deep_blue.xml new file mode 100644 index 00000000..5880c0de --- /dev/null +++ b/app/src/main/res/drawable/material_button_deep_blue.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/material_button_deep_blue_lighter.xml b/app/src/main/res/drawable/material_button_deep_blue_lighter.xml new file mode 100644 index 00000000..000bc4a6 --- /dev/null +++ b/app/src/main/res/drawable/material_button_deep_blue_lighter.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 225b9e4f..fb4c2f95 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -21,21 +21,6 @@ --> - - @string/cpp_theme_dark - @string/cpp_theme_light - @string/p_metro_blue_theme - @string/p_metro_green_theme - @string/p_metro_purple_theme - - - material_theme - material_light_theme - metro_blue_theme - metro_green_theme - metro_purple_theme - - @string/p_use_app_theme @string/cpp_theme_dark diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 14a03463..2efa67f2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -47,6 +47,11 @@ #313131 #212121 #101010 + #0a0a0a + + #06224d + #082a5e + #0a3980 #0D47A1 #1565C0 diff --git a/app/src/main/res/values/text_non_translatable.xml b/app/src/main/res/values/text_non_translatable.xml index 9e49f240..c7026931 100644 --- a/app/src/main/res/values/text_non_translatable.xml +++ b/app/src/main/res/values/text_non_translatable.xml @@ -16,6 +16,7 @@ f(x, y) αβγ E + %1$s (AMOLED) 0 1 diff --git a/app/src/main/res/values/theme_material_black.xml b/app/src/main/res/values/theme_material_black.xml new file mode 100644 index 00000000..4fcb3932 --- /dev/null +++ b/app/src/main/res/values/theme_material_black.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_appearance.xml b/app/src/main/res/xml/preferences_appearance.xml index 9c1fa08e..687d40cf 100644 --- a/app/src/main/res/xml/preferences_appearance.xml +++ b/app/src/main/res/xml/preferences_appearance.xml @@ -35,8 +35,6 @@ a:title="@string/cpp_prefs_vibrate_on_keypress" />