From da6dcece7f6cb85a01424be807e7610057fd2ab5 Mon Sep 17 00:00:00 2001 From: BlackyHawky Date: Fri, 17 Nov 2023 07:50:58 +0100 Subject: [PATCH] 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 --- .../inputmethod/keyboard/KeyboardTheme.java | 7 +++ .../internal/GestureTrailDrawingParams.java | 2 +- .../SlidingKeyInputDrawingPreview.java | 2 +- .../inputmethod/latin/common/Colors.kt | 1 + .../latin/settings/ColorsSettingsFragment.kt | 52 +++++++++++++++++-- .../inputmethod/latin/settings/Settings.java | 7 ++- app/src/main/res/values-fr/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 6 +++ 8 files changed, 73 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java index 0ee833664..73453de76 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java @@ -150,6 +150,7 @@ public final class KeyboardTheme implements Comparable { 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 { 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 { 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 { 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 { 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 { 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 { 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), diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/GestureTrailDrawingParams.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/GestureTrailDrawingParams.java index 6f018c96c..8219763cf 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/GestureTrailDrawingParams.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/GestureTrailDrawingParams.java @@ -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( diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java index 1dd5698f6..5c6b220dc 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java @@ -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; diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt index 3605b2f69..1ed7ee3b2 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.kt @@ -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, diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt index 9bc832347..c472efb30 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorsSettingsFragment.kt @@ -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) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java index 2c2dc945f..525039111 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java @@ -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 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); diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index e571226d1..787872da2 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -220,6 +220,8 @@ Nouveau dictionnaire: Personnaliser le thème Personnaliser le thème (mode nuit) Choix automatique de la couleur + Afficher les couleurs principales + Afficher toutes les couleurs Cliquez pour voir l\'aperçu Sélection des couleurs du texte et de l\'arrière-plan Arrière-plan du clavier @@ -230,6 +232,7 @@ Nouveau dictionnaire: Arrière-plan de la barre d\'espace Texte de la barre d\'espace Couleur d\'accentuation + Saisie gestuelle À propos Lien vers GitHub Licence Open-source diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6b5316d16..4fa525f71 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -612,6 +612,10 @@ New dictionary: Adjust colors (night) Choose color automatically + + Show main colors only + + Show all colors Click for preview @@ -632,6 +636,8 @@ New dictionary: Space bar text Accent + + Gesture input About