Fix build error and add stronger soft keyboard suppression
All checks were successful
APK-BUILD/pipeline/head This commit looks good

Replace BuildConfig.DEBUG (not generated by AGP 8.x) with unconditional
WebView debugging — safe for a kiosk app since it requires ADB access.

Add two additional layers of keyboard suppression for devices where the
null InputConnection alone is insufficient: inject JavaScript that sets
inputmode="none" on all inputs via MutationObserver, and force-hide the
keyboard via InputMethodManager on page load and window focus changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
caspar 2026-10-08 00:25:48 -04:00
parent e6ac00fe2a
commit 72ee038cde

View File

@ -15,6 +15,7 @@ import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.webkit.ConsoleMessage
import android.webkit.CookieManager
import android.webkit.SslErrorHandler
@ -88,7 +89,10 @@ class MainActivity : AppCompatActivity() {
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) enterImmersiveMode()
if (hasFocus) {
enterImmersiveMode()
hideKeyboard()
}
}
// ── WebView Setup ───────────────────────────────────────────────────
@ -131,7 +135,7 @@ class MainActivity : AppCompatActivity() {
setAcceptThirdPartyCookies(webView, true)
}
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG)
WebView.setWebContentsDebuggingEnabled(true)
webView.webViewClient = ScannerWebViewClient()
webView.webChromeClient = ScannerWebChromeClient()
@ -286,6 +290,42 @@ class MainActivity : AppCompatActivity() {
}
}
private fun hideKeyboard() {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(webView.windowToken, 0)
}
private fun injectKeyboardSuppression(view: WebView) {
view.evaluateJavascript("""
(function() {
if (window.__jkKbSuppressed) return;
window.__jkKbSuppressed = true;
function suppress(el) {
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA'
|| el.isContentEditable) {
el.setAttribute('inputmode', 'none');
el.setAttribute('autocomplete', 'off');
}
}
document.querySelectorAll('input, textarea, [contenteditable]')
.forEach(suppress);
new MutationObserver(function(muts) {
muts.forEach(function(m) {
m.addedNodes.forEach(function(n) {
if (n.nodeType === 1) {
suppress(n);
if (n.querySelectorAll)
n.querySelectorAll('input, textarea, [contenteditable]')
.forEach(suppress);
}
});
});
}).observe(document.body || document.documentElement,
{ childList: true, subtree: true });
})();
""".trimIndent(), null)
}
// ── WebViewClient ───────────────────────────────────────────────────
private inner class ScannerWebViewClient : WebViewClient() {
@ -311,6 +351,8 @@ class MainActivity : AppCompatActivity() {
override fun onPageFinished(view: WebView, url: String?) {
super.onPageFinished(view, url)
CookieManager.getInstance().flush()
injectKeyboardSuppression(view)
hideKeyboard()
ensureWebViewFocus()
}