requested changes

theme color preference is now before pure black background preference

new setting string arrays for when dynamic color is not available

general refactoring and formatting changes
This commit is contained in:
Katharine Chui
2022-02-04 14:35:05 +08:00
parent 3d138c9504
commit c9b8b2df9e
8 changed files with 51 additions and 129 deletions

View File

@@ -468,50 +468,29 @@ public class Utils {
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)) {
Resources resources = activity.getResources();
if (color.equals(resources.getString(R.string.settings_key_system_theme))) {
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);
}
} else if (color.equals(resources.getString(R.string.settings_key_pink_theme))) {
theme.applyStyle(R.style.pink, true);
} else if (color.equals(resources.getString(R.string.settings_key_magenta_theme))) {
theme.applyStyle(R.style.magenta, true);
} else if (color.equals(resources.getString(R.string.settings_key_violet_theme))) {
theme.applyStyle(R.style.violet, true);
} else if (color.equals(resources.getString(R.string.settings_key_blue_theme))) {
theme.applyStyle(R.style.blue, true);
} else if (color.equals(resources.getString(R.string.settings_key_sky_blue_theme))) {
theme.applyStyle(R.style.skyblue, true);
} else if (color.equals(resources.getString(R.string.settings_key_green_theme))) {
theme.applyStyle(R.style.green, true);
} else if (color.equals(resources.getString(R.string.settings_key_brown_theme))) {
theme.applyStyle(R.style.brown, true);
} else if (color.equals(resources.getString(R.string.settings_key_catima_theme))) {
// catima theme is AppTheme itself, no dynamic colors nor applyStyle
}
if (isDarkModeEnabled(activity) && settings.getOledDark()) {
theme.applyStyle(R.style.DarkBackground, true);
}

View File

@@ -108,5 +108,7 @@ public class Settings {
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)); }
public String getColor() {
return getString(R.string.setting_key_theme_color, mContext.getResources().getString(R.string.settings_key_system_theme));
}
}

View File

@@ -150,20 +150,8 @@ public class SettingsActivity extends CatimaAppCompatActivity {
return true;
});
if (!DynamicColors.isDynamicColorAvailable()) {
// remove catima from list
CharSequence[] colorValues = colorPreference.getEntryValues();
CharSequence[] colorEntries = colorPreference.getEntries();
CharSequence[] newColorValues = new CharSequence[colorValues.length - 1];
CharSequence[] newColorEntries = new CharSequence[colorEntries.length - 1];
for (int i = 0, j = 0; i < colorValues.length; i++) {
if (!colorValues[i].equals(getResources().getString(R.string.settings_key_catima_theme))) {
newColorValues[j] = colorValues[i];
newColorEntries[j] = colorEntries[i];
j++;
}
}
colorPreference.setEntries(newColorEntries);
colorPreference.setEntryValues(newColorValues);
colorPreference.setEntryValues(R.array.color_values_no_dynamic);
colorPreference.setEntries(R.array.color_value_strings_no_dynamic);
}
}

View File

@@ -40,35 +40,6 @@
</style>
<!-- color themes -->
<style name="red">
<item name="colorPrimary">#FFB4A6</item>
<item name="colorOnPrimary">#690000</item>
<item name="colorPrimaryContainer">#940000</item>
<item name="colorOnPrimaryContainer">#FFDAD3</item>
<item name="colorSecondary">#E7BDB6</item>
<item name="colorOnSecondary">#442925</item>
<item name="colorSecondaryContainer">#5D3F3A</item>
<item name="colorOnSecondaryContainer">#FFDAD3</item>
<item name="colorTertiary">#DEC48C</item>
<item name="colorOnTertiary">#3E2E04</item>
<item name="colorTertiaryContainer">#564418</item>
<item name="colorOnTertiaryContainer">#FBDFA5</item>
<item name="colorError">#FFB4A9</item>
<item name="colorErrorContainer">#930006</item>
<item name="colorOnError">#680003</item>
<item name="colorOnErrorContainer">#FFDAD4</item>
<item name="android:colorBackground">#201A19</item>
<item name="colorOnBackground">#EDE0DE</item>
<item name="colorSurface">#201A19</item>
<item name="colorOnSurface">#EDE0DE</item>
<item name="colorSurfaceVariant">#534341</item>
<item name="colorOnSurfaceVariant">#D8C2BE</item>
<item name="colorOutline">#A08C89</item>
<item name="colorOnSurfaceInverse">#201A19</item>
<item name="colorSurfaceInverse">#EDE0DE</item>
<item name="colorPrimaryInverse">#C10000</item>
</style>
<style name="pink">
<item name="colorPrimary">#FFB2C0</item>
<item name="colorOnPrimary">#670024</item>

View File

