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
19 changes: 17 additions & 2 deletions app/src/main/java/helium314/keyboard/latin/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package helium314.keyboard.latin

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Insets
import android.graphics.Rect
import android.util.AttributeSet
import android.util.DisplayMetrics
Expand Down Expand Up @@ -96,7 +97,15 @@ class InputView @JvmOverloads constructor(

/** The navigation bar inset as reported, or the height of the IME's own navigation bar if that is taller */
private fun reportedNavInset(): Int =
navigationBarFrameHeight().takeIf { it > 0 } ?: if (mNavBarBottomInsets > 0) mNavBarBottomInsets else getNavInsets()
navigationBarFrameHeight().takeIf { it > 0 }
?: if (screenNavInsets()?.let { isSideNavBar(it.left, it.right, it.bottom) } == true) 0
else if (mNavBarBottomInsets > 0) mNavBarBottomInsets else getNavInsets()

/** the navigation bar insets of the screen, independent of what is dispatched to this window */
private fun screenNavInsets(): Insets? =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) null
else context.getSystemService(WindowManager::class.java)
?.maximumWindowMetrics?.windowInsets?.getInsets(WindowInsets.Type.navigationBars())

/** what [navPadding] was computed from, for the log when the padding changes */
private var mLastNavMeasure = ""
Expand Down Expand Up @@ -130,7 +139,7 @@ class InputView @JvmOverloads constructor(
}

/** where [reportedNavInset] can come from: the IME's own navigation bar frame (Android 13+) or the system inset */
private fun insetSources() = "(imeNavFrame=${navigationBarFrameHeight()} systemInset=$mNavBarBottomInsets sdk=${Build.VERSION.SDK_INT})"
private fun insetSources() = "(imeNavFrame=${navigationBarFrameHeight()} systemInset=$mNavBarBottomInsets screenNav=${screenNavInsets()} sdk=${Build.VERSION.SDK_INT})"

private fun screenHeight(): Int {
val windowManager = context.getSystemService(WindowManager::class.java) ?: return 0
Expand Down Expand Up @@ -444,3 +453,9 @@ private const val TAG = "InputView"
*/
internal fun navBarOverlap(reportedInset: Int, viewBottom: Int, screenHeight: Int): Int =
(viewBottom - (screenHeight - reportedInset)).coerceIn(0, maxOf(reportedInset, 0))

/**
* Whether the screen has its navigation bar at a side. Some devices (3 button navigation in landscape, #1029) still
* give the keyboard window a bottom inset then, which must not be padded for.
*/
internal fun isSideNavBar(left: Int, right: Int, bottom: Int): Boolean = bottom == 0 && (left > 0 || right > 0)
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ class NavBarOverlapTest {
assertEquals(48, navBarOverlap(reportedInset = 48, viewBottom = 2500, screenHeight = 2400))
assertEquals(0, navBarOverlap(reportedInset = 0, viewBottom = 2400, screenHeight = 2400))
}

@Test fun `only a bar at the side makes a bottom inset bogus`() {
assertEquals(true, isSideNavBar(left = 0, right = 135, bottom = 0))
assertEquals(true, isSideNavBar(left = 135, right = 0, bottom = 0))
assertEquals(false, isSideNavBar(left = 0, right = 0, bottom = 135))
assertEquals(false, isSideNavBar(left = 0, right = 0, bottom = 0)) // nothing known: keep the inset
}
}
Loading