Gesture input color can be customized (#269)

and don't show all colors by default, rather have a menu option for this

---------

Co-authored-by: Helium314 <helium314@mailbox.org>
This commit is contained in:
BlackyHawky 2023-11-17 07:50:58 +01:00 committed by GitHub
parent 9f67113216
commit da6dcece7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 7 deletions

View file

@ -150,6 +150,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
themeStyle,
hasBorders,
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_ACCENT_SUFFIX, false),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_GESTURE_SUFFIX, false),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_BACKGROUND_SUFFIX, false),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_KEYS_SUFFIX, false),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX, false),
@ -163,6 +164,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
themeStyle,
hasBorders,
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_ACCENT_SUFFIX, true),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_GESTURE_SUFFIX, false),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_BACKGROUND_SUFFIX, true),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_KEYS_SUFFIX, true),
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX, true),
@ -176,6 +178,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
// colors taken from the drawable
Color.parseColor("#263238"),
Color.parseColor("#364248"),
@ -190,6 +193,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
themeStyle,
hasBorders,
Color.parseColor("#FFFFFF"),
Color.parseColor("#FFFFFF"),
// colors taken from the drawable
Color.parseColor("#282828"),
Color.parseColor("#FFFFFF"), // transparency!
@ -204,6 +208,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
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),
ContextCompat.getColor(context, R.color.key_background_functional_lxx_dark_border),
@ -217,6 +222,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
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),
ContextCompat.getColor(context, R.color.background_amoled_dark),
@ -231,6 +237,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_light),
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),
ContextCompat.getColor(context, R.color.key_background_functional_lxx_light_border),

View file

