From d08ce45f3af2dac9f0f44f500fded7a8accb2507 Mon Sep 17 00:00:00 2001 From: FarzanArzoiy Date: Fri, 24 Jul 2026 00:47:59 +0430 Subject: [PATCH] Fix #161: Apply landscape keyboard height dynamically on orientation change and preference update - Add refreshKeyboardHeight() that recalculates height from NeuralLayoutBridge - Call it in onConfigurationChanged() when device rotates - Call it in onSharedPreferenceChanged() when height-related prefs change - This makes the landscape slider work immediately and keeps portrait/landscape heights independent --- .../cleverkeys/CleverKeysService.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/tribixbite/cleverkeys/CleverKeysService.kt b/src/main/kotlin/tribixbite/cleverkeys/CleverKeysService.kt index 71aaf4380..37de10f41 100644 --- a/src/main/kotlin/tribixbite/cleverkeys/CleverKeysService.kt +++ b/src/main/kotlin/tribixbite/cleverkeys/CleverKeysService.kt @@ -370,7 +370,7 @@ class CleverKeysService : InputMethodService(), if (intent?.action == ACTION_THEME_CHANGED) { // 1. Refresh config to pick up new values (colors, etc.) _configManager.refresh(resources) - + // 2. FORCE view recreation. // Even if the theme ID hasn't changed (e.g. editing custom theme colors), // we need to recreate the view to pick up the new colors. @@ -566,6 +566,17 @@ class CleverKeysService : InputMethodService(), _configManager.refresh(resources) } + /** + * Recalculate the keyboard height based on current orientation/foldable state + * and apply it to the keyboard view. Call this whenever the height might have changed. + */ + private fun refreshKeyboardHeight() { + if (!::_neuralLayoutBridge.isInitialized) return + val height = _neuralLayoutBridge.calculateDynamicKeyboardHeight() + _keyboardView.layoutParams?.height = height.toInt() + _keyboardView.requestLayout() + } + // ConfigChangeListener implementation (v1.32.345) /** @@ -774,6 +785,7 @@ class CleverKeysService : InputMethodService(), // Without this, landscape margins are never applied because Config.orientation_landscape // isn't updated when the device rotates refresh_config() + refreshKeyboardHeight() } override fun onUpdateSelection( @@ -873,6 +885,12 @@ class CleverKeysService : InputMethodService(), return } + if (key in setOf("keyboard_height", "keyboard_height_landscape", + "keyboard_height_unfolded", "keyboard_height_landscape_unfolded")) { + refreshKeyboardHeight() + // Do NOT return here – let the existing handler also run if needed + } + // Initialize handler lazily (depends on components that may not exist yet) if (_preferenceUIUpdateHandler == null) { _preferenceUIUpdateHandler = PreferenceUIUpdateHandler.create(