From fbc1d6c792a2cd9779c1f89f3e435541fcadd57b Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Sun, 15 Nov 2026 12:09:59 +0530 Subject: [PATCH] fix(compat): remove API 23/24 calls flagged by lint HashMap.putIfAbsent (settings search map) and String.codePoints/IntStream (custom text styles parser) need API 24, and View.getRootWindowInsets in InputView needs API 23 on the pre-API-30 path. Use plain equivalents and a version guard so Android 6 and the offline flavor do not hit NoSuchMethodError. --- .../main/java/helium314/keyboard/latin/InputView.kt | 4 +++- .../keyboard/latin/style/UnicodeStyleEngine.kt | 12 ++++++++++-- .../helium314/keyboard/settings/SettingsContainer.kt | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/InputView.kt b/app/src/main/java/helium314/keyboard/latin/InputView.kt index 098175e92..af1dc1d79 100644 --- a/app/src/main/java/helium314/keyboard/latin/InputView.kt +++ b/app/src/main/java/helium314/keyboard/latin/InputView.kt @@ -50,9 +50,11 @@ class InputView @JvmOverloads constructor( if (mNavBarBottomInsets > 0) return mNavBarBottomInsets val insets = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { rootWindowInsets?.getInsets(WindowInsets.Type.navigationBars())?.bottom ?: 0 - } else { + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @Suppress("DEPRECATION") rootWindowInsets?.systemWindowInsetBottom ?: 0 + } else { + 0 // View.getRootWindowInsets needs API 23, the insets come from onApplyWindowInsets } if (insets > 0) { mNavBarBottomInsets = insets diff --git a/app/src/main/java/helium314/keyboard/latin/style/UnicodeStyleEngine.kt b/app/src/main/java/helium314/keyboard/latin/style/UnicodeStyleEngine.kt index 99e7bda82..f3fb7304d 100644 --- a/app/src/main/java/helium314/keyboard/latin/style/UnicodeStyleEngine.kt +++ b/app/src/main/java/helium314/keyboard/latin/style/UnicodeStyleEngine.kt @@ -723,8 +723,16 @@ object UnicodeStyleEngine { if (colon < 0) return null val name = line.substring(0, colon).trim() if (name.isEmpty()) return null - val cps = line.substring(colon + 1).codePoints().filter { !Character.isWhitespace(it) }.toArray() - return if (cps.size == 52 || cps.size == 62) name to cps else null + // plain loop: String.codePoints() and IntStream need API 24, the app supports API 21/23 + val rest = line.substring(colon + 1) + val cps = ArrayList(62) + var i = 0 + while (i < rest.length) { + val cp = rest.codePointAt(i) + if (!Character.isWhitespace(cp)) cps.add(cp) + i += Character.charCount(cp) + } + return if (cps.size == 52 || cps.size == 62) name to cps.toIntArray() else null } private fun buildReverseMap(styles: List): Map { diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt b/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt index 756a89f36..d32b8b9a8 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt @@ -39,7 +39,7 @@ class SettingsContainer(context: Context) { /** settings screen (destination) that shows a setting, for jumping there from the search */ private val screens: Map = HashMap().apply { - settingsWithScreens.forEach { (setting, destination) -> if (destination != null) putIfAbsent(setting.key, destination) } + settingsWithScreens.forEach { (setting, destination) -> if (destination != null && !containsKey(setting.key)) put(setting.key, destination) } } operator fun get(key: Any): Setting? = map[key]