@ -41,7 +41,7 @@ final class GestureTrailDrawingParams {
public final int mTrailLingerDuration;
public GestureTrailDrawingParams(final TypedArray mainKeyboardViewAttr) {
mTrailColor = Settings.getInstance().getCurrent().mColors.getAccent(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureTrailColor, 0);
mTrailColor = Settings.getInstance().getCurrent().mColors.getGesture(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureTrailColor, 0);
mTrailStartWidth = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_gestureTrailStartWidth, 0.0f);
mTrailEndWidth = mainKeyboardViewAttr.getDimension(

View file

@ -38,7 +38,7 @@ public final class SlidingKeyInputDrawingPreview extends AbstractDrawingPreview
private final Paint mPaint = new Paint();
public SlidingKeyInputDrawingPreview(final TypedArray mainKeyboardViewAttr) {
final int previewColor = Settings.getInstance().getCurrent().mColors.getAccent(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0);
final int previewColor = Settings.getInstance().getCurrent().mColors.getGesture(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0);
final float previewRadius = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0) / 2.0f;
final int PERCENTAGE_INT = 100;

View file

@ -30,6 +30,7 @@ class Colors (
val themeStyle: String,
val hasKeyBorders: Boolean,
val accent: Int,
val gesture: Int,
val background: Int,
val keyBackground: Int,
val functionalKey: Int,

View file

@ -2,9 +2,11 @@
package org.dslul.openboard.inputmethod.latin.settings
import android.app.Activity
import android.content.res.Configuration
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import android.widget.CompoundButton
@ -12,7 +14,9 @@ import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import androidx.core.view.MenuProvider
import androidx.core.view.forEachIndexed
import androidx.core.view.get
import androidx.fragment.app.Fragment
import com.rarepebble.colorpicker.ColorPickerView
import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher
@ -24,11 +28,14 @@ import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils
import org.dslul.openboard.inputmethod.latin.utils.ExecutorUtils
import org.dslul.openboard.inputmethod.latin.utils.ResourceUtils
open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvider {
private val binding by viewBinding(ColorSettingsBinding::bind)
open val isNight = false
open val titleResId = R.string.select_user_colors
private var moreColors: Boolean
get() = prefs.getBoolean(Settings.PREF_SHOW_ALL_COLORS, false)
set(value) { prefs.edit().putBoolean(Settings.PREF_SHOW_ALL_COLORS, value).apply() }
private val prefs by lazy { DeviceProtectedUtils.getSharedPreferences(requireContext()) }
private val colorPrefs = listOf(
Settings.PREF_COLOR_BACKGROUND_SUFFIX,
@ -39,11 +46,18 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
Settings.PREF_COLOR_HINT_TEXT_SUFFIX,
Settings.PREF_COLOR_SPACEBAR_TEXT_SUFFIX,
Settings.PREF_COLOR_ACCENT_SUFFIX,
Settings.PREF_COLOR_GESTURE_SUFFIX,
)
private val colorPrefsToHideInitially by lazy {
listOf(Settings.PREF_COLOR_SPACEBAR_TEXT_SUFFIX, Settings.PREF_COLOR_GESTURE_SUFFIX) +
if (prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false))
listOf(Settings.PREF_COLOR_SPACEBAR_SUFFIX)
else listOf(Settings.PREF_COLOR_KEYS_SUFFIX, Settings.PREF_COLOR_FUNCTIONAL_KEYS_SUFFIX)
}
override fun onResume() {
super.onResume()
val activity: Activity? = activity
val activity = activity
if (activity is AppCompatActivity) {
val actionBar = activity.supportActionBar ?: return
actionBar.setTitle(titleResId)
@ -53,6 +67,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
prefs.edit { putBoolean(Settings.PREF_FORCE_OPPOSITE_THEME, true) }
reloadKeyboard(false)
}
activity?.addMenuProvider(this)
}
override fun onPause() {
@ -61,10 +76,35 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
if (isNight != ResourceUtils.isNight(requireContext().resources))
// reload again so the correct configuration is applied
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
activity?.removeMenuProvider(this)
}
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
if (menu.size() == 1) menu[0].setTitle(getMenuTitle())
else menu.add(Menu.NONE, 1, Menu.NONE, getMenuTitle())
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
// necessary, even though we only have a single menu item
// because the back arrow on top absurdly is implemented as a menu item
if (menuItem.itemId == 1) {
moreColors = !moreColors
menuItem.setTitle(getMenuTitle())
updateColorPrefs()
return true
}
return false
}
private fun getMenuTitle() = if (moreColors) R.string.main_colors else R.string.all_colors
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
updateColorPrefs()
}
private fun updateColorPrefs() {
binding.colorSettingsContainer.removeAllViews()
val colorPrefNames = listOf(
R.string.select_color_background,
R.string.select_color_key_background,
@ -74,11 +114,15 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
R.string.select_color_key_hint,
R.string.select_color_spacebar_text,
R.string.select_color_accent,
R.string.select_color_gesture,
).map { requireContext().getString(it) }
val prefPrefix = if (isNight) Settings.PREF_THEME_USER_COLOR_NIGHT_PREFIX else Settings.PREF_THEME_USER_COLOR_PREFIX
colorPrefs.forEachIndexed { index, colorPref ->
val autoColor = prefs.getBoolean(prefPrefix + colorPref + Settings.PREF_AUTO_USER_COLOR_SUFFIX, true)
if (!moreColors && colorPref in colorPrefsToHideInitially && autoColor)
return@forEachIndexed
val csb = ColorSettingBinding.inflate(layoutInflater, binding.colorSettingsContainer, true)
csb.colorSwitch.isChecked = !prefs.getBoolean(prefPrefix + colorPref + Settings.PREF_AUTO_USER_COLOR_SUFFIX, true)
csb.colorSwitch.isChecked = !autoColor
csb.colorPreview.setColorFilter(Settings.readUserColor(prefs, requireContext(), colorPrefs[index], isNight))
csb.colorText.text = colorPrefNames[index]
if (!csb.colorSwitch.isChecked) {

View file

@ -67,6 +67,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
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_GESTURE_SUFFIX = "gesture";
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_BACKGROUND_SUFFIX = "background";
@ -137,6 +138,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_PINNED_CLIPS = "pinned_clips";
// used as a workaround against keyboard not showing edited theme in ColorsSettingsFragment
public static final String PREF_FORCE_OPPOSITE_THEME = "force_opposite_theme";
public static final String PREF_SHOW_ALL_COLORS = "pref_show_all_colors";
private static final float UNDEFINED_PREFERENCE_VALUE_FLOAT = -1.0f;
private static final int UNDEFINED_PREFERENCE_VALUE_INT = -1;
@ -149,7 +151,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
private static final Settings sInstance = new Settings();
// preferences that are not used in SettingsValues
// preferences that are not used in SettingsValues and thus should not trigger reload when changed
private static final HashSet<String> dontReloadOnChanged = new HashSet<>() {{
add(PREF_FORCE_OPPOSITE_THEME);
add(PREF_PINNED_CLIPS);
@ -157,6 +159,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
add(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID);
add(PREF_EMOJI_RECENT_KEYS);
add(PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG);
add(PREF_SHOW_ALL_COLORS);
}};
public static Settings getInstance() {
@ -525,6 +528,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return value.data;
}
return ContextCompat.getColor(getDayNightContext(context, isNight), R.color.accent);
case PREF_COLOR_GESTURE_SUFFIX:
return readUserColor(prefs, context, PREF_COLOR_ACCENT_SUFFIX, isNight);
case PREF_COLOR_TEXT_SUFFIX:
// base it on background color, and not key, because it's also used for suggestions
final int background = readUserColor(prefs, context, PREF_COLOR_BACKGROUND_SUFFIX, isNight);

View file

@ -220,6 +220,8 @@ Nouveau dictionnaire:
<string name="select_user_colors">Personnaliser le thème</string>
<string name="select_user_colors_night">Personnaliser le thème (mode nuit)</string>
<string name="auto_user_color">Choix automatique de la couleur</string>
<string name="main_colors">Afficher les couleurs principales</string>
<string name="all_colors">Afficher toutes les couleurs</string>
<string name="hint_show_keyboard">Cliquez pour voir l\'aperçu</string>
<string name="select_user_colors_summary">Sélection des couleurs du texte et de l\'arrière-plan</string>
<string name="select_color_background">Arrière-plan du clavier</string>
@ -230,6 +232,7 @@ Nouveau dictionnaire:
<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_gesture">Saisie gestuelle</string>
<string name="settings_screen_about">À propos</string>
<string name="about_github_link" >Lien vers GitHub</string>
<string name="license" >Licence Open-source</string>

View file

@ -612,6 +612,10 @@ New dictionary:
<string name="select_user_colors_night">Adjust colors (night)</string>
<!-- Text when determining color automatically -->
<string name="auto_user_color">Choose color automatically</string>
<!-- Menu item for showing fewer colors -->
<string name="main_colors">Show main colors only</string>
<!-- Menu item for showing all colors -->
<string name="all_colors">Show all colors</string>
<!-- Hint for text field just to show keyboard (in color settings) -->
<string name="hint_show_keyboard">Click for preview</string>
<!-- Description for selection of user-defined colors. -->
@ -632,6 +636,8 @@ New dictionary:
<string name="select_color_spacebar_text">Space bar text</string>
<!-- Selection: accent color. -->
<string name="select_color_accent">Accent</string>
<!-- Selection: gesture color. -->
<string name="select_color_gesture">Gesture input</string>
<!-- Settings screen title for about [CHAR LIMIT=33]-->
<string name="settings_screen_about">About</string>
<!-- version for about screen-->