diff --git a/app/src/main/java/protect/card_locker/CatimaAppCompatActivity.java b/app/src/main/java/protect/card_locker/CatimaAppCompatActivity.java index 9a3ff44dd..df6995ff5 100644 --- a/app/src/main/java/protect/card_locker/CatimaAppCompatActivity.java +++ b/app/src/main/java/protect/card_locker/CatimaAppCompatActivity.java @@ -19,10 +19,9 @@ public class CatimaAppCompatActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // XXX on the splash screen activity, aka the main activity, this has to be executed after applying dynamic colors, not before - // so running this only on non main for now - if (!this.getClass().getSimpleName().equals(MainActivity.class.getSimpleName())) { - Utils.patchOledDarkTheme(this); + // XXX splash screen activity has to do this after installing splash screen before view inflate + if(!this.getClass().getSimpleName().equals(MainActivity.class.getSimpleName())) { + Utils.patchColors(this); } } @@ -39,9 +38,6 @@ public class CatimaAppCompatActivity extends AppCompatActivity { getWindow().setStatusBarColor(Utils.isDarkModeEnabled(this) ? Color.TRANSPARENT : Color.argb(127, 0, 0, 0)); } // XXX android 9 and below has a nasty rendering bug if the theme was patched earlier - // the splash screen activity needs the fix regardless to solve a dynamic color api issue - if (!this.getClass().getSimpleName().equals(MainActivity.class.getSimpleName())) { - Utils.postPatchOledDarkTheme(this); - } + Utils.postPatchColors(this); } } diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java b/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java index 3b817c540..4ed97eb92 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java @@ -16,6 +16,5 @@ public class LoyaltyCardLockerApplication extends Application { Settings settings = new Settings(this); AppCompatDelegate.setDefaultNightMode(settings.getTheme()); - DynamicColors.applyToActivitiesIfAvailable(this); } } diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index 0f4906d0b..81c5d6536 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -180,20 +180,10 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard protected void onCreate(Bundle inputSavedInstanceState) { super.onCreate(inputSavedInstanceState); SplashScreen.installSplashScreen(this); - - // onPreCreate can't tell this activity uses a material theme due to splash screen, force color application here - DynamicColors.applyIfAvailable(this); - Utils.patchOledDarkTheme(this); setTitle(R.string.app_name); - + // XXX color patching has to be done again after setting splash screen + Utils.patchColors(this); setContentView(R.layout.main_activity); - - // XXX more dynamic color fixing due to splash screen - // without this the background color will get stuck with the old color before dynamic color - TypedValue typedValue = new TypedValue(); - getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true); - findViewById(android.R.id.content).setBackgroundColor(typedValue.data); - Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index f5e4fd328..bc1042821 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -17,6 +17,7 @@ import android.util.Log; import android.util.TypedValue; import android.widget.Toast; +import com.google.android.material.color.DynamicColors; import com.google.zxing.BinaryBitmap; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; @@ -464,21 +465,64 @@ public class Utils { } // replace colors in the current theme - // use before views are inflated, after dynamic color - public static void patchOledDarkTheme(AppCompatActivity activity) { - if (isDarkModeEnabled(activity) && new Settings(activity).getOledDark()) { - activity.getTheme().applyStyle(R.style.DarkBackground, true); + public static void patchColors(AppCompatActivity activity) { + Settings settings = new Settings(activity); + String color = settings.getColor(); + final String system = activity.getResources().getString(R.string.settings_key_system_theme); + final String red = activity.getResources().getString(R.string.settings_key_red_theme); + final String pink = activity.getResources().getString(R.string.settings_key_pink_theme); + final String magenta = activity.getResources().getString(R.string.settings_key_magenta_theme); + final String violet = activity.getResources().getString(R.string.settings_key_violet_theme); + final String blue = activity.getResources().getString(R.string.settings_key_blue_theme); + final String sky_blue = activity.getResources().getString(R.string.settings_key_sky_blue_theme); + final String green = activity.getResources().getString(R.string.settings_key_green_theme); + final String brown = activity.getResources().getString(R.string.settings_key_brown_theme); + // do nothing if color is catima + // final String catima = activity.getResources().getString(R.string.settings_key_catima_theme); + + Resources.Theme theme = activity.getTheme(); + + if (color.equals(system)) { + DynamicColors.applyIfAvailable(activity); + } else { + if (color.equals(red)) { + theme.applyStyle(R.style.red, true); + } + if (color.equals(pink)) { + theme.applyStyle(R.style.pink, true); + } + if (color.equals(magenta)) { + theme.applyStyle(R.style.magenta, true); + } + if (color.equals(violet)) { + theme.applyStyle(R.style.violet, true); + } + if (color.equals(blue)) { + theme.applyStyle(R.style.blue, true); + } + if (color.equals(sky_blue)) { + theme.applyStyle(R.style.skyblue, true); + } + if (color.equals(green)) { + theme.applyStyle(R.style.green, true); + } + if (color.equals(brown)) { + theme.applyStyle(R.style.brown, true); + } + } + + + if (isDarkModeEnabled(activity) && settings.getOledDark()) { + theme.applyStyle(R.style.DarkBackground, true); } } // XXX android 9 and below has issues with patched theme where the background becomes a // rendering mess // use after views are inflated - public static void postPatchOledDarkTheme(AppCompatActivity activity) { - if (isDarkModeEnabled(activity) && new Settings(activity).getOledDark()) { - TypedValue typedValue = new TypedValue(); - activity.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true); - activity.findViewById(android.R.id.content).setBackgroundColor(typedValue.data); - } + public static void postPatchColors(AppCompatActivity activity) { + TypedValue typedValue = new TypedValue(); + activity.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true); + activity.findViewById(android.R.id.content).setBackgroundColor(typedValue.data); } } diff --git a/app/src/main/java/protect/card_locker/preferences/Settings.java b/app/src/main/java/protect/card_locker/preferences/Settings.java index bd77dc135..36a5b8b00 100644 --- a/app/src/main/java/protect/card_locker/preferences/Settings.java +++ b/app/src/main/java/protect/card_locker/preferences/Settings.java @@ -107,4 +107,6 @@ public class Settings { public boolean getOledDark() { return getBoolean(R.string.settings_key_oled_dark, false); } + + public String getColor() { return getString(R.string.setting_key_theme_color, mContext.getResources().getString(R.string.settings_key_system_theme)); } } diff --git a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java index bb710b1f7..2a3cd54c3 100644 --- a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java +++ b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java @@ -140,6 +140,13 @@ public class SettingsActivity extends CatimaAppCompatActivity { refreshActivity(true); return true; }); + + Preference colorPreference = findPreference(getResources().getString(R.string.setting_key_theme_color)); + assert colorPreference != null; + colorPreference.setOnPreferenceChangeListener((preference, o) -> { + refreshActivity(true); + return true; + }); } private void refreshActivity(boolean reloadMain) { diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml index 8630f2c4a..e7351758a 100644 --- a/app/src/main/res/layout/settings_activity.xml +++ b/app/src/main/res/layout/settings_activity.xml @@ -1,9 +1,11 @@ - + android:fitsSystemWindows="true" + tools:context="protect.card_locker.preferences.SettingsActivity"> + android:layout_height="?attr/actionBarSize" /> + android:layout_height="match_parent" + android:layout_marginTop="?attr/actionBarSize" /> - + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 939599068..ed20d926c 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -38,4 +38,237 @@ #000000 #000000 + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index 4c472fc4c..db81428ba 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -12,6 +12,39 @@ @string/settings_dark_theme + + @string/settings_key_system_theme + @string/settings_key_catima_theme + @string/settings_key_red_theme + @string/settings_key_pink_theme + @string/settings_key_magenta_theme + @string/settings_key_violet_theme + @string/settings_key_blue_theme + @string/settings_key_sky_blue_theme + @string/settings_key_green_theme + + @string/settings_key_brown_theme + + + + @string/settings_system_theme + @string/settings_catima_theme + @string/settings_red_theme + @string/settings_pink_theme + @string/settings_magenta_theme + @string/settings_violet_theme + @string/settings_blue_theme + @string/settings_sky_blue_theme + @string/settings_green_theme + + @string/settings_brown_theme + + + bg diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bf381222d..8a111c1a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -221,6 +221,7 @@ pref_theme_color Theme color Catima + Red Pink Magenta Violet @@ -230,6 +231,7 @@ Grey Brown catima_theme + red_theme pink_theme magenta_theme violet_theme diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 9b0486158..7aa2a167b 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -52,4 +52,237 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 14e295d34..80d7d0a72 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -22,6 +22,15 @@ app:iconSpaceReserved="false" app:singleLineTitle="false" /> + +