better way of force-reloading the keyboard theme

not duplicating an existing mechanism any more
and working while keyboard is shown (at least it looks like it)
This commit is contained in:
Helium314 2025-03-01 17:06:49 +01:00
parent f0bb541b72
commit 95b6333bf4
19 changed files with 86 additions and 80 deletions

View file

@ -79,6 +79,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private int mCurrentUiMode;
private int mCurrentOrientation;
private int mCurrentDpi;
private boolean mThemeNeedsReload;
@SuppressLint("StaticFieldLeak") // this is a keyboard, we want to keep it alive in background
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
@ -113,21 +114,29 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
}
// todo: maybe we can remove this after removing old setting?
public void forceUpdateKeyboardTheme(@NonNull Context displayContext) {
Settings settings = Settings.getInstance();
settings.loadSettings(displayContext, settings.getCurrent().mLocale, settings.getCurrent().mInputAttributes);
final boolean showing = mLatinIME.isInputViewShown();
if (showing)
mLatinIME.hideWindow();
mLatinIME.setInputView(onCreateInputView(displayContext, mIsHardwareAcceleratedDrawingEnabled));
if (showing)
mLatinIME.showWindow(true);
}
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context, final KeyboardTheme keyboardTheme) {
final Resources res = context.getResources();
if (mThemeContext == null
if (mThemeNeedsReload
|| mThemeContext == null
|| !keyboardTheme.equals(mKeyboardTheme)
|| mCurrentDpi != res.getDisplayMetrics().densityDpi
|| mCurrentOrientation != res.getConfiguration().orientation
|| (mCurrentUiMode & Configuration.UI_MODE_NIGHT_MASK) != (res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
|| !mThemeContext.getResources().equals(res)
|| Settings.getValues().mColors.haveColorsChanged(context)) {
mThemeNeedsReload = false;
mKeyboardTheme = keyboardTheme;
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
mCurrentUiMode = res.getConfiguration().uiMode;
@ -719,4 +728,17 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
public String getLocaleAndConfidenceInfo() {
return mLatinIME.getLocaleAndConfidenceInfo();
}
/** Marks the theme as outdated. The theme will be reloaded next time the keyboard is shown.
* If the keyboard is currently showing, theme will be reloaded immediately. */
public void setThemeNeedsReload() {
mThemeNeedsReload = true;
if (mLatinIME == null || !mLatinIME.isInputViewShown())
return; // will be reloaded right before showing IME
// Hide and show IME, showing will trigger the reload.
// Reloading while IME is shown is glitchy, and hiding / showing is so fast the user shouldn't notice.
mLatinIME.hideWindow();
mLatinIME.showWindow(true);
}
}

View file

@ -27,7 +27,6 @@ import helium314.keyboard.latin.utils.isBrightColor
import helium314.keyboard.latin.utils.isGoodContrast
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.SettingsActivity
import helium314.keyboard.settings.keyboardNeedsReload
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import java.util.EnumMap
@ -352,7 +351,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
val key = Settings.PREF_USER_COLORS_PREFIX + themeName
val value = Json.encodeToString(colors.filter { it.color != null || it.auto == false })
prefs.edit().putString(key, value).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
fun readUserColors(prefs: SharedPreferences, themeName: String): List<ColorSetting> {
@ -363,7 +362,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
fun writeUserMoreColors(prefs: SharedPreferences, themeName: String, value: Int) {
val key = Settings.PREF_USER_MORE_COLORS_PREFIX + themeName
prefs.edit().putInt(key, value).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
fun readUserMoreColors(prefs: SharedPreferences, themeName: String): Int {
@ -374,7 +373,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
fun writeUserAllColors(prefs: SharedPreferences, themeName: String, colorMap: EnumMap<ColorType, Int>) {
val key = Settings.PREF_USER_ALL_COLORS_PREFIX + themeName
prefs.edit().putString(key, colorMap.map { "${it.key},${it.value}" }.joinToString(";")).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
fun readUserAllColors(prefs: SharedPreferences, themeName: String): EnumMap<ColorType, Int> {

View file

@ -89,7 +89,6 @@ import helium314.keyboard.latin.utils.SubtypeLocaleUtils;
import helium314.keyboard.latin.utils.SubtypeSettings;
import helium314.keyboard.latin.utils.ViewLayoutUtils;
import helium314.keyboard.settings.SettingsActivity;
import helium314.keyboard.settings.SettingsActivityKt;
import kotlin.collections.CollectionsKt;
import java.io.FileDescriptor;
@ -899,8 +898,6 @@ public class LatinIME extends InputMethodService implements
void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) {
super.onStartInputView(editorInfo, restarting);
reloadIfNecessary();
mDictionaryFacilitator.onStartInput();
// Switch to the null consumer to handle cases leading to early exit below, for which we
// also wouldn't be consuming gesture data.
@ -1975,13 +1972,4 @@ public class LatinIME extends InputMethodService implements
// deallocateMemory always called on hiding, and should not be called when showing
}
}
private void reloadIfNecessary() {
// better do the reload when showing the keyboard next time, and not on settings change
if (SettingsActivityKt.keyboardNeedsReload) {
KeyboardLayoutSet.onKeyboardThemeChanged();
mKeyboardSwitcher.forceUpdateKeyboardTheme(mDisplayContext);
SettingsActivityKt.keyboardNeedsReload = false;
}
}
}

View file

@ -23,7 +23,6 @@ import helium314.keyboard.latin.common.encodeBase36
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.LayoutType.Companion.folder
import helium314.keyboard.latin.utils.ScriptUtils.script
import helium314.keyboard.settings.keyboardNeedsReload
import kotlinx.serialization.SerializationException
import java.io.File
import java.io.IOException
@ -174,7 +173,7 @@ object LayoutUtilsCustom {
getLayoutFile(layoutName, layoutType, context).delete()
onLayoutFileChanged()
SubtypeSettings.onRenameLayout(layoutType, layoutName, null, context)
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
fun getDisplayName(layoutName: String) =

View file

@ -24,6 +24,7 @@ import androidx.compose.ui.platform.ComposeView
import androidx.core.view.ViewCompat
import androidx.core.view.isGone
import helium314.keyboard.compat.locale
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.InputAttributes
import helium314.keyboard.latin.R
@ -173,7 +174,8 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
override fun onPause() {
super.onPause()
paused = true
if (forceNight != null || forceTheme != null) keyboardNeedsReload = true
if (forceNight != null || forceTheme != null)
KeyboardSwitcher.getInstance().setThemeNeedsReload()
forceNight = false
forceTheme = null
}
@ -186,7 +188,7 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
fun setForceTheme(theme: String?, night: Boolean?) {
if (paused) return
if (forceTheme != theme || forceNight != night) {
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
forceTheme = theme
forceNight = night
@ -240,6 +242,3 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
prefChanged.value++
}
}
@JvmField
var keyboardNeedsReload = false

View file

@ -38,6 +38,7 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import helium314.keyboard.keyboard.ColorSetting
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.ColorType
@ -56,7 +57,6 @@ import helium314.keyboard.settings.SettingsActivity
import helium314.keyboard.settings.SettingsDestination
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.filePicker
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.previewDark
import helium314.keyboard.settings.screens.SaveThoseColors
import kotlinx.coroutines.launch
@ -187,7 +187,7 @@ private fun AddColorRow(onDismissRequest: () -> Unit, userColors: Collection<Str
onDismissRequest()
prefs.edit().putString(prefKey, textValue.text).apply()
SettingsDestination.navigateTo(targetScreen)
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
}
}
@ -203,7 +203,7 @@ private fun ColorItemRow(onDismissRequest: () -> Unit, item: String, isSelected:
.clickable {
onDismissRequest()
prefs.edit().putString(prefKey, item).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
.padding(start = 6.dp)
.heightIn(min = 40.dp)
@ -213,7 +213,7 @@ private fun ColorItemRow(onDismissRequest: () -> Unit, item: String, isSelected:
onClick = {
onDismissRequest()
prefs.edit().putString(prefKey, item).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
)
Text(
@ -239,7 +239,7 @@ private fun ColorItemRow(onDismissRequest: () -> Unit, item: String, isSelected:
.remove(Settings.PREF_USER_MORE_COLORS_PREFIX + item).apply()
if (isSelected)
prefs.edit().remove(prefKey).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
)
}

View file

@ -18,6 +18,7 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.utils.LayoutType
import helium314.keyboard.latin.utils.LayoutUtilsCustom
@ -29,7 +30,6 @@ import helium314.keyboard.settings.CloseIcon
import helium314.keyboard.settings.SettingsActivity
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.previewDark
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@ -77,7 +77,7 @@ fun LayoutEditDialog(
LayoutUtilsCustom.onLayoutFileChanged()
onEdited(newLayoutName)
(ctx.getActivity() as? SettingsActivity)?.prefChanged?.value = 555
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
},
confirmButtonText = stringResource(R.string.save),
initialText = startContent ?: LayoutUtilsCustom.getLayoutFile(initialLayoutName, layoutType, ctx).readText(),

View file

@ -32,6 +32,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Constants.Subtype.ExtraValue
import helium314.keyboard.latin.settings.Defaults.default
@ -49,7 +50,6 @@ import helium314.keyboard.settings.EditButton
import helium314.keyboard.settings.Setting
import helium314.keyboard.settings.SettingsActivity
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.layoutFilePicker
import helium314.keyboard.settings.layoutIntent
import helium314.keyboard.settings.previewDark
@ -167,7 +167,7 @@ private fun LayoutItemRow(
.clickable {
onDismissRequest()
Settings.writeDefaultLayoutName(layoutName, layoutType, prefs)
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
.padding(start = 6.dp)
.heightIn(min = 40.dp)
@ -177,7 +177,7 @@ private fun LayoutItemRow(
onClick = {
onDismissRequest()
Settings.writeDefaultLayoutName(layoutName, layoutType, prefs)
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
)
Text(

View file

@ -19,6 +19,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.FileUtils
import helium314.keyboard.latin.settings.Defaults
@ -30,7 +31,6 @@ import helium314.keyboard.settings.Setting
import helium314.keyboard.settings.SettingsActivity
import helium314.keyboard.settings.dialogs.ConfirmationDialog
import helium314.keyboard.settings.dialogs.InfoDialog
import helium314.keyboard.settings.keyboardNeedsReload
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -105,7 +105,7 @@ fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) {
onNeutral = {
getFile().delete()
Settings.clearCachedBackgroundImages()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
)
}
@ -117,7 +117,7 @@ fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) {
private fun setBackgroundImage(ctx: Context, uri: Uri, isNight: Boolean, isLandscape: Boolean): Boolean {
val imageFile = Settings.getCustomBackgroundFile(ctx, isNight, isLandscape)
FileUtils.copyContentUriToNewFile(uri, ctx, imageFile)
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
try {
BitmapFactory.decodeFile(imageFile.absolutePath)
} catch (_: Exception) {

View file

@ -12,6 +12,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import helium314.keyboard.dictionarypack.DictionaryPackConstants
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.keyboard.internal.keyboard_parser.LAYOUT_NUMBER
import helium314.keyboard.keyboard.internal.keyboard_parser.LAYOUT_NUMPAD
import helium314.keyboard.keyboard.internal.keyboard_parser.LAYOUT_NUMPAD_LANDSCAPE
@ -39,7 +40,6 @@ import helium314.keyboard.settings.SettingsActivity
import helium314.keyboard.settings.dialogs.ConfirmationDialog
import helium314.keyboard.settings.dialogs.InfoDialog
import helium314.keyboard.settings.filePicker
import helium314.keyboard.settings.keyboardNeedsReload
import kotlinx.serialization.json.Json
import java.io.File
import java.io.FileInputStream
@ -177,7 +177,7 @@ fun BackupRestorePreference(setting: Setting) {
ctx.getActivity()?.sendBroadcast(newDictBroadcast)
LayoutUtilsCustom.onLayoutFileChanged()
(ctx.getActivity() as? SettingsActivity)?.prefChanged?.value = 210 // for settings reload
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
Preference(name = setting.title, onClick = { showDialog = true })
if (showDialog) {

View file

@ -10,11 +10,11 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.FileUtils
import helium314.keyboard.latin.settings.Settings
@ -22,7 +22,6 @@ import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.settings.Setting
import helium314.keyboard.settings.dialogs.ConfirmationDialog
import helium314.keyboard.settings.dialogs.InfoDialog
import helium314.keyboard.settings.keyboardNeedsReload
import java.io.File
@Composable
@ -41,7 +40,7 @@ fun CustomFontPreference(setting: Setting) {
fontFile.delete()
tempFile.renameTo(fontFile)
Settings.clearCachedTypeface()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
} catch (_: Exception) {
showErrorDialog = true
tempFile.delete()
@ -66,7 +65,7 @@ fun CustomFontPreference(setting: Setting) {
showDialog = false
fontFile.delete()
Settings.clearCachedTypeface()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
},
neutralButtonText = stringResource(R.string.delete),
confirmButtonText = stringResource(R.string.load),

View file

@ -13,6 +13,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.keyboard.internal.KeyboardIconsSet
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Constants.Separators
@ -20,7 +21,6 @@ import helium314.keyboard.latin.utils.getStringResourceOrName
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.Setting
import helium314.keyboard.settings.dialogs.ReorderDialog
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.screens.GetIcon
@Composable
@ -42,7 +42,7 @@ fun ReorderSwitchPreference(setting: Setting, default: String) {
onConfirmed = { reorderedItems ->
val value = reorderedItems.joinToString(Separators.ENTRY) { it.name + Separators.KV + it.state }
prefs.edit().putString(setting.key, value).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
},
onDismissRequest = { showDialog = false },
onNeutral = { prefs.edit().remove(setting.key).apply() },

View file

@ -16,6 +16,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardActionListener
import helium314.keyboard.keyboard.KeyboardLayoutSet
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.keyboard.internal.keyboard_parser.POPUP_KEYS_ALL
import helium314.keyboard.keyboard.internal.keyboard_parser.POPUP_KEYS_MAIN
import helium314.keyboard.keyboard.internal.keyboard_parser.POPUP_KEYS_MORE
@ -42,7 +43,6 @@ import helium314.keyboard.settings.preferences.SliderPreference
import helium314.keyboard.settings.preferences.SwitchPreference
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.dialogs.TextInputDialog
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.preferences.BackupRestorePreference
import helium314.keyboard.settings.preferences.LoadGestureLibPreference
import helium314.keyboard.settings.previewDark
@ -221,7 +221,7 @@ fun createAdvancedSettings(context: Context) = listOf(
else -> "version unknown"
}
},
onValueChanged = { keyboardNeedsReload = true }
onValueChanged = { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
)
},
Setting(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) {

View file

@ -16,6 +16,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.keyboard.internal.KeyboardIconsSet
import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings
@ -36,7 +37,6 @@ import helium314.keyboard.settings.dialogs.ColorThemePickerDialog
import helium314.keyboard.settings.dialogs.CustomizeIconsDialog
import helium314.keyboard.settings.dialogs.TextInputDialog
import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.preferences.BackgroundImagePref
import helium314.keyboard.settings.preferences.CustomFontPreference
import helium314.keyboard.settings.previewDark
@ -116,7 +116,7 @@ fun createAppearanceSettings(context: Context) = listOf(
setting,
items,
Defaults.PREF_ICON_STYLE
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_CUSTOM_ICON_NAMES, R.string.customize_icons) { setting ->
var showDialog by rememberSaveable { mutableStateOf(false) }
@ -125,11 +125,11 @@ fun createAppearanceSettings(context: Context) = listOf(
onClick = { showDialog = true }
)
if (showDialog) {
if (keyboardNeedsReload) {
/* if (keyboardNeedsReload) {
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(LocalContext.current)
keyboardNeedsReload = false
}
CustomizeIconsDialog(setting.key) { showDialog = false }
*/ CustomizeIconsDialog(setting.key) { showDialog = false }
}
},
Setting(context, Settings.PREF_THEME_COLORS, R.string.theme_colors) { setting ->
@ -173,10 +173,10 @@ fun createAppearanceSettings(context: Context) = listOf(
)
},
Setting(context, Settings.PREF_THEME_KEY_BORDERS, R.string.key_borders) {
SwitchPreference(it, Defaults.PREF_THEME_KEY_BORDERS)
SwitchPreference(it, Defaults.PREF_THEME_KEY_BORDERS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_THEME_DAY_NIGHT, R.string.day_night_mode, R.string.day_night_mode_summary) {
SwitchPreference(it, Defaults.PREF_THEME_DAY_NIGHT) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_THEME_DAY_NIGHT) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_NAVBAR_COLOR, R.string.theme_navbar, R.string.day_night_mode_summary) {
SwitchPreference(it, Defaults.PREF_NAVBAR_COLOR)
@ -199,7 +199,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_SPLIT_SPACER_SCALE,
range = 0.5f..2f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE, R.string.enable_split_keyboard_landscape) {
SwitchPreference(it, Defaults.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE) { KeyboardSwitcher.getInstance().reloadKeyboard() }
@ -211,10 +211,10 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_SPLIT_SPACER_SCALE_LANDSCAPE,
range = 0.5f..2f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_NARROW_KEY_GAPS, R.string.prefs_narrow_key_gaps) {
SwitchPreference(it, Defaults.PREF_NARROW_KEY_GAPS) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_NARROW_KEY_GAPS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_KEYBOARD_HEIGHT_SCALE, R.string.prefs_keyboard_height_scale) { setting ->
SliderPreference(
@ -223,7 +223,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_KEYBOARD_HEIGHT_SCALE,
range = 0.5f..1.5f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_BOTTOM_PADDING_SCALE, R.string.prefs_bottom_padding_scale) { setting ->
SliderPreference(
@ -232,7 +232,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_BOTTOM_PADDING_SCALE,
range = 0f..5f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, R.string.prefs_bottom_padding_scale_landscape) { setting ->
SliderPreference(
@ -241,7 +241,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE,
range = 0f..5f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_SIDE_PADDING_SCALE, R.string.prefs_side_padding_scale) { setting ->
SliderPreference(
@ -250,7 +250,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_SIDE_PADDING_SCALE,
range = 0f..3f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_SIDE_PADDING_SCALE_LANDSCAPE, R.string.prefs_side_padding_scale_landscape) { setting ->
SliderPreference(
@ -259,7 +259,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_SIDE_PADDING_SCALE_LANDSCAPE,
range = 0f..3f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_SPACE_BAR_TEXT, R.string.prefs_space_bar_text) { setting ->
var showDialog by rememberSaveable { mutableStateOf(false) }
@ -274,7 +274,7 @@ fun createAppearanceSettings(context: Context) = listOf(
onDismissRequest = { showDialog = false },
onConfirmed = {
prefs.edit().putString(setting.key, it).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
},
initialText = prefs.getString(setting.key, Defaults.PREF_SPACE_BAR_TEXT) ?: "",
title = { Text(setting.title) },
@ -292,7 +292,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_FONT_SCALE,
range = 0.5f..1.5f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_EMOJI_FONT_SCALE, R.string.prefs_emoji_font_scale) { setting ->
SliderPreference(
@ -301,7 +301,7 @@ fun createAppearanceSettings(context: Context) = listOf(
default = Defaults.PREF_EMOJI_FONT_SCALE,
range = 0.5f..1.5f,
description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
)

View file

@ -10,6 +10,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.DictionaryDumpBroadcastReceiver
import helium314.keyboard.latin.DictionaryFacilitator
@ -24,7 +25,6 @@ import helium314.keyboard.settings.SearchSettingsScreen
import helium314.keyboard.settings.preferences.SwitchPreference
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.preferences.PreferenceCategory
import helium314.keyboard.settings.previewDark
@ -86,7 +86,7 @@ private fun createDebugSettings(context: Context) = listOf(
}
},
Setting(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) {
SwitchPreference(it, Defaults.PREF_SHOW_SUGGESTION_INFOS) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_SHOW_SUGGESTION_INFOS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) {
SwitchPreference(it, Defaults.PREF_FORCE_NON_DISTINCT_MULTITOUCH) { needsRestart = true }

View file

@ -8,6 +8,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings
@ -22,7 +23,6 @@ import helium314.keyboard.settings.preferences.SliderPreference
import helium314.keyboard.settings.preferences.SwitchPreference
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.previewDark
@Composable
@ -81,7 +81,7 @@ fun createGestureTypingSettings(context: Context) = listOf(
val followingSystem = it == default
// allow the default to be overridden
ctx.prefs().edit().putBoolean(Settings.PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM, followingSystem).apply()
keyboardNeedsReload = true
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
},
Setting(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) {
@ -107,7 +107,7 @@ fun createGestureTypingSettings(context: Context) = listOf(
range = 100f..1900f,
description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) },
stepSize = 10,
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
)

View file

@ -10,6 +10,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardLayoutSet
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.AudioAndHapticFeedbackManager
import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Defaults
@ -28,7 +29,6 @@ import helium314.keyboard.settings.preferences.SliderPreference
import helium314.keyboard.settings.preferences.SwitchPreference
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.previewDark
@Composable
@ -90,7 +90,7 @@ fun createPreferencesSettings(context: Context) = listOf(
ReorderSwitchPreference(it, Defaults.PREF_POPUP_KEYS_ORDER)
},
Setting(context, Settings.PREF_SHOW_POPUP_HINTS, R.string.show_popup_hints, R.string.show_popup_hints_summary) {
SwitchPreference(it, Defaults.PREF_SHOW_POPUP_HINTS) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_SHOW_POPUP_HINTS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_POPUP_ON, R.string.popup_on_keypress) {
SwitchPreference(it, Defaults.PREF_POPUP_ON)
@ -110,16 +110,16 @@ fun createPreferencesSettings(context: Context) = listOf(
SwitchPreference(it, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY)
},
Setting(context, Settings.PREF_SHOW_NUMBER_ROW, R.string.number_row, R.string.number_row_summary) {
SwitchPreference(it, Defaults.PREF_SHOW_NUMBER_ROW) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_SHOW_NUMBER_ROW) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_LOCALIZED_NUMBER_ROW, R.string.localized_number_row, R.string.localized_number_row_summary) {
SwitchPreference(it, Defaults.PREF_LOCALIZED_NUMBER_ROW) { KeyboardLayoutSet.onSystemLocaleChanged() }
},
Setting(context, Settings.PREF_SHOW_NUMBER_ROW_HINTS, R.string.number_row_hints) {
SwitchPreference(it, Defaults.PREF_SHOW_NUMBER_ROW_HINTS) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_SHOW_NUMBER_ROW_HINTS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, R.string.show_language_switch_key) {
SwitchPreference(it, Defaults.PREF_SHOW_LANGUAGE_SWITCH_KEY) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_SHOW_LANGUAGE_SWITCH_KEY) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_LANGUAGE_SWITCH_KEY, R.string.language_switch_key_behavior) {
ListPreference(
@ -130,7 +130,7 @@ fun createPreferencesSettings(context: Context) = listOf(
stringResource(R.string.language_switch_key_switch_both) to "both"
),
Defaults.PREF_LANGUAGE_SWITCH_KEY
) { keyboardNeedsReload = true }
) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_SHOW_EMOJI_KEY, R.string.show_emoji_key) {
SwitchPreference(it, Defaults.PREF_SHOW_EMOJI_KEY)
@ -138,7 +138,7 @@ fun createPreferencesSettings(context: Context) = listOf(
Setting(context, Settings.PREF_REMOVE_REDUNDANT_POPUPS,
R.string.remove_redundant_popups, R.string.remove_redundant_popups_summary)
{
SwitchPreference(it, Defaults.PREF_REMOVE_REDUNDANT_POPUPS) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_REMOVE_REDUNDANT_POPUPS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, R.string.clipboard_history_retention_time) { setting ->
SliderPreference(

View file

@ -17,6 +17,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.permissions.PermissionsUtil
import helium314.keyboard.latin.settings.Defaults
@ -36,7 +37,6 @@ import helium314.keyboard.settings.preferences.SwitchPreference
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.dialogs.ConfirmationDialog
import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.previewDark
@Composable
@ -163,7 +163,7 @@ fun createCorrectionSettings(context: Context) = listOf(
Setting(context, Settings.PREF_BIGRAM_PREDICTIONS,
R.string.bigram_prediction, R.string.bigram_prediction_summary
) {
SwitchPreference(it, Defaults.PREF_BIGRAM_PREDICTIONS) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_BIGRAM_PREDICTIONS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER,
R.string.center_suggestion_text_to_enter, R.string.center_suggestion_text_to_enter_summary

View file

@ -23,6 +23,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap
import androidx.core.util.TypedValueCompat
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.keyboard.internal.KeyboardIconsSet
import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Defaults
@ -35,7 +36,6 @@ import helium314.keyboard.settings.preferences.SwitchPreference
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.dialogs.ToolbarKeysCustomizer
import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.keyboardNeedsReload
import helium314.keyboard.settings.previewDark
@Composable
@ -84,7 +84,7 @@ fun createToolbarSettings(context: Context) = listOf(
Setting(context, Settings.PREF_QUICK_PIN_TOOLBAR_KEYS,
R.string.quick_pin_toolbar_keys, R.string.quick_pin_toolbar_keys_summary)
{
SwitchPreference(it, Defaults.PREF_QUICK_PIN_TOOLBAR_KEYS) { keyboardNeedsReload = true }
SwitchPreference(it, Defaults.PREF_QUICK_PIN_TOOLBAR_KEYS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
},
Setting(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary)
{