mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-17 15:32:48 +00:00
fix wrong day/night theme showing in ColorsSettingsFragment
and run the keyboard reload in background to avoid visual glitches
This commit is contained in:
parent
b18b7dc820
commit
2ade6b3b09
2 changed files with 19 additions and 20 deletions
|
@ -46,17 +46,18 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
|
||||||
val actionBar = activity.supportActionBar ?: return
|
val actionBar = activity.supportActionBar ?: return
|
||||||
actionBar.setTitle(titleResId)
|
actionBar.setTitle(titleResId)
|
||||||
}
|
}
|
||||||
if (isNight != ResourceUtils.isNight(requireContext().resources))
|
if (isNight != ResourceUtils.isNight(requireContext().resources)) {
|
||||||
// reload to get the right configuration
|
// reload to get the right configuration
|
||||||
// todo: this does not work, keyboard also reloading with some other context
|
prefs.edit { putBoolean(Settings.PREF_FORCE_OPPOSITE_THEME, true) }
|
||||||
reloadKeyboard(false)
|
reloadKeyboard(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
prefs.edit { putBoolean(Settings.PREF_FORCE_OPPOSITE_THEME, false) }
|
||||||
if (isNight != ResourceUtils.isNight(requireContext().resources))
|
if (isNight != ResourceUtils.isNight(requireContext().resources))
|
||||||
// reload again so the correct configuration is applied
|
// reload again so the correct configuration is applied
|
||||||
// todo: this does not work, keyboard also reloading with some other context
|
|
||||||
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
|
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
|
||||||
val hidden = RichInputMethodManager.getInstance().inputMethodManager.hideSoftInputFromWindow(binding.dummyText.windowToken, 0)
|
val hidden = RichInputMethodManager.getInstance().inputMethodManager.hideSoftInputFromWindow(binding.dummyText.windowToken, 0)
|
||||||
val b = ColorPickerDialog.Builder(requireContext())
|
val b = ColorPickerDialog.Builder(requireContext())
|
||||||
.setTitle(colorPrefNames[index])
|
.setTitle(colorPrefNames[index])
|
||||||
// todo: later it should be activated, but currently setting alpha leads to glitches,
|
// todo: later alphy bar should be activated, but currently setting alpha leads to glitches,
|
||||||
// e.g. when setting alpha on key text it's not applied for key icons, but for emojis
|
// e.g. when setting alpha on key text it's not applied for key icons, but for emojis
|
||||||
.attachAlphaSlideBar(false)
|
.attachAlphaSlideBar(false)
|
||||||
.setPositiveButton(android.R.string.ok, ColorEnvelopeListener { envelope, _ ->
|
.setPositiveButton(android.R.string.ok, ColorEnvelopeListener { envelope, _ ->
|
||||||
|
@ -142,25 +143,23 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
|
||||||
// only reloading main keyboard view is necessary...
|
// only reloading main keyboard view is necessary...
|
||||||
// or get an actual (live) preview instead of the full keyboard?
|
// or get an actual (live) preview instead of the full keyboard?
|
||||||
// or accelerate keyboard inflate, a big here issue is emojiCategory creating many keyboards
|
// or accelerate keyboard inflate, a big here issue is emojiCategory creating many keyboards
|
||||||
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
|
// KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
|
||||||
// todo: this does not work, keyboard also reloading with some other context
|
// if (!show) return
|
||||||
// KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(Settings.getDayNightContext(requireContext(), isNight))
|
// Thread.sleep(100) // some pause is necessary to avoid visual glitches
|
||||||
if (!show) return
|
// RichInputMethodManager.getInstance().inputMethodManager.showSoftInput(binding.dummyText, 0)
|
||||||
Thread.sleep(100) // some pause is necessary to avoid visual glitches
|
// return
|
||||||
RichInputMethodManager.getInstance().inputMethodManager.showSoftInput(binding.dummyText, 0)
|
|
||||||
return
|
// todo: fix slowdowns and sometimes showing glitches with above, then move away from executor
|
||||||
// for some reason showing again does not work when running with executor
|
|
||||||
// but when running without it's noticeably slow, and sometimes produces glitches
|
|
||||||
// todo: decider whether to just hide, or have some slowdown and show again
|
|
||||||
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute {
|
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute {
|
||||||
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
|
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
|
||||||
if (!show) return@execute
|
if (!show) return@execute
|
||||||
|
// for some reason showing again does not work when running with executor
|
||||||
|
// but when running without it's noticeably slow, and sometimes produces glitches
|
||||||
Thread.sleep(100)
|
Thread.sleep(100)
|
||||||
RichInputMethodManager.getInstance().inputMethodManager.showSoftInput(binding.dummyText, 0)
|
RichInputMethodManager.getInstance().inputMethodManager.showSoftInput(binding.dummyText, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ColorsNightSettingsFragment : ColorsSettingsFragment() {
|
class ColorsNightSettingsFragment : ColorsSettingsFragment() {
|
||||||
|
|
|
@ -133,10 +133,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
|
|
||||||
public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "pref_dont_show_missing_dict_dialog";
|
public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "pref_dont_show_missing_dict_dialog";
|
||||||
|
|
||||||
// This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead.
|
|
||||||
// This is being used only for the backward compatibility.
|
|
||||||
private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY =
|
|
||||||
"pref_suppress_language_switch_key";
|
|
||||||
|
|
||||||
private static final String PREF_LAST_USED_PERSONALIZATION_TOKEN =
|
private static final String PREF_LAST_USED_PERSONALIZATION_TOKEN =
|
||||||
"pref_last_used_personalization_token";
|
"pref_last_used_personalization_token";
|
||||||
|
@ -151,6 +147,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_ID = "last_shown_emoji_category_id";
|
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_ID = "last_shown_emoji_category_id";
|
||||||
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID = "last_shown_emoji_category_page_id";
|
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID = "last_shown_emoji_category_page_id";
|
||||||
|
|
||||||
|
// used as a workaround against keyboard not showing edited theme in ColorsSettingsFragment
|
||||||
|
public static final String PREF_FORCE_OPPOSITE_THEME = "force_opposite_theme";
|
||||||
|
|
||||||
private static final float UNDEFINED_PREFERENCE_VALUE_FLOAT = -1.0f;
|
private static final float UNDEFINED_PREFERENCE_VALUE_FLOAT = -1.0f;
|
||||||
private static final int UNDEFINED_PREFERENCE_VALUE_INT = -1;
|
private static final int UNDEFINED_PREFERENCE_VALUE_INT = -1;
|
||||||
|
|
||||||
|
@ -535,7 +534,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) {
|
public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) {
|
||||||
final boolean isNight = ResourceUtils.isNight(context.getResources());
|
boolean isNight = ResourceUtils.isNight(context.getResources());
|
||||||
|
if (prefs.getBoolean(PREF_FORCE_OPPOSITE_THEME, false)) isNight = !isNight;
|
||||||
final String themeColors = (isNight && prefs.getBoolean(PREF_THEME_DAY_NIGHT, context.getResources().getBoolean(R.bool.day_night_default)))
|
final String themeColors = (isNight && prefs.getBoolean(PREF_THEME_DAY_NIGHT, context.getResources().getBoolean(R.bool.day_night_default)))
|
||||||
? prefs.getString(Settings.PREF_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER)
|
? prefs.getString(Settings.PREF_THEME_VARIANT_NIGHT, KeyboardTheme.THEME_DARKER)
|
||||||
: prefs.getString(Settings.PREF_THEME_VARIANT, KeyboardTheme.THEME_LIGHT);
|
: prefs.getString(Settings.PREF_THEME_VARIANT, KeyboardTheme.THEME_LIGHT);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue