Compare commits
No commits in common. "619fa4f048564c531bccc811aeac03e65459b3cf" and "72ee038cdeb911968d4a93f37d3eff36e96724f5" have entirely different histories.
619fa4f048
...
72ee038cde
10
CLAUDE.md
10
CLAUDE.md
@ -6,15 +6,7 @@ Native Android app (Kotlin) that wraps `https://smart.joykoo.mx/` in a fullscree
|
|||||||
|
|
||||||
## Critical Design Decision
|
## Critical Design Decision
|
||||||
|
|
||||||
The Android soft keyboard must NEVER appear. Keyboard suppression uses multiple layers — do not remove any of them:
|
The Android soft keyboard must NEVER appear. The custom `NoSoftKeyboardWebView` returns `null` from `onCreateInputConnection()` to prevent the IME from ever being invoked, while hardware key events from the scanner still flow through the standard View key-event dispatch chain. Do not revert this or add an InputConnection — it is the core of the app.
|
||||||
|
|
||||||
1. `NoSoftKeyboardWebView.onCheckIsTextEditor()` → `false`
|
|
||||||
2. `EditorInfo` flags `IME_FLAG_NO_EXTRACT_UI | IME_FLAG_NO_FULLSCREEN` in `onCreateInputConnection()`
|
|
||||||
3. `InputMethodManager.hideSoftInputFromWindow()` posted after each InputConnection request and on page load / window focus
|
|
||||||
4. JavaScript injection setting `inputmode="none"` on all `<input>`, `<textarea>`, and `contenteditable` elements via `MutationObserver`
|
|
||||||
5. Manifest `windowSoftInputMode="stateAlwaysHidden|adjustNothing"`
|
|
||||||
|
|
||||||
The real `InputConnection` from `super.onCreateInputConnection()` **must be returned** — returning `null` breaks hardware key input from the barcode scanner on devices like the Urovo CT58C.
|
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
|
|||||||
@ -12,9 +12,6 @@ object AppConfig {
|
|||||||
"joykoo.mx",
|
"joykoo.mx",
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Size in dp of the corner regions used for hidden tap gestures. */
|
|
||||||
const val GESTURE_CORNER_DP = 60
|
|
||||||
|
|
||||||
/** Number of rapid Back presses required to exit the app when there is no WebView history. */
|
/** Number of rapid Back presses required to exit the app when there is no WebView history. */
|
||||||
const val BACK_PRESS_EXIT_COUNT = 3
|
const val BACK_PRESS_EXIT_COUNT = 3
|
||||||
|
|
||||||
@ -26,10 +23,4 @@ object AppConfig {
|
|||||||
|
|
||||||
/** Time window (ms) for admin tap sequence. */
|
/** Time window (ms) for admin tap sequence. */
|
||||||
const val ADMIN_TAP_WINDOW_MS = 3000L
|
const val ADMIN_TAP_WINDOW_MS = 3000L
|
||||||
|
|
||||||
/** Number of taps on the top-right corner to toggle the on-screen keyboard. */
|
|
||||||
const val KEYBOARD_TOGGLE_TAP_COUNT = 5
|
|
||||||
|
|
||||||
/** Time window (ms) for keyboard toggle tap sequence. */
|
|
||||||
const val KEYBOARD_TOGGLE_TAP_WINDOW_MS = 3000L
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,10 +41,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Admin exit: rapid taps in the top-left corner
|
// Admin exit: rapid taps in the top-left corner
|
||||||
private var adminTapTimestamps = mutableListOf<Long>()
|
private var adminTapTimestamps = mutableListOf<Long>()
|
||||||
|
|
||||||
// Keyboard toggle: rapid taps in the top-right corner
|
|
||||||
private var keyboardToggleTapTimestamps = mutableListOf<Long>()
|
|
||||||
private var isKeyboardSuppressed = true
|
|
||||||
|
|
||||||
// Back-press exit: rapid presses when no WebView history
|
// Back-press exit: rapid presses when no WebView history
|
||||||
private var backPressTimestamps = mutableListOf<Long>()
|
private var backPressTimestamps = mutableListOf<Long>()
|
||||||
|
|
||||||
@ -217,14 +213,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
||||||
if (ev.actionMasked == MotionEvent.ACTION_DOWN) {
|
if (ev.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||||
val threshold = (AppConfig.GESTURE_CORNER_DP * resources.displayMetrics.density).toInt()
|
// Top-left 60x60 dp region as the hidden admin area
|
||||||
|
val threshold = (60 * resources.displayMetrics.density).toInt()
|
||||||
if (ev.x < threshold && ev.y < threshold) {
|
if (ev.x < threshold && ev.y < threshold) {
|
||||||
handleAdminTap()
|
handleAdminTap()
|
||||||
}
|
}
|
||||||
val screenWidth = resources.displayMetrics.widthPixels
|
|
||||||
if (ev.x > screenWidth - threshold && ev.y < threshold) {
|
|
||||||
handleKeyboardToggleTap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return super.dispatchTouchEvent(ev)
|
return super.dispatchTouchEvent(ev)
|
||||||
}
|
}
|
||||||
@ -241,6 +234,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showAdminExitDialog() {
|
private fun showAdminExitDialog() {
|
||||||
|
// Structured so a PIN check can be added here before calling finish()
|
||||||
AlertDialog.Builder(this)
|
AlertDialog.Builder(this)
|
||||||
.setTitle("Salir de la aplicación")
|
.setTitle("Salir de la aplicación")
|
||||||
.setMessage("¿Desea cerrar la aplicación del escáner?")
|
.setMessage("¿Desea cerrar la aplicación del escáner?")
|
||||||
@ -249,35 +243,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Keyboard Toggle (hidden tap gesture, top-right corner) ──────────
|
|
||||||
|
|
||||||
private fun handleKeyboardToggleTap() {
|
|
||||||
val now = System.currentTimeMillis()
|
|
||||||
keyboardToggleTapTimestamps.add(now)
|
|
||||||
keyboardToggleTapTimestamps.removeAll {
|
|
||||||
now - it > AppConfig.KEYBOARD_TOGGLE_TAP_WINDOW_MS
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyboardToggleTapTimestamps.size >= AppConfig.KEYBOARD_TOGGLE_TAP_COUNT) {
|
|
||||||
keyboardToggleTapTimestamps.clear()
|
|
||||||
toggleKeyboard()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun toggleKeyboard() {
|
|
||||||
isKeyboardSuppressed = !isKeyboardSuppressed
|
|
||||||
webView.keyboardSuppressed = isKeyboardSuppressed
|
|
||||||
|
|
||||||
if (isKeyboardSuppressed) {
|
|
||||||
injectKeyboardSuppression(webView)
|
|
||||||
hideKeyboard()
|
|
||||||
Toast.makeText(this, R.string.keyboard_disabled, Toast.LENGTH_SHORT).show()
|
|
||||||
} else {
|
|
||||||
removeKeyboardSuppression(webView)
|
|
||||||
Toast.makeText(this, R.string.keyboard_enabled, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Lifecycle ───────────────────────────────────────────────────────
|
// ── Lifecycle ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@ -326,15 +291,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun hideKeyboard() {
|
private fun hideKeyboard() {
|
||||||
if (!isKeyboardSuppressed) return
|
|
||||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.hideSoftInputFromWindow(webView.windowToken, 0)
|
imm.hideSoftInputFromWindow(webView.windowToken, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun injectKeyboardSuppression(view: WebView) {
|
private fun injectKeyboardSuppression(view: WebView) {
|
||||||
if (!isKeyboardSuppressed) return
|
|
||||||
view.evaluateJavascript("""
|
view.evaluateJavascript("""
|
||||||
(function() {
|
(function() {
|
||||||
|
if (window.__jkKbSuppressed) return;
|
||||||
|
window.__jkKbSuppressed = true;
|
||||||
function suppress(el) {
|
function suppress(el) {
|
||||||
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA'
|
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA'
|
||||||
|| el.isContentEditable) {
|
|| el.isContentEditable) {
|
||||||
@ -344,8 +309,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
document.querySelectorAll('input, textarea, [contenteditable]')
|
document.querySelectorAll('input, textarea, [contenteditable]')
|
||||||
.forEach(suppress);
|
.forEach(suppress);
|
||||||
if (window.__jkKbObserver) window.__jkKbObserver.disconnect();
|
new MutationObserver(function(muts) {
|
||||||
window.__jkKbObserver = new MutationObserver(function(muts) {
|
|
||||||
muts.forEach(function(m) {
|
muts.forEach(function(m) {
|
||||||
m.addedNodes.forEach(function(n) {
|
m.addedNodes.forEach(function(n) {
|
||||||
if (n.nodeType === 1) {
|
if (n.nodeType === 1) {
|
||||||
@ -356,27 +320,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}).observe(document.body || document.documentElement,
|
||||||
window.__jkKbObserver.observe(document.body || document.documentElement,
|
|
||||||
{ childList: true, subtree: true });
|
{ childList: true, subtree: true });
|
||||||
})();
|
})();
|
||||||
""".trimIndent(), null)
|
""".trimIndent(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeKeyboardSuppression(view: WebView) {
|
|
||||||
view.evaluateJavascript("""
|
|
||||||
(function() {
|
|
||||||
if (window.__jkKbObserver) {
|
|
||||||
window.__jkKbObserver.disconnect();
|
|
||||||
window.__jkKbObserver = null;
|
|
||||||
}
|
|
||||||
document.querySelectorAll('[inputmode="none"]').forEach(function(el) {
|
|
||||||
el.removeAttribute('inputmode');
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
""".trimIndent(), null)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── WebViewClient ───────────────────────────────────────────────────
|
// ── WebViewClient ───────────────────────────────────────────────────
|
||||||
|
|
||||||
private inner class ScannerWebViewClient : WebViewClient() {
|
private inner class ScannerWebViewClient : WebViewClient() {
|
||||||
|
|||||||
@ -4,51 +4,65 @@ import android.content.Context
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.view.inputmethod.InputConnection
|
import android.view.inputmethod.InputConnection
|
||||||
import android.view.inputmethod.InputMethodManager
|
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebView subclass that prevents the Android software keyboard (IME) from
|
* WebView subclass that prevents the Android software keyboard (IME) from
|
||||||
* appearing while preserving hardware keyboard / barcode-scanner key events.
|
* appearing while preserving hardware keyboard / barcode-scanner key events.
|
||||||
*
|
*
|
||||||
* Keyboard suppression uses multiple layers:
|
* HOW IT WORKS
|
||||||
* 1. onCheckIsTextEditor() → false: first signal to the IME not to show.
|
* ============
|
||||||
* 2. EditorInfo flags (NO_EXTRACT_UI, NO_FULLSCREEN): prevent fullscreen IME.
|
* When an HTML <input> inside a WebView gains focus, the framework calls
|
||||||
* 3. InputMethodManager.hideSoftInputFromWindow posted after each
|
* onCreateInputConnection() on the focused View. If this method returns a
|
||||||
* InputConnection request: force-hides if the IME appears anyway.
|
* non-null InputConnection, the InputMethodManager (IMM) has a channel to
|
||||||
* 4. JavaScript inputmode="none" injection (in MainActivity): tells the
|
* the IME and will show the software keyboard.
|
||||||
* Chromium renderer not to request the keyboard for HTML inputs.
|
|
||||||
* 5. Manifest stateAlwaysHidden|adjustNothing: system-level default.
|
|
||||||
*
|
*
|
||||||
* The real InputConnection from super is returned so that hardware key
|
* By returning null, we tell the IMM that this View does not participate in
|
||||||
* events from the barcode scanner are relayed into focused HTML inputs
|
* the input-method protocol. The IMM therefore never shows the soft keyboard
|
||||||
* by the Chromium renderer.
|
* for this View — it is prevented from opening in the first place rather
|
||||||
|
* than being hidden reactively after it appears.
|
||||||
|
*
|
||||||
|
* WHY HARDWARE/SCANNER INPUT STILL WORKS
|
||||||
|
* =======================================
|
||||||
|
* Hardware key events (from a physical keyboard or a barcode scanner in
|
||||||
|
* HID/keyboard-wedge mode) are delivered through the Android View key-event
|
||||||
|
* dispatch pipeline: Activity.dispatchKeyEvent → ViewGroup.dispatchKeyEvent
|
||||||
|
* → View.dispatchKeyEvent → View.onKeyDown/onKeyUp. This pipeline is
|
||||||
|
* completely independent of InputConnection/IME. WebView's internal
|
||||||
|
* key-event handling (which forwards events to the Chromium renderer and
|
||||||
|
* into focused HTML inputs) works through this pipeline, so hardware key
|
||||||
|
* events continue to reach whichever HTML input has focus inside the
|
||||||
|
* WebView.
|
||||||
|
*
|
||||||
|
* The only thing lost by returning null is the ability to receive composed
|
||||||
|
* text from a software IME (e.g. predictive text, swipe typing, CJK
|
||||||
|
* composition). Since this device is a dedicated barcode scanner with no
|
||||||
|
* need for software keyboard input, this is the desired behavior.
|
||||||
|
*
|
||||||
|
* ADDITIONAL SAFETY: onCheckIsTextEditor()
|
||||||
|
* ========================================
|
||||||
|
* Some Android IME implementations also check onCheckIsTextEditor() to
|
||||||
|
* decide whether to show. Returning false provides a second signal that
|
||||||
|
* this View does not want IME interaction.
|
||||||
*/
|
*/
|
||||||
class NoSoftKeyboardWebView : WebView {
|
class NoSoftKeyboardWebView : WebView {
|
||||||
|
|
||||||
var keyboardSuppressed = true
|
|
||||||
|
|
||||||
constructor(context: Context) : super(context)
|
constructor(context: Context) : super(context)
|
||||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
|
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
|
||||||
super(context, attrs, defStyleAttr)
|
super(context, attrs, defStyleAttr)
|
||||||
|
|
||||||
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
|
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
|
||||||
val ic = super.onCreateInputConnection(outAttrs)
|
// Returning null prevents the IMM from establishing a connection to
|
||||||
if (keyboardSuppressed) {
|
// any software IME. The soft keyboard cannot appear because there is
|
||||||
outAttrs.imeOptions = outAttrs.imeOptions or
|
// no InputConnection for it to communicate through. Hardware key
|
||||||
EditorInfo.IME_FLAG_NO_EXTRACT_UI or
|
// events still flow via the View key-event dispatch chain.
|
||||||
EditorInfo.IME_FLAG_NO_FULLSCREEN
|
return null
|
||||||
post {
|
|
||||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE)
|
|
||||||
as InputMethodManager
|
|
||||||
imm.hideSoftInputFromWindow(windowToken, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCheckIsTextEditor(): Boolean {
|
override fun onCheckIsTextEditor(): Boolean {
|
||||||
return !keyboardSuppressed
|
// Signal to the framework that this View is not a text editor,
|
||||||
|
// preventing IME-related behaviors from triggering.
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,4 @@
|
|||||||
<string name="error_no_connection">No se puede conectar</string>
|
<string name="error_no_connection">No se puede conectar</string>
|
||||||
<string name="error_check_wifi">Verifique la conexión Wi-Fi e intente de nuevo.</string>
|
<string name="error_check_wifi">Verifique la conexión Wi-Fi e intente de nuevo.</string>
|
||||||
<string name="retry">Reintentar</string>
|
<string name="retry">Reintentar</string>
|
||||||
<string name="keyboard_enabled">Teclado en pantalla activado</string>
|
|
||||||
<string name="keyboard_disabled">Teclado en pantalla desactivado</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user