hex/android/app
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ryan Vogel 2b1ccbd9a4
Android keyboard (proposal): offer a dictation whose field went away as "Insert dictation" (#2821)
* Android keyboard: a dictation the app hides the keyboard on goes into its field

Why: an app hiding the keyboard (Grok does when you scroll up to read the reply)
threw away a dictation that was recording or transcribing. leaveEditor() called
MicCapture.cancel() on onFinishInputView, onWindowHidden and onFinishInput, and
onStartInput cancelled on every start, even the same field restarting. A tester
on a OnePlus 12 (build 2448) lost what he had dictated each time. Gboard stops
listening at the hide too, but keeps the words already spoken in the field.

What changed:
- Hidden with its field still bound (onFinishInputView(false), onWindowHidden),
  a recording stops at once as with ✓ and what was heard is transcribed.
- DictationField (Insertion.kt) numbers the fields Hex starts in; a dictation
  keeps the number it was spoken in (MicCapture.start(options, field), handed
  back with the text), and commitSpeech types the text only while that number is
  current, the editor is connected and the field isn't a password one. It no
  longer requires the input view to be shown.
- The same field restarting in place (restarting, same package and fieldId)
  keeps its number and its dictation; any other start is a new field.
- A Hex key hold whose touch Android cancels with the keyboard gone finishes
  the dictation; a cancel with the keyboard up discards it, as before.
- README and comments (MicCapture.cancel, KeepAwake) say what is now true.

Unchanged: the field going away (onFinishInput, another field or app, Next
keyboard) still cancels everything recording or transcribing, so nothing reaches
another field, app or password field. ✕ still discards. Home and the Quick
Settings sheet are untouched apart from MicCapture's insert callback taking the
field number.

Verified on the Studio: :app:testDebugUnitTest (345 tests, 0 failures, four new
cases in InsertionTest) and :app:assemblePreview. On emulator-5710 (API 36) with
a probe app, a preview build of this branch, hold and hands-free × recording and
transcribing: Hide keyboard puts the text spoken before the hide into the same
field (Last dictation counts it), Clear focus and Focus field 2 leave both fields
empty; the microphone's recording stopped within 0.26 s of each hide (dumpsys
audio). Also: ✕ while recording and transcribing, focus moved to a password
field, another app opening during transcription, the 1-minute stop then a hide,
Labs › Automatic listens for the language choosing Español for a dictation
finished hidden, and the Quick Settings sheet copying its text.

* Android keyboard (proposal): offer a dictation whose field went away as "Insert dictation"

Why: with #2820 a dictation goes into the field it was spoken in, even with the
keyboard hidden, but one whose field went away (the app cleared focus, moved to
another field, or closed it while it transcribed) is still dropped. This keeps
it, for a tap, without ever typing it anywhere by itself. A proposal for Ryan:
not to merge before he approves the look and wording.

What changed:
- The field going away (onFinishInput, a new field's onStartInput) calls the new
  MicCapture.leave() instead of cancel(): a recording stops as with ✓ and is
  transcribed; notes of a left dictation ("No speech heard") aren't shown in the
  next field.
- A text whose field is gone is held in HexKeyboard (Kept), in memory only, for
  KEPT_MS = 2 minutes; several join in spoken order. DictationField remembers
  the app of its recent field numbers (appOf).
- The strip offers it once, as a notice: "Insert dictation" with ✕ ("Discard
  dictation" for TalkBack), only in a field of the same app that isn't a
  password field (DictationField.offersKept). The words are never shown. A tap
  types it at the cursor through the same path as a dictation (signature,
  spacing, Undo dictation); ✕, that showing ending, or 2 minutes drop it.
  Nothing is written to disk, the clipboard or a log.
- Strings in English and Simplified Chinese ("插入听写", "丢弃听写"); README.

Removed: the field going away no longer aborts a decode in progress, so a new
dictation in the next field can wait for the left one's decode.

Verified on the Studio: :app:testDebugUnitTest (346 tests, 0 failures, a new
InsertionTest case) and :app:assemblePreview. On emulator-5710 (preview build
9449): focus moved to field 2 while transcribing shows the chip there, and a tap
inserts the text in field 2; nothing in another app (and the chip comes back in
the first app within 2 minutes), nothing in a password field, no second offer
after a hide and reopen, gone after 2 minutes; a hide still types into the same
field with no chip. Screenshots light and dark, Hex key on the left, English and
Chinese, and the accessibility labels from uiautomator --windows.

* Android keyboard: any start of input ends a dictation, a restart included

Why: #2820's first commit kept a dictation when onStartInput came with
restarting = true for the same package and fieldId, taking that for the same
field restarting in place. Chrome, a WebView and Compose move between their
inputs by restarting one view: on emulator-5710 (debug log of acaa7aba4), two web
inputs and a textarea in Chrome and in a WebView, and Hex's own Compose
feedback form, all reported restarting = true, the same package, fieldId -1, and
for the two web inputs the same inputType 0xc0a1, imeOptions, selection 0,0,
no hint, label or extras, and empty text either side. A dictation spoken in web
input A went into input B when the person tapped B or the page called b.focus(),
while recording and while transcribing; in Compose, into the message field. The
old cancel prevented that.

What changed: onStartInput always starts a new field and cancels, as before
#2820. DictationField.started() takes no arguments. A hide still finishes the
recording and types into the same field: Back or an app hiding the keyboard
sends no onStartInput in a native EditText, Chrome or Compose.

Removed: the restart rule. A native app restarting input on the same field
during a dictation (setText, restartInput: restarting = true too) discards it
again, as before #2820. Matching the EditorInfo and the text around the cursor
was weighed and rejected: two empty web or Compose fields look identical.

Verified: :app:testDebugUnitTest (345 tests, 0 failures; InsertionTest's cases
now say any start is another field) and :app:assemblePreview on the Studio. On
emulator-5710 with build 9451: Chrome and WebView, tap B or b.focus() while
recording or transcribing: nothing in A, B or C; clearing A from script (no
restart) keeps the text in A, as Gboard does; Compose, tap the other field while
transcribing: nothing in either. Back while recording or transcribing in
Chrome, Compose and a native EditText, and the probe's Hide keyboard: the text
goes into the field it was spoken in.
2026-11-25 08:48:35 -05:00
..
src Android keyboard (proposal): offer a dictation whose field went away as "Insert dictation" (#2821) 2026-11-25 08:48:35 -05:00
build.gradle.kts Android: Hex words files (Word replacements, review sheet, export) (#2781) 2026-11-24 19:42:04 -05:00
proguard-rules.pro Android: faster English dictation (Labs) (#2704) 2026-11-24 13:36:38 -05:00