diff --git a/app/src/main/java/mx/joykoo/scanner/MainActivity.kt b/app/src/main/java/mx/joykoo/scanner/MainActivity.kt index 0ab4c81..746375f 100644 --- a/app/src/main/java/mx/joykoo/scanner/MainActivity.kt +++ b/app/src/main/java/mx/joykoo/scanner/MainActivity.kt @@ -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() }