Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/src/main/java/helium314/keyboard/latin/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<View>(R.id.main_keyboard_frame) ?: return
if (isFloatingMode()) {
Expand All @@ -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<View>(R.id.keyboard_view_wrapper)
val showToolbarOnly = wrapper?.visibility != View.VISIBLE
val bottomPadding = if (showToolbarOnly) insets else 0
Expand Down
27 changes: 25 additions & 2 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Loading