Expose more colors to users (only for user-defined themes) (#239)

This commit is contained in:
BlackyHawky 2023-10-23 23:55:19 +02:00 committed by GitHub
parent 9a7968ea14
commit 02a3fe2d19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 11 deletions

View file

@ -134,17 +134,23 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
case THEME_USER: case THEME_USER:
final int accent = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_ACCENT_SUFFIX, false); final int accent = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_ACCENT_SUFFIX, false);
final int keyBgColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_KEYS_SUFFIX, false); final int keyBgColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_KEYS_SUFFIX, false);
final int functionalKeyBgColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX, false);
final int spaceBarBgColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_SPACEBAR_SUFFIX, false);
final int keyTextColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_TEXT_SUFFIX, false); final int keyTextColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_TEXT_SUFFIX, false);
final int hintTextColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_HINT_TEXT_SUFFIX, false); final int hintTextColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_HINT_TEXT_SUFFIX, false);
final int spaceBarTextColor = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_SPACEBAR_TEXT_SUFFIX, false);
final int background = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_BACKGROUND_SUFFIX, false); final int background = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_BACKGROUND_SUFFIX, false);
return new Colors(themeStyle, hasBorders, accent, background, keyBgColor, ColorUtilKt.brightenOrDarken(keyBgColor, true), keyBgColor, keyTextColor, hintTextColor); return new Colors(themeStyle, hasBorders, accent, background, keyBgColor, functionalKeyBgColor, spaceBarBgColor, keyTextColor, hintTextColor, spaceBarTextColor);
case THEME_USER_NIGHT: case THEME_USER_NIGHT:
final int accent2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_ACCENT_SUFFIX, true); final int accent2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_ACCENT_SUFFIX, true);
final int keyBgColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_KEYS_SUFFIX, true); final int keyBgColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_KEYS_SUFFIX, true);
final int functionalKeyBgColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX, true);
final int spaceBarBgColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_SPACEBAR_SUFFIX, true);
final int keyTextColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_TEXT_SUFFIX, true); final int keyTextColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_TEXT_SUFFIX, true);
final int hintTextColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_HINT_TEXT_SUFFIX, true); final int hintTextColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_HINT_TEXT_SUFFIX, true);
final int spaceBarTextColor2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_SPACEBAR_TEXT_SUFFIX, true);
final int background2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_BACKGROUND_SUFFIX, true); final int background2 = Settings.readUserColor(prefs, context, Settings.PREF_COLOR_BACKGROUND_SUFFIX, true);
return new Colors(themeStyle, hasBorders, accent2, background2, keyBgColor2, ColorUtilKt.brightenOrDarken(keyBgColor2, true), keyBgColor2, keyTextColor2, hintTextColor2); return new Colors(themeStyle, hasBorders, accent2, background2, keyBgColor2, functionalKeyBgColor2, spaceBarBgColor2, keyTextColor2, hintTextColor2, spaceBarTextColor2);
case THEME_DARK: case THEME_DARK:
return new Colors( return new Colors(
themeStyle, themeStyle,
@ -156,7 +162,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
Color.parseColor("#2d393f"), Color.parseColor("#2d393f"),
Color.parseColor("#364248"), Color.parseColor("#364248"),
ContextCompat.getColor(context, R.color.key_text_color_lxx_dark), ContextCompat.getColor(context, R.color.key_text_color_lxx_dark),
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark) ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark),
ContextCompat.getColor(context, R.color.spacebar_letter_color_lxx_dark)
); );
case THEME_HOLO_WHITE: case THEME_HOLO_WHITE:
return new Colors( return new Colors(
@ -169,6 +176,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
Color.parseColor("#444444"), // should be 222222, but the key drawable is already grey Color.parseColor("#444444"), // should be 222222, but the key drawable is already grey
Color.parseColor("#FFFFFF"), Color.parseColor("#FFFFFF"),
Color.parseColor("#FFFFFF"), Color.parseColor("#FFFFFF"),
Color.parseColor("#282828"),
Color.parseColor("#282828") Color.parseColor("#282828")
); );
case THEME_DARKER: case THEME_DARKER:
@ -181,7 +189,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
ContextCompat.getColor(context, R.color.key_background_functional_lxx_dark_border), ContextCompat.getColor(context, R.color.key_background_functional_lxx_dark_border),
ContextCompat.getColor(context, R.color.key_background_normal_lxx_dark_border), ContextCompat.getColor(context, R.color.key_background_normal_lxx_dark_border),
ContextCompat.getColor(context, R.color.key_text_color_lxx_dark), ContextCompat.getColor(context, R.color.key_text_color_lxx_dark),
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark) ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark),
ContextCompat.getColor(context, R.color.spacebar_letter_color_lxx_dark)
); );
case THEME_BLACK: case THEME_BLACK:
return new Colors( return new Colors(
@ -193,7 +202,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
ContextCompat.getColor(context, R.color.background_amoled_dark), ContextCompat.getColor(context, R.color.background_amoled_dark),
ContextCompat.getColor(context, R.color.background_amoled_dark), ContextCompat.getColor(context, R.color.background_amoled_dark),
ContextCompat.getColor(context, R.color.key_text_color_lxx_dark), ContextCompat.getColor(context, R.color.key_text_color_lxx_dark),
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark) ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark),
ContextCompat.getColor(context, R.color.spacebar_letter_color_lxx_dark)
); );
case THEME_LIGHT: case THEME_LIGHT:
default: default:
@ -206,7 +216,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
ContextCompat.getColor(context, R.color.key_background_functional_lxx_light_border), ContextCompat.getColor(context, R.color.key_background_functional_lxx_light_border),
ContextCompat.getColor(context, R.color.key_background_normal_lxx_light_border), ContextCompat.getColor(context, R.color.key_background_normal_lxx_light_border),
ContextCompat.getColor(context, R.color.key_text_color_lxx_light), ContextCompat.getColor(context, R.color.key_text_color_lxx_light),
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_light) ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_light),
ContextCompat.getColor(context, R.color.spacebar_letter_color_lxx_light)
); );
} }
} }

