From db25cc416d607046c40a547a38669d62ebace0e6 Mon Sep 17 00:00:00 2001 From: SavagePeanut Date: Wed, 13 Mar 2024 20:19:16 +0000 Subject: [PATCH 1/2] Custom background color --- src/cheogram/res/values/colors.xml | 8 ++++++++ src/cheogram/res/values/themes.xml | 6 ++++++ .../conversations/ui/SettingsActivity.java | 9 ++++++++- .../conversations/utils/ThemeHelper.java | 20 +++++++++++++++++++ src/main/res/xml/preferences.xml | 10 ++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/cheogram/res/values/colors.xml b/src/cheogram/res/values/colors.xml index 54eadd7c3e089e029f8c72f4c27ecfa3bc1b4406..a391bea697fb54535bbefdaaaad87133cd0fc4ce 100644 --- a/src/cheogram/res/values/colors.xml +++ b/src/cheogram/res/values/colors.xml @@ -9,6 +9,14 @@ #FFC700 @color/perpy + @color/grey50 + @color/grey200 + @color/grey300 + + @color/grey800 + @color/grey700 + @color/grey900 @color/black_perpy + @color/black_perpy diff --git a/src/cheogram/res/values/themes.xml b/src/cheogram/res/values/themes.xml index 27c5ace57fa2446e90d5fdef959bbb51e84bd5f8..bcd7c9097674283543c1fbd83f6db9417ae1c8cf 100644 --- a/src/cheogram/res/values/themes.xml +++ b/src/cheogram/res/values/themes.xml @@ -361,6 +361,9 @@ diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index 92953da6f66a468d23f4041803fab56298e12231..05b0c1f6dbf7f4c2ff6dab223cc278991a3c17c0 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -581,7 +581,14 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference xmppConnectionService.reinitializeMuclumbusService(); } else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) { xmppConnectionService.expireOldMessages(true); - } else if (name.equals(THEME) || name.equals("custom_theme_primary") || name.equals("custom_theme_primary_dark") || name.equals("custom_theme_accent") || name.equals("custom_theme_dark")) { + } else if ( name.equals(THEME) || + name.equals("custom_theme_primary") || + name.equals("custom_theme_primary_dark") || + name.equals("custom_theme_accent") || + name.equals("custom_theme_dark") || + name.equals("custom_theme_background_primary") || + name.equals("custom_theme_background_primary_dark")) + { final int theme = findTheme(); xmppConnectionService.setTheme(theme); ThemeHelper.applyCustomColors(xmppConnectionService); diff --git a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java index 3ce5f16de1ac2aa397b83502436738dbb5522901..e844f07ba59744249bc08e0a04cf058660d4fe6b 100644 --- a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java @@ -64,6 +64,26 @@ public class ThemeHelper { if (sharedPreferences.contains("custom_theme_primary")) colors.put(R.color.custom_theme_primary, sharedPreferences.getInt("custom_theme_primary", 0)); if (sharedPreferences.contains("custom_theme_primary_dark")) colors.put(R.color.custom_theme_primary_dark, sharedPreferences.getInt("custom_theme_primary_dark", 0)); if (sharedPreferences.contains("custom_theme_accent")) colors.put(R.color.custom_theme_accent, sharedPreferences.getInt("custom_theme_accent", 0)); + if (sharedPreferences.contains("custom_theme_background_primary")) { + int background_primary = sharedPreferences.getInt("custom_theme_background_primary", 0); + int alpha = (background_primary >> 24) & 0xFF; + int red = (background_primary >> 16) & 0xFF; + int green = (background_primary >> 8) & 0xFF; + int blue = background_primary & 0xFF; + colors.put(R.color.custom_theme_background_primary, background_primary); + colors.put(R.color.custom_theme_background_secondary, (int)((alpha << 24) | ((int)(red*.9) << 16) | ((int)(green*.9) << 8) | (int)(blue*.9))); + colors.put(R.color.custom_theme_background_tertiary, (int)((alpha << 24) | ((int)(red*.85) << 16) | ((int)(green*.85) << 8) | (int)(blue*.85))); + } + if (sharedPreferences.contains("custom_theme_background_primary_dark")) { + int background_primary = sharedPreferences.getInt("custom_theme_background_primary_dark", 0); + int alpha = (background_primary >> 24) & 0xFF; + int red = (background_primary >> 16) & 0xFF; + int green = (background_primary >> 8) & 0xFF; + int blue = background_primary & 0xFF; + colors.put(R.color.custom_theme_background_primary_dark, background_primary); + colors.put(R.color.custom_theme_background_secondary_dark, (int)((alpha << 24) | ((int)(40 + red*.84) << 16) | ((int)(40 + green*.84) << 8) | (int)(40 + blue*.84))); + colors.put(R.color.custom_theme_background_tertiary_dark, (int)((alpha << 24) | ((int)(red*.5) << 16) | ((int)(green*.5) << 8) | (int)(blue*.5))); + } if (colors.isEmpty()) return colors; ResourcesLoader loader = ColorResourcesLoaderCreator.create(context, colors); diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 41fa01d0f2e626c8e5462a05bfb700136da9ffcc..260cca0b19931ea19161fe530fde121716f4dd3b 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -211,6 +211,16 @@ android:defaultValue="false" android:key="custom_theme_dark" android:title="Custom Theme is Dark?" /> + + Date: Wed, 13 Mar 2024 20:54:31 +0000 Subject: [PATCH 2/2] follow system dark mode with custom theme --- .../java/eu/siacs/conversations/ui/SettingsActivity.java | 1 + src/main/java/eu/siacs/conversations/utils/ThemeHelper.java | 4 +++- src/main/res/xml/preferences.xml | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index 05b0c1f6dbf7f4c2ff6dab223cc278991a3c17c0..de24c026fc47b379a896191edb20be6a73d3c3f8 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -582,6 +582,7 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference } else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) { xmppConnectionService.expireOldMessages(true); } else if ( name.equals(THEME) || + name.equals("custom_theme_automatic") || name.equals("custom_theme_primary") || name.equals("custom_theme_primary_dark") || name.equals("custom_theme_accent") || diff --git a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java index e844f07ba59744249bc08e0a04cf058660d4fe6b..2f6fd2e1dcb2887dfb6f7dcaf41aa84bc27c5be7 100644 --- a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java @@ -137,7 +137,9 @@ public class ThemeHelper { private static boolean isDark(final SharedPreferences sharedPreferences, final Resources resources) { final String setting = sharedPreferences.getString(SettingsActivity.THEME, resources.getString(R.string.theme)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && "automatic".equals(setting)) { + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && "automatic".equals(setting)) || + ("custom".equals(setting) && sharedPreferences.getBoolean("custom_theme_automatic", false)) + ) { return (resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; } else { if ("custom".equals(setting)) return sharedPreferences.getBoolean("custom_theme_dark", false); diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 260cca0b19931ea19161fe530fde121716f4dd3b..7d5c526c6af8cf95407acb6726e86ffd2615fb7e 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -209,6 +209,12 @@ +