add holo theme base on custom colors, and remove old theme selection (wip)

This commit is contained in:
Helium314 2023-09-01 00:35:40 +02:00
parent ede5bf8f4f
commit e2d2889d81
13 changed files with 161 additions and 125 deletions

View file

@ -19,7 +19,6 @@ package org.dslul.openboard.inputmethod.keyboard;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.util.Log;
@ -31,37 +30,25 @@ import org.dslul.openboard.inputmethod.latin.settings.Settings;
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public final class KeyboardTheme implements Comparable<KeyboardTheme> {
// old themes
public static final String THEME_FAMILY_MATERIAL = "Material";
public static final String THEME_FAMILY_HOLO = "Holo (Legacy)";
public static final String THEME_VARIANT_HOLO_WHITE = "White";
public static final String THEME_VARIANT_HOLO_BLUE = "Blue";
public static final String THEME_VARIANT_CUSTOM = "User-defined";
public static final String THEME_VARIANT_HOLO_USER = "User-defined (Holo)";
public static final String THEME_STYLE_MATERIAL = "Material";
public static final String THEME_STYLE_HOLO = "Holo";
// new themes using the custom colors
public static final String THEME_LIGHT = "light";
public static final String THEME_HOLO_WHITE = "holo_white"; // todo: rename (but useful to have for testing)
public static final String THEME_DARK = "dark";
public static final String THEME_DARKER = "darker";
public static final String THEME_BLACK = "black";
public static final String THEME_USER = "user";
public static final String THEME_USER_DARK = "user_dark";
public static final String[] CUSTOM_THEME_VARIANTS = new String[] { THEME_LIGHT, THEME_DARK, THEME_DARKER, THEME_BLACK, THEME_USER };
public static final String[] CUSTOM_THEME_VARIANTS_DARK = new String[] { THEME_DARK, THEME_DARKER, THEME_BLACK, THEME_USER_DARK };
public static final String[] THEME_VARIANTS = new String[] { THEME_LIGHT, THEME_HOLO_WHITE, THEME_DARK, THEME_DARKER, THEME_BLACK, THEME_USER };
public static final String[] THEME_VARIANTS_DARK = new String[] { THEME_DARK, THEME_DARKER, THEME_BLACK, THEME_USER_DARK };
public static final String[] THEME_FAMILIES = {THEME_FAMILY_MATERIAL, THEME_FAMILY_HOLO};
public static final Map<String, String[]> THEME_VARIANTS = new HashMap<>();
static {
THEME_VARIANTS.put(THEME_FAMILY_MATERIAL, CUSTOM_THEME_VARIANTS);
THEME_VARIANTS.put(THEME_FAMILY_HOLO,
new String[] {THEME_VARIANT_HOLO_WHITE, THEME_VARIANT_HOLO_BLUE, THEME_VARIANT_HOLO_USER});
}
public static final String[] THEME_STYLES = { THEME_STYLE_MATERIAL, THEME_STYLE_HOLO };
private static final String TAG = KeyboardTheme.class.getSimpleName();
@ -190,28 +177,19 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
return theme.mThemeName;
}
public static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs) {
saveKeyboardThemeId(themeId, prefs, Build.VERSION.SDK_INT);
}
/* package private for testing */
static String getPreferenceKey(final int sdkVersion) {
if (sdkVersion <= VERSION_CODES.KITKAT) {
return KLP_KEYBOARD_THEME_KEY;
}
return LXX_KEYBOARD_THEME_KEY;
}
/* package private for testing */
static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs,
final int sdkVersion) {
final String prefKey = getPreferenceKey(sdkVersion);
prefs.edit().putString(prefKey, Integer.toString(themeId)).apply();
}
// todo: this actually should be called style now, as the colors are independent
// and selection should be simplified, becuase really...
public static KeyboardTheme getKeyboardTheme(final Context context) {
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context);
return getKeyboardTheme(prefs, Build.VERSION.SDK_INT, KEYBOARD_THEMES);
final String style = prefs.getString(Settings.PREF_THEME_STYLE, THEME_STYLE_MATERIAL);
final boolean borders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false);
final int matchingId = style.equals(THEME_STYLE_HOLO) ? THEME_ID_HOLO_CUSTOM : (borders ? THEME_ID_LXX_CUSTOM_BORDER : THEME_ID_LXX_CUSTOM);
for (int i = 0; i < KEYBOARD_THEMES.length; i++) {
if (KEYBOARD_THEMES[i].mThemeId == matchingId)
return KEYBOARD_THEMES[i];
}
return KEYBOARD_THEMES[2]; // custom no border
// return getKeyboardTheme(prefs, Build.VERSION.SDK_INT, KEYBOARD_THEMES);
}
/* package private for testing */
@ -237,24 +215,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
}
public static String getThemeFamily(int themeId) {
if (themeId == THEME_ID_HOLO_BLUE || themeId == THEME_ID_HOLO_WHITE || themeId == THEME_ID_HOLO_CUSTOM) return THEME_FAMILY_HOLO;
return THEME_FAMILY_MATERIAL;
}
public static String getThemeVariant(int themeId) {
switch (themeId) {
case THEME_ID_HOLO_WHITE:
return THEME_VARIANT_HOLO_WHITE;
case THEME_ID_HOLO_BLUE:
return THEME_VARIANT_HOLO_BLUE;
case THEME_ID_LXX_CUSTOM:
case THEME_ID_LXX_CUSTOM_BORDER:
return THEME_VARIANT_CUSTOM;
case THEME_ID_HOLO_CUSTOM:
return THEME_VARIANT_HOLO_USER;
default:
return null;
}
if (themeId == THEME_ID_HOLO_BLUE || themeId == THEME_ID_HOLO_WHITE || themeId == THEME_ID_HOLO_CUSTOM) return THEME_STYLE_HOLO;
return THEME_STYLE_MATERIAL;
}
public static boolean getHasKeyBorders(int themeId) {
@ -279,37 +241,26 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
}
}
public static int getThemeForParameters(String family, String variant,
boolean keyBorders) {
if (THEME_FAMILY_HOLO.equals(family)) {
if (THEME_VARIANT_HOLO_BLUE.equals(variant)) return THEME_ID_HOLO_BLUE;
if (THEME_VARIANT_HOLO_USER.equals(variant)) return THEME_ID_HOLO_CUSTOM;
return THEME_ID_HOLO_WHITE;
}
if (keyBorders) return THEME_ID_LXX_CUSTOM_BORDER;
return THEME_ID_LXX_CUSTOM;
}
// todo (later): material you, system accent, ...
// todo: copies of original themes might need adjustments, though maybe it's only Colors that needs to be adjusted
public static Colors getCustomTheme(String theme, Context context, SharedPreferences prefs) {
switch (theme) {
public static Colors getThemeColors(final String themeColors, final String themeStyle, final Context context, final SharedPreferences prefs) {
switch (themeColors) {
case THEME_USER:
final int accent = prefs.getInt(Settings.PREF_THEME_USER_COLOR_ACCENT, Color.BLUE);
final int keyBgColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_KEYS, Color.LTGRAY);
final int keyTextColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_TEXT, Color.WHITE);
final int hintTextColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_HINT_TEXT, Color.WHITE);
final int background = prefs.getInt(Settings.PREF_THEME_USER_COLOR_BACKGROUND, Color.DKGRAY);
return new Colors(accent, background, keyBgColor, Colors.brightenOrDarken(keyBgColor, true), keyBgColor, keyTextColor, hintTextColor);
return Colors.newColors(themeStyle, accent, background, keyBgColor, Colors.brightenOrDarken(keyBgColor, true), keyBgColor, keyTextColor, hintTextColor);
case THEME_USER_DARK:
final int accent2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_ACCENT, Color.BLUE);
final int keyBgColor2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_KEYS, Color.LTGRAY);
final int keyTextColor2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_TEXT, Color.WHITE);
final int hintTextColor2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_HINT_TEXT, Color.WHITE);
final int background2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_BACKGROUND, Color.DKGRAY);
return new Colors(accent2, background2, keyBgColor2, Colors.brightenOrDarken(keyBgColor2, true), keyBgColor2, keyTextColor2, hintTextColor2);
return Colors.newColors(themeStyle, accent2, background2, keyBgColor2, Colors.brightenOrDarken(keyBgColor2, true), keyBgColor2, keyTextColor2, hintTextColor2);
case THEME_DARK:
return new Colors(
return Colors.newColors(
themeStyle,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
// colors taken from the drawable
Color.parseColor("#263238"),
@ -319,8 +270,21 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
ContextCompat.getColor(context, R.color.key_text_color_lxx_dark),
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark)
);
case THEME_HOLO_WHITE:
return Colors.newColors(
themeStyle,
Color.parseColor("#FFFFFF"),
// colors taken from the drawable
Color.parseColor("#282828"),
Color.parseColor("#FFFFFF"), // transparency!
Color.parseColor("#444444"), // should be 222222, but the key drawable is already grey
Color.parseColor("#FFFFFF"),
Color.parseColor("#FFFFFF"),
Color.parseColor("#282828")
);
case THEME_DARKER:
return new Colors(
return Colors.newColors(
themeStyle,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
ContextCompat.getColor(context, R.color.keyboard_background_lxx_dark_border),
ContextCompat.getColor(context, R.color.key_background_normal_lxx_dark_border),
@ -330,7 +294,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark)
);
case THEME_BLACK:
return new Colors(
return Colors.newColors(
themeStyle,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
ContextCompat.getColor(context, R.color.background_amoled_black),
ContextCompat.getColor(context, R.color.background_amoled_dark),
@ -341,7 +306,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
);
case THEME_LIGHT:
default:
return new Colors(
return Colors.newColors(
themeStyle,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_light),
ContextCompat.getColor(context, R.color.keyboard_background_lxx_light_border),
ContextCompat.getColor(context, R.color.key_background_normal_lxx_light_border),

View file

@ -38,6 +38,7 @@ import org.dslul.openboard.inputmethod.keyboard.internal.KeyVisualAttributes;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.common.HoloColors;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView;
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
@ -136,6 +137,7 @@ public class KeyboardView extends View {
public KeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
mColors = Settings.getInstance().getCurrent().mColors;
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
@ -149,6 +151,9 @@ public class KeyboardView extends View {
R.styleable.KeyboardView_spacebarBackground);
mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground.mutate()
: keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate();
if (mColors.getClass() == HoloColors.class) // todo: this logic should be in Colors, not here
mActionKeyBackground = mFunctionalKeyBackground;
else
mActionKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate();
mSpacebarIconWidthRatio = keyboardViewAttr.getFloat(
@ -175,7 +180,6 @@ public class KeyboardView extends View {
mPaint.setAntiAlias(true);
mColors = Settings.getInstance().getCurrent().mColors;
final Class<?> c = this.getClass();
if (c == MoreKeysKeyboardView.class) {
mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_ADJUSTED_BACKGROUND);
@ -189,9 +193,16 @@ public class KeyboardView extends View {
mColors.setBackgroundColor(mFunctionalKeyBackground, Colors.TYPE_FUNCTIONAL);
if (this.getClass() == MoreKeysKeyboardView.class)
getBackground().setColorFilter(mColors.adjustedBackgroundFilter);
else {
// todo: this should only be applied to specific keyboards, check original version for which one
// and actually this again is something that maybe should be done in Colors
final Drawable keyboardBackground = mColors.getKeyboardBackground();
if (this.getClass() != MoreSuggestionsView.class && keyboardBackground != null)
setBackground(keyboardBackground);
else
getBackground().setColorFilter(mColors.backgroundFilter);
}
}
@Nullable
public KeyVisualAttributes getKeyVisualAttribute() {
@ -610,7 +621,7 @@ public class KeyboardView extends View {
}
private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) {
if (key.isAccentColored()) {
if (key.isAccentColored() && mColors.getClass() != HoloColors.class) { // todo: again sth that should not be here
icon.setColorFilter(mColors.actionKeyIconColorFilter);
} else if (key.isShift() && keyboard != null) {
// todo (idea): replace shift icon with white one and use the normal multiply filters

View file

@ -52,8 +52,10 @@ import org.dslul.openboard.inputmethod.keyboard.internal.TimerHandler;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.RichInputMethodSubtype;
import org.dslul.openboard.inputmethod.latin.SuggestedWords;
import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.common.CoordinateUtils;
import org.dslul.openboard.inputmethod.latin.common.HoloColors;
import org.dslul.openboard.inputmethod.latin.settings.DebugSettings;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils;
@ -61,6 +63,7 @@ import org.dslul.openboard.inputmethod.latin.utils.LanguageOnSpacebarUtils;
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.WeakHashMap;
@ -216,7 +219,11 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
mLanguageOnSpacebarTextColor = Settings.getInstance().getCurrent().mColors.keyHintText; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
final Colors colors = Settings.getInstance().getCurrent().mColors;
if (colors.getClass() == HoloColors.class) // todo: this logic should be in Colors
mLanguageOnSpacebarTextColor = colors.keyText;
else
mLanguageOnSpacebarTextColor = colors.keyHintText; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED);

View file

@ -103,6 +103,10 @@ class ClipboardHistoryView @JvmOverloads constructor(
}
val colors = Settings.getInstance().current.mColors
clearKey.colorFilter = colors.keyTextFilter
val colorBackground = colors.keyboardBackground
if (colorBackground != null)
background = colorBackground
else
background.colorFilter = colors.backgroundFilter
}

View file

@ -19,6 +19,7 @@ package org.dslul.openboard.inputmethod.keyboard.emoji;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
@ -161,6 +162,8 @@ public final class EmojiPalettesView extends LinearLayout
// TODO: Replace background color with its own setting rather than using the
// category page indicator background as a workaround.
iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
// todo: this doesn't get applied for holo, what could cause this?
// very interesting: in onTabChanged it's applied
iconView.setColorFilter(Settings.getInstance().getCurrent().mColors.keyTextFilter);
iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
iconView.setContentDescription(mEmojiCategory.getAccessibilityDescription(categoryId));
@ -271,6 +274,10 @@ public final class EmojiPalettesView extends LinearLayout
colors.setBackgroundColor(mAlphabetKeyLeft.getBackground(), Colors.TYPE_FUNCTIONAL);
colors.setBackgroundColor(mDeleteKey.getBackground(), Colors.TYPE_FUNCTIONAL);
colors.setBackgroundColor(mSpacebar.getBackground(), Colors.TYPE_SPACE);
final Drawable background = colors.getKeyboardBackground();
if (background != null)
setBackground(background);
else
getBackground().setColorFilter(colors.backgroundFilter);
mEmojiCategoryPageIndicatorView.setColors(colors.accent, colors.adjustedBackground);
}

View file

@ -134,7 +134,7 @@ public final class KeyVisualAttributes {
// todo: maybe a separate color?
mFunctionalTextColor = colors.keyText; //keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
mHintLetterColor = colors.keyHintText; //keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
mHintLabelColor = colors.keyHintText; //keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
mHintLabelColor = colors.keyText; //keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
mShiftedLetterHintInactivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
mShiftedLetterHintActivatedColor = keyAttr.getColor(

View file

@ -5,13 +5,17 @@ import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.core.graphics.BlendModeColorFilterCompat;
import androidx.core.graphics.BlendModeCompat;
import androidx.annotation.ColorInt;
import androidx.core.graphics.ColorUtils;
import androidx.core.graphics.drawable.DrawableCompat;
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme;
// todo: maybe kotlin? would make it much shorter and more readable
public class Colors {
@ -42,7 +46,14 @@ public class Colors {
private ColorStateList spaceBarStateList;
private ColorStateList adjustedBackgroundStateList;
public Colors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) {
public static Colors newColors(String themeStyle, int accent, int background, int keyBackground, int functionalKey, int spaceBar, int keyText, int keyHintText) {
Log.i("test1", "colors with style "+themeStyle);
if (themeStyle.equals(KeyboardTheme.THEME_STYLE_HOLO))
return new HoloColors(accent, background, keyBackground, functionalKey, spaceBar, keyText, keyHintText);
return new Colors(accent, background, keyBackground, functionalKey, spaceBar, keyText, keyHintText);
}
protected Colors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) {
accent = _accent;
background = _background;
keyBackground = _keyBackground;
@ -82,6 +93,11 @@ public class Colors {
DrawableCompat.setTintList(background, list);
}
@Nullable
public Drawable getKeyboardBackground() {
return null;
}
public static final int TYPE_BACKGROUND = 0;
public static final int TYPE_KEY = 1;
public static final int TYPE_FUNCTIONAL = 2;
@ -170,7 +186,7 @@ public class Colors {
return (int) (rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068);
}
private static int adjustLuminosityAndKeepAlpha(@ColorInt final int color, final float amount) {
protected static int adjustLuminosityAndKeepAlpha(@ColorInt final int color, final float amount) {
final int alpha = Color.alpha(color);
float[] hsl = new float[3];
ColorUtils.colorToHSL(color, hsl);

View file

@ -0,0 +1,20 @@
package org.dslul.openboard.inputmethod.latin.common;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
public class HoloColors extends Colors {
protected HoloColors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) {
super(_accent, _background, _keyBackground, _functionalKey, _spaceBar, _keyText, _keyHintText);
}
@Override
public Drawable getKeyboardBackground() {
// thanks a lot google for omitting something extremely exotic like a "subtract" color
// filter that could be simply applied on top of a brighter version of keyboard_background_holo
final int bottomColor = adjustLuminosityAndKeepAlpha(background, -0.2f); // does it need adjusting?
return new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { background, bottomColor });
}
}

View file

@ -25,6 +25,7 @@ import android.os.Bundle
import android.preference.ListPreference
import android.preference.Preference
import android.preference.TwoStatePreference
import android.util.Log
import androidx.core.content.edit
import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme
@ -72,7 +73,7 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
removePreference(Settings.PREF_THEME_DAY_NIGHT)
removePreference(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT)
removePreference(Settings.PREF_THEME_VARIANT_NIGHT)
} else {
// on P there is experimental support for night mode, exposed by some roms like LineageOS
// try to detect this using UI_MODE_NIGHT_UNDEFINED, but actually the system could always report day too?
@ -80,7 +81,7 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
&& (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_UNDEFINED
) {
removePreference(Settings.PREF_THEME_DAY_NIGHT)
removePreference(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT)
removePreference(Settings.PREF_THEME_VARIANT_NIGHT)
}
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
@ -108,7 +109,7 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
override fun onPause() {
super.onPause()
if (needsReload)
// if (needsReload) // todo: until re-working settings, just always reload
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(activity)
needsReload = false
}
@ -123,6 +124,7 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
override fun onSharedPreferenceChanged(prefs: SharedPreferences, key: String) {
super.onSharedPreferenceChanged(prefs, key)
Log.i("test1", "changed pref $key to ${prefs.all.filter { it.key == key }}")
updateAfterPreferenceChanged()
}
@ -137,8 +139,8 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
} else
isEnabled = false
val variant = sharedPreferences.getString(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER)
val variants = KeyboardTheme.CUSTOM_THEME_VARIANTS_DARK
val variant = sharedPreferences.getString(Settings.PREF_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER)
val variants = KeyboardTheme.THEME_VARIANTS_DARK
entries = variants.map {
// todo: this workaround get the same string as for "user" theme, maybe clarify that it's a separate theme
val name = if (it == "user_dark") "theme_name_user" else "theme_name_$it"
@ -153,10 +155,11 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
}
userColorsPref.apply {
isEnabled = KeyboardTheme.getIsCustom(selectedThemeId)
&& (sharedPreferences.getString(Settings.PREF_CUSTOM_THEME_VARIANT, KeyboardTheme.THEME_LIGHT) == KeyboardTheme.THEME_USER
|| (sharedPreferences.getString(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER) == KeyboardTheme.THEME_USER_DARK
&& (sharedPreferences.getString(Settings.PREF_THEME_VARIANT, KeyboardTheme.THEME_LIGHT) == KeyboardTheme.THEME_USER
|| (sharedPreferences.getString(Settings.PREF_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER) == KeyboardTheme.THEME_USER_DARK
&& sharedPreferences.getBoolean(Settings.PREF_THEME_DAY_NIGHT, false)
))
isEnabled = true
}
}
@ -165,22 +168,21 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
variant: String = themeVariantPref.value,
keyBorders: Boolean = keyBordersPref.isChecked
) {
selectedThemeId = KeyboardTheme.getThemeForParameters(family, variant, keyBorders)
KeyboardTheme.saveKeyboardThemeId(selectedThemeId, sharedPreferences)
// selectedThemeId = KeyboardTheme.getThemeForParameters(family, variant, keyBorders)
// KeyboardTheme.saveKeyboardThemeId(selectedThemeId, sharedPreferences)
}
private fun updateThemePreferencesState(skipThemeFamily: Boolean = false, skipThemeVariant: Boolean = false) {
val themeFamily = KeyboardTheme.getThemeFamily(selectedThemeId)
val isLegacyFamily = KeyboardTheme.THEME_FAMILY_HOLO == themeFamily
val isLegacyFamily = KeyboardTheme.THEME_STYLE_HOLO == themeFamily
if (!skipThemeFamily) {
themeFamilyPref.apply {
value = themeFamily
summary = themeFamily
}
}
val variants = KeyboardTheme.THEME_VARIANTS[themeFamily]!!
val variant = if (isLegacyFamily) KeyboardTheme.getThemeVariant(selectedThemeId)
else sharedPreferences.getString(Settings.PREF_CUSTOM_THEME_VARIANT, KeyboardTheme.THEME_LIGHT)
val variants = KeyboardTheme.THEME_VARIANTS
val variant = sharedPreferences.getString(Settings.PREF_THEME_VARIANT, KeyboardTheme.THEME_LIGHT)
if (!skipThemeVariant) {
themeVariantPref.apply {
entries = if (isLegacyFamily) variants // todo: translatable string for holo, not internal name
@ -208,10 +210,10 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
}
private fun setupTheme() {
themeFamilyPref = preferenceScreen.findPreference(Settings.PREF_THEME_FAMILY) as ListPreference
themeFamilyPref = preferenceScreen.findPreference(Settings.PREF_THEME_STYLE) as ListPreference
themeFamilyPref.apply {
entries = KeyboardTheme.THEME_FAMILIES
entryValues = KeyboardTheme.THEME_FAMILIES
entries = KeyboardTheme.THEME_STYLES
entryValues = KeyboardTheme.THEME_STYLES
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
summary = entries[entryValues.indexOfFirst { it == value }]
saveSelectedThemeId(family = value as String)
@ -219,17 +221,18 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
true
}
}
// todo: remove!
themeVariantPref = preferenceScreen.findPreference(Settings.PREF_THEME_VARIANT) as ListPreference
themeVariantPref.apply {
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
summary = entries[entryValues.indexOfFirst { it == value }]
if (themeFamilyPref.value == KeyboardTheme.THEME_FAMILY_MATERIAL) {
if (themeFamilyPref.value == KeyboardTheme.THEME_STYLE_MATERIAL) {
// not so nice workaround, could be removed in the necessary re-work: new value seems
// to be stored only after this method call, but we update the summary and user-defined color enablement in here -> store it now
if (value == sharedPreferences.getString(Settings.PREF_CUSTOM_THEME_VARIANT, KeyboardTheme.THEME_LIGHT))
if (value == sharedPreferences.getString(Settings.PREF_THEME_VARIANT, KeyboardTheme.THEME_LIGHT))
return@OnPreferenceChangeListener true // avoid infinite loop
sharedPreferences.edit { putString(Settings.PREF_CUSTOM_THEME_VARIANT, value as String) }
sharedPreferences.edit { putString(Settings.PREF_THEME_VARIANT, value as String) }
summary = entries[entryValues.indexOfFirst { it == value }]
needsReload = true
@ -250,14 +253,14 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
updateThemePreferencesState(skipThemeFamily = true)
true
}
customThemeVariantNightPref = preferenceScreen.findPreference(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT) as? ListPreference
customThemeVariantNightPref = preferenceScreen.findPreference(Settings.PREF_THEME_VARIANT_NIGHT) as? ListPreference
customThemeVariantNightPref?.apply {
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
// not so nice workaround, could be removed in the necessary re-work: new value seems
// to be stored only after this method call, but we update the summary and user-defined color enablement in here -> store it now
if (value == sharedPreferences.getString(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARK))
if (value == sharedPreferences.getString(Settings.PREF_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARK))
return@OnPreferenceChangeListener true // avoid infinite loop
sharedPreferences.edit { putString(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT, value as String) }
sharedPreferences.edit { putString(Settings.PREF_THEME_VARIANT_NIGHT, value as String) }
summary = entries[entryValues.indexOfFirst { it == value }]
needsReload = true
@ -267,7 +270,7 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
}
userColorsPref = preferenceScreen.findPreference(Settings.PREF_THEME_USER)
userColorsPref.onPreferenceClickListener = Preference.OnPreferenceClickListener { _ ->
if (sharedPreferences.getBoolean(Settings.PREF_THEME_DAY_NIGHT, false) && sharedPreferences.getString(Settings.PREF_CUSTOM_THEME_VARIANT, KeyboardTheme.THEME_LIGHT) == KeyboardTheme.THEME_USER)
if (sharedPreferences.getBoolean(Settings.PREF_THEME_DAY_NIGHT, false) && sharedPreferences.getString(Settings.PREF_THEME_VARIANT, KeyboardTheme.THEME_LIGHT) == KeyboardTheme.THEME_USER)
AlertDialog.Builder(activity)
.setMessage(R.string.day_or_night_colors)
.setPositiveButton(R.string.day_or_night_night) { _, _ -> adjustColors(true)}

View file

@ -61,10 +61,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_VIBRATE_ON = "vibrate_on";
public static final String PREF_SOUND_ON = "sound_on";
public static final String PREF_POPUP_ON = "popup_on";
public static final String PREF_THEME_FAMILY = "theme_family";
public static final String PREF_THEME_STYLE = "theme_style";
public static final String PREF_THEME_VARIANT = "theme_variant";
public static final String PREF_CUSTOM_THEME_VARIANT = "custom_theme_variant";
public static final String PREF_CUSTOM_THEME_VARIANT_NIGHT = "custom_theme_variant_night";
public static final String PREF_THEME_VARIANT_NIGHT = "theme_variant_night";
public static final String PREF_THEME_KEY_BORDERS = "theme_key_borders";
public static final String PREF_THEME_DAY_NIGHT = "theme_auto_day_night";
public static final String PREF_THEME_USER = "theme_select_colors";
@ -573,13 +572,15 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
prefs.edit().putString(PREF_SECONDARY_LOCALES_PREFIX + mainLocaleString.toLowerCase(Locale.ROOT), sb.toString()).apply();
}
public static Colors getColors(final Context context, final SharedPreferences prefs) {
public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) {
// todo: night mode can be unspecified -> maybe need to adjust for correct behavior on some devices?
final boolean isNight = (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
final String themeColors = (isNight && prefs.getBoolean(Settings.PREF_THEME_DAY_NIGHT, false))
? prefs.getString(Settings.PREF_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER)
: prefs.getString(Settings.PREF_THEME_VARIANT, KeyboardTheme.THEME_LIGHT);
final String themeStyle = prefs.getString(Settings.PREF_THEME_STYLE, KeyboardTheme.THEME_STYLE_MATERIAL);
if (isNight && prefs.getBoolean(Settings.PREF_THEME_DAY_NIGHT, false))
return KeyboardTheme.getCustomTheme(prefs.getString(Settings.PREF_CUSTOM_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER), context, prefs);
return KeyboardTheme.getCustomTheme(prefs.getString(Settings.PREF_CUSTOM_THEME_VARIANT, KeyboardTheme.THEME_LIGHT), context, prefs);
return KeyboardTheme.getThemeColors(themeColors, themeStyle, context, prefs);
}
}

View file

@ -254,7 +254,7 @@ public class SettingsValues {
mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs);
mSecondaryLocales = Settings.getSecondaryLocales(prefs, SubtypeSettingsKt.getSelectedSubtype(prefs).getLocale());
mColors = Settings.getColors(context, prefs);
mColors = Settings.getColorsForCurrentTheme(context, prefs);
mColors.createColorFilters(prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false));
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);

View file

@ -44,9 +44,9 @@
name="KeyboardView.HoloWhite"
parent="KeyboardView.Holo"
>
<item name="android:background">@drawable/keyboard_background_holo</item>
<item name="keyBackground">@drawable/btn_keyboard_key_holo_white</item>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_functional_holo_white</item>
<item name="android:background">@android:color/white</item>
<item name="keyBackground">@drawable/btn_keyboard_spacebar_holo_white</item>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_pressed_klp_light</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_holo_white</item>
<item name="keyTextColor">@color/key_text_color_blue</item>
<item name="keyTextInactivatedColor">@color/key_text_inactivated_color_holo</item>
@ -132,7 +132,7 @@
<item name="centerSuggestionPercentile">@fraction/config_center_suggestion_percentile</item>
<item name="maxMoreSuggestionsRow">@integer/config_max_more_suggestions_row</item>
<item name="minMoreSuggestionsWidth">@fraction/config_min_more_suggestions_width</item>
<item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
<item name="android:background">@android:color/white</item>
<item name="android:src">@drawable/suggestions_strip_divider_holo</item>
<item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
<item name="colorValidTypedWord">@color/typed_word_color_holo_white</item>

View file

@ -24,8 +24,9 @@
android:title="@string/settings_screen_theme">
<ListPreference
android:key="theme_family"
android:title="@string/theme_family"/>
android:key="theme_style"
android:title="@string/theme_family"
android:defaultValue="Material"/>
<ListPreference
android:key="theme_variant"