View file

@ -35,7 +35,8 @@ class Colors (
val functionalKey: Int, val functionalKey: Int,
val spaceBar: Int, val spaceBar: Int,
val keyText: Int, val keyText: Int,
val keyHintText: Int val keyHintText: Int,
val spaceBarText: Int
) { ) {
val navBar: Int val navBar: Int
/** brightened or darkened variant of [background], to be used if exact background color would be /** brightened or darkened variant of [background], to be used if exact background color would be
@ -45,7 +46,6 @@ class Colors (
val doubleAdjustedBackground: Int val doubleAdjustedBackground: Int
/** brightened or darkened variant of [keyText] */ /** brightened or darkened variant of [keyText] */
val adjustedKeyText: Int val adjustedKeyText: Int
val spaceBarText: Int
val backgroundFilter: ColorFilter val backgroundFilter: ColorFilter
val adjustedBackgroundFilter: ColorFilter val adjustedBackgroundFilter: ColorFilter
@ -74,11 +74,9 @@ class Colors (
val darkerBackground = adjustLuminosityAndKeepAlpha(background, -0.2f) val darkerBackground = adjustLuminosityAndKeepAlpha(background, -0.2f)
navBar = darkerBackground navBar = darkerBackground
keyboardBackground = GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(background, darkerBackground)) keyboardBackground = GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(background, darkerBackground))
spaceBarText = keyText
} else { } else {
navBar = background navBar = background
keyboardBackground = null keyboardBackground = null
spaceBarText = keyHintText
} }
// create color filters // create color filters

View file

