From d2f414811f44ebe74048b06ac7e3c77eb023f432 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 21 Jul 2023 19:32:53 +0200 Subject: [PATCH] properly apply user defined theme immediately --- README.md | 7 ++++--- .../inputmethod/keyboard/KeyboardSwitcher.java | 4 ++++ .../latin/settings/AppearanceSettingsFragment.kt | 11 ++++++++++- .../inputmethod/latin/settings/ColorPickerDialog.java | 3 ++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ef97b3079..ec01592ab 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,12 @@ Plan / to do: * ~theming, https://github.com/openboard-team/openboard/issues/124~ * ~fix emoji view not themed properly~ * ~fix ABC buttons in emoji and clipboard view have wrong text color~ + * ~allow adjusting colors without requiring manual reload of keyboard~ + * ~fix issues in _more suggestions_ view, https://github.com/Helium314/openboard/issues/9#issuecomment-1626932543~ (not 100% fixed, but should not be noticeable) * fix buttons on long-press action key not themed - * allow adjusting colors without requiring manual reload of keyboard - * fix issues in _more suggestions_ view, https://github.com/Helium314/openboard/issues/9#issuecomment-1626932543 + * fix icons on long-press comma key not themed * ~delete suggestions, https://github.com/openboard-team/openboard/issues/106~ - * make functionality more discoverable, e.g. add a button to the _more suggestions_ menu + * make functionality more discoverable, e.g. add a button to the _more suggestions_ menu, or replace long-press menu and show more suggestions by scrolling suggestion strip * ~gesture typing, https://github.com/openboard-team/openboard/issues/3~ * ~license issues, require using an external library~ * ~move/copy _use contacts_ setting from well hidden spell checker settings to _text correction_ settings~ diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardSwitcher.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardSwitcher.java index f8bc09c85..4568f45b3 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardSwitcher.java @@ -100,6 +100,10 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } } + public void forceUpdateKeyboardTheme() { + mLatinIME.setInputView(onCreateInputView(mIsHardwareAcceleratedDrawingEnabled)); + } + private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context, final KeyboardTheme keyboardTheme) { final boolean nightModeChanged = (mCurrentUiMode & Configuration.UI_MODE_NIGHT_MASK) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt index 6648fd646..a1cac0ae2 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt @@ -21,6 +21,7 @@ import android.os.Bundle import android.preference.ListPreference import android.preference.Preference import android.preference.TwoStatePreference +import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme import org.dslul.openboard.inputmethod.latin.R import org.dslul.openboard.inputmethod.latin.common.Constants @@ -33,6 +34,7 @@ import java.util.* class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceChangeListener { private var selectedThemeId = 0 + private var needsReload = false private lateinit var themeFamilyPref: ListPreference private lateinit var themeVariantPref: ListPreference @@ -71,6 +73,13 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC findPreference(Settings.PREF_CUSTOM_INPUT_STYLES)) } + override fun onPause() { + super.onPause() + if (needsReload) + KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme() + needsReload = false + } + override fun onPreferenceChange(preference: Preference, value: Any?): Boolean { (preference as? ListPreference)?.apply { summary = entries[entryValues.indexOfFirst { it == value }] @@ -185,7 +194,7 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC 3 -> Settings.PREF_THEME_USER_COLOR_ACCENT else -> Settings.PREF_THEME_USER_COLOR_KEYS } - val d = ColorPickerDialog(activity, items[i], sharedPreferences, pref) + val d = ColorPickerDialog(activity, items[i], sharedPreferences, pref) { needsReload = true} d.show() } .show() diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorPickerDialog.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorPickerDialog.java index 25b3f100a..cb229e516 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorPickerDialog.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/ColorPickerDialog.java @@ -30,7 +30,7 @@ import android.widget.TextView; import org.dslul.openboard.inputmethod.latin.R; public class ColorPickerDialog extends AlertDialog implements SeekBar.OnSeekBarChangeListener { - protected ColorPickerDialog(Context context, String title, SharedPreferences prefs, String colorPref) { + protected ColorPickerDialog(Context context, String title, SharedPreferences prefs, String colorPref, Runnable onChanged) { super(context); setTitle(title); View view = getLayoutInflater().inflate(R.layout.color_dialog, null); @@ -80,6 +80,7 @@ public class ColorPickerDialog extends AlertDialog implements SeekBar.OnSeekBarC mSeekBarGreen.getProgress(), mSeekBarBlue.getProgress()); prefs.edit().putInt(colorPref, value).apply(); + onChanged.run(); dismiss(); } });