Skip to content

Commit

Permalink
Gesture input color can be customized (openboard-team#269)
Browse files Browse the repository at this point in the history
and don't show all colors by default, rather have a menu option for this

---------

Co-authored-by: Helium314 <[email protected]>
  • Loading branch information
BlackyHawky and Helium314 authored Nov 17, 2023
1 parent 9f67113 commit da6dcec
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public static Colors getThemeColors(final String themeColors, final String theme
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),
Expand All @@ -163,6 +164,7 @@ public static Colors getThemeColors(final String themeColors, final String theme
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),
Expand All @@ -176,6 +178,7 @@ public static Colors getThemeColors(final String themeColors, final String theme
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"),
Expand All @@ -190,6 +193,7 @@ public static Colors getThemeColors(final String themeColors, final String theme
themeStyle,
hasBorders,
Color.parseColor("#FFFFFF"),
Color.parseColor("#FFFFFF"),
// colors taken from the drawable
Color.parseColor("#282828"),
Color.parseColor("#FFFFFF"), // transparency!
Expand All @@ -204,6 +208,7 @@ public static Colors getThemeColors(final String themeColors, final String theme
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),
Expand All @@ -217,6 +222,7 @@ public static Colors getThemeColors(final String themeColors, final String theme
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),
Expand All @@ -231,6 +237,7 @@ public static Colors getThemeColors(final String themeColors, final String theme
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

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
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
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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() {
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -149,14 +151,15 @@ 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);
add(PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID);
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() {
Expand Down Expand Up @@ -525,6 +528,8 @@ private static int determineAutoColor(final SharedPreferences prefs, final Conte
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);
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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. -->
Expand All @@ -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-->
Expand Down

0 comments on commit da6dcec

Please sign in to comment.