@ -33,8 +33,11 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
private val colorPrefs = listOf( private val colorPrefs = listOf(
Settings.PREF_COLOR_BACKGROUND_SUFFIX, Settings.PREF_COLOR_BACKGROUND_SUFFIX,
Settings.PREF_COLOR_KEYS_SUFFIX, Settings.PREF_COLOR_KEYS_SUFFIX,
Settings.PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX,
Settings.PREF_COLOR_SPACEBAR_SUFFIX,
Settings.PREF_COLOR_TEXT_SUFFIX, Settings.PREF_COLOR_TEXT_SUFFIX,
Settings.PREF_COLOR_HINT_TEXT_SUFFIX, Settings.PREF_COLOR_HINT_TEXT_SUFFIX,
Settings.PREF_COLOR_SPACEBAR_TEXT_SUFFIX,
Settings.PREF_COLOR_ACCENT_SUFFIX, Settings.PREF_COLOR_ACCENT_SUFFIX,
) )
@ -65,8 +68,11 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
val colorPrefNames = listOf( val colorPrefNames = listOf(
R.string.select_color_background, R.string.select_color_background,
R.string.select_color_key_background, R.string.select_color_key_background,
R.string.select_color_functional_key_background,
R.string.select_color_spacebar_background,
R.string.select_color_key, R.string.select_color_key,
R.string.select_color_key_hint, R.string.select_color_key_hint,
R.string.select_color_spacebar_text,
R.string.select_color_accent, R.string.select_color_accent,
).map { requireContext().getString(it) } ).map { requireContext().getString(it) }
val prefPrefix = if (isNight) Settings.PREF_THEME_USER_COLOR_NIGHT_PREFIX else Settings.PREF_THEME_USER_COLOR_PREFIX val prefPrefix = if (isNight) Settings.PREF_THEME_USER_COLOR_NIGHT_PREFIX else Settings.PREF_THEME_USER_COLOR_PREFIX

View file

@ -62,6 +62,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_THEME_USER_COLOR_PREFIX = "theme_color_"; public static final String PREF_THEME_USER_COLOR_PREFIX = "theme_color_";
public static final String PREF_THEME_USER_COLOR_NIGHT_PREFIX = "theme_dark_color_"; public static final String PREF_THEME_USER_COLOR_NIGHT_PREFIX = "theme_dark_color_";
public static final String PREF_COLOR_KEYS_SUFFIX = "keys"; public static final String PREF_COLOR_KEYS_SUFFIX = "keys";
public static final String PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX = "functional_keys";
public static final String PREF_COLOR_SPACEBAR_SUFFIX = "spacebar";
public static final String PREF_COLOR_SPACEBAR_TEXT_SUFFIX = "spacebar_text";
public static final String PREF_COLOR_ACCENT_SUFFIX = "accent"; public static final String PREF_COLOR_ACCENT_SUFFIX = "accent";
public static final String PREF_COLOR_TEXT_SUFFIX = "text"; public static final String PREF_COLOR_TEXT_SUFFIX = "text";
public static final String PREF_COLOR_HINT_TEXT_SUFFIX = "hint_text"; public static final String PREF_COLOR_HINT_TEXT_SUFFIX = "hint_text";
@ -511,9 +514,16 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
else return Color.WHITE; else return Color.WHITE;
case PREF_COLOR_HINT_TEXT_SUFFIX: case PREF_COLOR_HINT_TEXT_SUFFIX:
if (ColorUtilKt.isBrightColor(readUserColor(prefs, context, PREF_COLOR_KEYS_SUFFIX, isNight))) return Color.DKGRAY; if (ColorUtilKt.isBrightColor(readUserColor(prefs, context, PREF_COLOR_KEYS_SUFFIX, isNight))) return Color.DKGRAY;
else return Color.LTGRAY; else return readUserColor(prefs, context, PREF_COLOR_TEXT_SUFFIX, isNight);
case PREF_COLOR_KEYS_SUFFIX: case PREF_COLOR_KEYS_SUFFIX:
return ColorUtilKt.brightenOrDarken(readUserColor(prefs, context, PREF_COLOR_BACKGROUND_SUFFIX, isNight), isNight); return ColorUtilKt.brightenOrDarken(readUserColor(prefs, context, PREF_COLOR_BACKGROUND_SUFFIX, isNight), isNight);
case PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX:
return ColorUtilKt.brightenOrDarken(readUserColor(prefs, context, PREF_COLOR_KEYS_SUFFIX, isNight), true);
case PREF_COLOR_SPACEBAR_SUFFIX:
return readUserColor(prefs, context, PREF_COLOR_KEYS_SUFFIX, isNight);
case PREF_COLOR_SPACEBAR_TEXT_SUFFIX:
if (ColorUtilKt.isBrightColor(readUserColor(prefs, context, PREF_COLOR_SPACEBAR_SUFFIX, isNight))) return Color.DKGRAY;
else return readUserColor(prefs, context, PREF_COLOR_TEXT_SUFFIX, isNight);
case PREF_COLOR_BACKGROUND_SUFFIX: case PREF_COLOR_BACKGROUND_SUFFIX:
default: default:
return ContextCompat.getColor(getDayNightContext(context, isNight), R.color.keyboard_background); return ContextCompat.getColor(getDayNightContext(context, isNight), R.color.keyboard_background);