@@ -15,34 +15,47 @@
<string-array name="color_values">
<item>@string/settings_key_system_theme</item>
<item>@string/settings_key_catima_theme</item>
<item>@string/settings_key_red_theme</item>
<item>@string/settings_key_pink_theme</item>
<item>@string/settings_key_magenta_theme</item>
<item>@string/settings_key_violet_theme</item>
<item>@string/settings_key_blue_theme</item>
<item>@string/settings_key_sky_blue_theme</item>
<item>@string/settings_key_green_theme</item>
<!-- can't generate a good grey theme
<item>@string/settings_key_grey_theme</item>
-->
<item>@string/settings_key_brown_theme</item>
</string-array>
<string-array name="color_value_strings">
<item>@string/settings_system_theme</item>
<item>@string/settings_catima_theme</item>
<item>@string/settings_red_theme</item>
<item>@string/settings_pink_theme</item>
<item>@string/settings_magenta_theme</item>
<item>@string/settings_violet_theme</item>
<item>@string/settings_blue_theme</item>
<item>@string/settings_sky_blue_theme</item>
<item>@string/settings_green_theme</item>
<!--
<item>@string/settings_grey_theme</item>
-->
<item>@string/settings_brown_theme</item>
</string-array>
<string-array name="color_values_no_dynamic">
<item>@string/settings_key_system_theme</item>
<item>@string/settings_key_pink_theme</item>
<item>@string/settings_key_magenta_theme</item>
<item>@string/settings_key_violet_theme</item>
<item>@string/settings_key_blue_theme</item>
<item>@string/settings_key_sky_blue_theme</item>
<item>@string/settings_key_green_theme</item>
<item>@string/settings_key_brown_theme</item>
</string-array>
<string-array name="color_value_strings_no_dynamic">
<item>@string/settings_catima_theme</item>
<item>@string/settings_pink_theme</item>
<item>@string/settings_magenta_theme</item>
<item>@string/settings_violet_theme</item>
<item>@string/settings_blue_theme</item>
<item>@string/settings_sky_blue_theme</item>
<item>@string/settings_green_theme</item>
<item>@string/settings_brown_theme</item>
</string-array>
<string-array name="locale_values">

View File

@@ -221,7 +221,6 @@
<string name="setting_key_theme_color" translatable="false">pref_theme_color</string>
<string name="settings_theme_color">Theme color</string>
<string name="settings_catima_theme">Catima</string>
<string name="settings_red_theme">Red</string>
<string name="settings_pink_theme">Pink</string>
<string name="settings_magenta_theme">Magenta</string>
<string name="settings_violet_theme">Violet</string>
@@ -231,7 +230,6 @@
<string name="settings_grey_theme">Grey</string>
<string name="settings_brown_theme">Brown</string>
<string name="settings_key_catima_theme" translatable="false">catima_theme</string>
<string name="settings_key_red_theme" translatable="false">red_theme</string>
<string name="settings_key_pink_theme" translatable="false">pink_theme</string>
<string name="settings_key_magenta_theme" translatable="false">magenta_theme</string>
<string name="settings_key_violet_theme" translatable="false">violet_theme</string>

View File

@@ -54,35 +54,6 @@
<style name="DarkBackground" />
<!-- color themes -->
<style name="red">
<item name="colorPrimary">#C10000</item>
<item name="colorOnPrimary">#FFFFFF</item>
<item name="colorPrimaryContainer">#FFDAD3</item>
<item name="colorOnPrimaryContainer">#410000</item>
<item name="colorSecondary">#775651</item>
<item name="colorOnSecondary">#FFFFFF</item>
<item name="colorSecondaryContainer">#FFDAD3</item>
<item name="colorOnSecondaryContainer">#2C1511</item>
<item name="colorTertiary">#705C2E</item>
<item name="colorOnTertiary">#FFFFFF</item>
<item name="colorTertiaryContainer">#FBDFA5</item>
<item name="colorOnTertiaryContainer">#261A00</item>
<item name="colorError">#BA1B1B</item>
<item name="colorErrorContainer">#FFDAD4</item>
<item name="colorOnError">#FFFFFF</item>
<item name="colorOnErrorContainer">#410001</item>
<item name="android:colorBackground">#FCFCFC</item>
<item name="colorOnBackground">#201A19</item>
<item name="colorSurface">#FCFCFC</item>
<item name="colorOnSurface">#201A19</item>
<item name="colorSurfaceVariant">#F5DEDA</item>
<item name="colorOnSurfaceVariant">#534341</item>
<item name="colorOutline">#867370</item>
<item name="colorOnSurfaceInverse">#FBEEEC</item>
<item name="colorSurfaceInverse">#362F2E</item>
<item name="colorPrimaryInverse">#FFB4A6</item>
</style>
<style name="pink">
<item name="colorPrimary">#BC0049</item>
<item name="colorOnPrimary">#FFFFFF</item>

View File

@@ -15,13 +15,6 @@
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/settings_key_oled_dark"
android:title="@string/settings_oled_dark"
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
<ListPreference
android:key="@string/setting_key_theme_color"
android:title="@string/settings_theme_color"
@@ -31,6 +24,13 @@
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/settings_key_oled_dark"
android:title="@string/settings_oled_dark"
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
<ListPreference
android:defaultValue=""
android:entries="@array/locale_values"