diff --git a/app/src/main/java/helium314/keyboard/latin/InputView.kt b/app/src/main/java/helium314/keyboard/latin/InputView.kt index be10c2648..098175e92 100644 --- a/app/src/main/java/helium314/keyboard/latin/InputView.kt +++ b/app/src/main/java/helium314/keyboard/latin/InputView.kt @@ -99,6 +99,23 @@ class InputView @JvmOverloads constructor( } } + private var observedNavBarFrame: View? = null + + /** + * Height of the IME's own navigation bar, which is drawn over the bottom of this view. It can be taller than + * the system's navigation bar inset, so reserve its actual height. Updates padding when it gets laid out. + */ + private fun navigationBarFrameHeight(): Int { + val frame = LatinIME.getInstance()?.findNavigationBarFrame() ?: return 0 + if (frame !== observedNavBarFrame) { + observedNavBarFrame = frame + frame.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom -> + if (bottom - top != oldBottom - oldTop) post { updateBottomPadding() } + } + } + return if (frame.visibility == View.VISIBLE) frame.height else 0 + } + fun updateBottomPadding() { val mainKeyboardFrame = findViewById(R.id.main_keyboard_frame) ?: return if (isFloatingMode()) { @@ -115,7 +132,8 @@ class InputView @JvmOverloads constructor( R.id.clipboard_history_view, R.id.touchpad_view ) - val insets = if (mNavBarBottomInsets > 0) mNavBarBottomInsets else getNavInsets() + val insets = navigationBarFrameHeight().takeIf { it > 0 } + ?: if (mNavBarBottomInsets > 0) mNavBarBottomInsets else getNavInsets() val wrapper = findViewById(R.id.keyboard_view_wrapper) val showToolbarOnly = wrapper?.visibility != View.VISIBLE val bottomPadding = if (showToolbarOnly) insets else 0 diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt index 1bfd2db3c..36dc0dd4e 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt @@ -699,6 +699,27 @@ class LatinIME : InputMethodService(), } } + /** + * The IME's own NavigationBarFrame sits below the input view and has no background. With edge-to-edge + * enforced, window.navigationBarColor does not reach it, so the app behind shows through unless we paint it. + */ + private fun setNavigationBarFrameBackground(color: Int?) { + val frame = findNavigationBarFrame() ?: return + if (color == null) frame.background = null else frame.setBackgroundColor(color) + } + + fun findNavigationBarFrame(): View? { + fun find(group: ViewGroup): View? { + for (i in 0 until group.childCount) { + val child = group.getChildAt(i) + if (child.javaClass.name.contains("NavigationBarFrame")) return child + if (child is ViewGroup && child !is InputView) find(child)?.let { return it } + } + return null + } + return (window?.window?.decorView as? ViewGroup)?.let { find(it) } + } + fun forceInsetsRefresh() { val win = window?.window ?: return val attrs = win.attributes ?: return @@ -2197,15 +2218,17 @@ class LatinIME : InputMethodService(), } val settingsValues = settings.current if (!settingsValues.mCustomNavBarColor) { + setNavigationBarFrameBackground(null) clearNavigationBarColor() return } - + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) val color = settingsValues.mColors.get(ColorType.NAVIGATION_BAR) window.navigationBarColor = color - + setNavigationBarFrameBackground(color) + val view = window.decorView val controller = WindowCompat.getInsetsController(window, view) if (controller != null) {