View file

@ -220,6 +220,9 @@ Nouveau dictionnaire:
<string name="select_color_key">Texte des touches</string> <string name="select_color_key">Texte des touches</string>
<string name="select_color_key_hint">Indice des touches</string> <string name="select_color_key_hint">Indice des touches</string>
<string name="select_color_key_background">Arrière-plan des touches</string> <string name="select_color_key_background">Arrière-plan des touches</string>
<string name="select_color_functional_key_background">Arrière-plan des touches fonctionnelles</string>
<string name="select_color_spacebar_background">Arrière-plan de la barre d\'espace</string>
<string name="select_color_spacebar_text">Texte de la barre d\'espace</string>
<string name="select_color_accent">Couleur d\'accentuation</string> <string name="select_color_accent">Couleur d\'accentuation</string>
<string name="settings_screen_about">À propos</string> <string name="settings_screen_about">À propos</string>
<string name="about_github_link" >Lien vers GitHub</string> <string name="about_github_link" >Lien vers GitHub</string>

View file

@ -49,11 +49,13 @@
<!-- Color resources for the old LXX_Light theme, now used for THEME_LIGHT. --> <!-- Color resources for the old LXX_Light theme, now used for THEME_LIGHT. -->
<color name="key_hint_letter_color_lxx_light">#B337474F</color> <color name="key_hint_letter_color_lxx_light">#B337474F</color>
<color name="spacebar_letter_color_lxx_light">#B337474F</color>
<color name="key_text_color_lxx_light">#37474F</color> <color name="key_text_color_lxx_light">#37474F</color>
<!-- Color resources for the old LXX_Dark theme, now used for several dark themes. --> <!-- Color resources for the old LXX_Dark theme, now used for several dark themes. -->
<color name="key_text_color_lxx_dark">#FFFFFF</color> <color name="key_text_color_lxx_dark">#FFFFFF</color>
<color name="key_hint_letter_color_lxx_dark">#80FFFFFF</color> <color name="key_hint_letter_color_lxx_dark">#80FFFFFF</color>
<color name="spacebar_letter_color_lxx_dark">#80FFFFFF</color>
<!-- Color resources for the old LXX_Dark_Border theme, now for THEME_DARKER. --> <!-- Color resources for the old LXX_Dark_Border theme, now for THEME_DARKER. -->
<color name="keyboard_background_lxx_dark_border">#0d0d0d</color> <color name="keyboard_background_lxx_dark_border">#0d0d0d</color>

View file

@ -606,6 +606,12 @@ New dictionary:
<string name="select_color_key_hint">Key hint text</string> <string name="select_color_key_hint">Key hint text</string>
<!-- Selection: key color. --> <!-- Selection: key color. -->
<string name="select_color_key_background">Key background</string> <string name="select_color_key_background">Key background</string>
<!-- Selection: functional key color. -->
<string name="select_color_functional_key_background">Functional key background</string>
<!-- Selection: space bar color. -->
<string name="select_color_spacebar_background">Space bar background</string>
<!-- Selection: space bar text color. -->
<string name="select_color_spacebar_text">Space bar text</string>
<!-- Selection: accent color. --> <!-- Selection: accent color. -->
<string name="select_color_accent">Accent</string> <string name="select_color_accent">Accent</string>
<!-- Settings screen title for about [CHAR LIMIT=33]--> <!-- Settings screen title for about [CHAR LIMIT=33]-->