hex/android/app/src/main/res/xml
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ryan Vogel 78258948d0
Android: Hex words files (Word replacements, review sheet, export) (#2781)
* docs: define the Hex words file (.hexwords), version 1, with shared cases

Ryan approved sharing vocabulary and word replacements between the desktop,
iPhone and Android apps through a file the person moves themselves. Three
builders start from this in parallel, so the format is written down and frozen
first, with cases all three apps must pass.

- docs/specs/hex-words.md: every field and limit, how text is cleaned and
  compared, the reading order with its refusal and skip reasons, versions,
  what each app writes, the merge rules (desktop and phone) and Undo, the
  file's name and type on each platform, and what a reader must never do.
- tests/fixtures/hex-words: read.json (54 cases over files/, from small to
  hostile: not UTF-8, 10,000 levels deep, duplicate keys, lone surrogates,
  8 MiB + 1 byte generated), merge.json (24 desktop and phone cases),
  write.json (6 cases) and hex-words.schema.json (JSON Schema 2020-12 for
  writer output). files/ is byte-exact (-text -whitespace).
- docs/README.md links the spec.

No app code changes. The typing config (.mhexconfig) stays separate: its
parts need evidence and Full Access, and it describes one phone's keyboard.

Verified: the expected results were produced by a throwaway Python reference
reader, merger and writer (not committed) and read through by hand; every
write.json output and the valid read results re-written validate against the
schema with jsonschema 4.26, and five malformed writer outputs are rejected;
a file with every list at its limits in 4-byte characters is 6.5 MiB, under
the 8 MiB cap; markdownlint-cli2 is clean on the new docs.

* docs(hex-words): Android parses with its own strict parser

org.json is lenient and neither it nor android.util.JsonReader runs in the
app's JVM unit tests, which is where the shared cases run. Verified:
markdownlint-cli2 clean.

* android: read, merge and write Hex words files; Word replacements list

Adds ly.anoma.hex.words: a strict JSON parser of its own (the spec's check
pass and parser in one walk: depth refused as each { or [ opens, duplicate
keys after escapes, lone surrogate escapes, leading zeros, one value only),
the reader, the phone merge and the phone writer, all pure, following
docs/specs/hex-words.md on hex-words-format. Text rules use code points, the
spec's exact White_Space set, Locale.ROOT lowercasing then sigma folding,
general categories L and N, and java.text.Normalizer NFC.

Adds Custom vocabulary's Word replacements: stored in the speech prefs,
escaped as DictationFixes stores its records, within the file's limits,
no empty or blank outputs yet. Dictations apply them before learned fixes
with DictationFixes' whole-word, case-following rules and up to 8 words; a
learned fix for the same heard words is left out. DictationFixes.apply now
builds its table and calls the shared replace(); its behaviour is unchanged.
Only applied while the Custom vocabulary switch is on.

WordsStore keeps the Undo copy (both lists and the switch) in prefs.

Checks: HexWordsCasesTest (the one new test file) runs all 54 read cases,
the 11 phone merge cases with an Undo round trip each, the 2 phone write
cases with a schema check, and writes the cross-check Android sample, which
matches expected.json's apps.android.file. DictationLearningTest gains 3
Word replacement tests. On anomastudio: nice ./gradlew --no-daemon --offline
:app:testDebugUnitTest -x prepareSpeechModel --tests words.* --tests
speech.*: 73 tests, 0 failures.

* android: open, review, add, undo and export Hex words files

Arrival: WordsActivity (exported) carries the spec's two intent filters
(VIEW on content with the three MIME types, and SEND), no BROWSABLE and no
new permission, and Settings > Dictation > Custom vocabulary > Words file >
Open a words file... uses ACTION_OPEN_DOCUMENT (*/*). Only content addresses
are read, never a file path; the file is copied into cache/words-in (at
most 8 MiB + 1 byte), read, and the copy deleted after Add, Cancel or a
refusal. No persistable URI permission is taken, nothing is logged.

The review sheet shows the file's claimed maker, a newer-version note, each
part with its own switch and counts, added rows, clashes (Keep mine by
default, Use this one), what this phone can't use grouped by reason with
examples, and what the file skipped by reason. A refusal is one sentence.
File text is plain Compose text, shortened to 64 code points and wrapped in
FSI/PDI. While Custom vocabulary is off the sheet offers its own switch,
off until tapped. Add saves the Undo copy (both lists and the switch);
Undo is in the confirmation and as Undo last import until either list is
edited by hand or another file is imported.

Settings: Custom vocabulary gains Word replacements (add and remove, with
the file's limits and no blank outputs) and Words file (open, Share...
through a FileProvider on cache/words-out written then renamed, Save to...
with ACTION_CREATE_DOCUMENT, and Include fixes Hex learned, off, shown only
when Labs > Learn from my fixes has fixes in use). HexTheme is now internal
so the new activity uses the app's look. The vocabulary editor reloads after
an import or Undo instead of writing its stale text back.

Manifest adds the activity with its two filters and the FileProvider
(res/xml/words_files.xml). Every new string is in values and values-zh-rCN.
docs/features/README.md describes it in the Android section.

Checks: on anomastudio, nice ./gradlew --no-daemon --offline
:app:testDebugUnitTest -x prepareSpeechModel: 299 tests, 0 failures,
HexWordsCasesTest's shared cases included. Not yet run on an emulator.

* docs(hex-words): pin refusal order and out-of-range numbers; clarify writer order and phone scope

The Android builder found three places where implementations could
disagree:
- Two problems in one file: the spec said 'the first met' but no case
  pinned it. It now says where each problem is met, and three cases pin it
  (duplicate key first, too deep first, syntax error first).
- A number a 64-bit float can't hold (1e400, a 400-digit integer):
  serde_json refuses it, while other parsers read it as infinity. It is now
  notJSON wherever it appears, with two cases.
- A writer checks a full list's limit first, in the reader's order.
Also written down: on a phone, Word replacements apply to the app's and the
keyboard's dictations (never translated ones), and on Android learned fixes
are 'in use' only while Learn from my fixes is on.

Verified: the reference reader (now a single sequential check pass)
regenerates read.json with only the five new cases changed; merge.json and
write.json are unchanged; markdownlint-cli2 is clean.

* android(words): refuse numbers a 64-bit float can't hold as notJSON

The spec at hex-words-format 9fa746aa6 makes a number like 1e400 or a
400-digit integer notJSON wherever it appears; the parser used to accept it
and the reader then refused 1e400 as badVersion. The first-problem order the
spec now pins already held: the walk refuses at the bracket past 8 levels,
at a key's second appearance, or where the text stops being JSON.

Checks: on anomastudio, nice ./gradlew --no-daemon --offline
:app:testDebugUnitTest -x prepareSpeechModel: 299 tests, 0 failures;
HexWordsCasesTest runs all 59 read cases, 11 phone merge, 2 phone write.

* android(words): Undo last import on the Words file page has no chevron

It is an action, not a page, and the Custom vocabulary card's row already
shows none. Seen on the emulator run.

Checks: assembleDebug on anomastudio, then the Words file page on the
hex-words-android emulator (API 35).

* docs(hex-words): a phone's spelling-replacement that repeats an earlier one is a duplicate

The iPhone builder asked what happens when two terms in one file share a
spelling: on a phone both would become replacements with the same heard
words. The spec only covered a spelling against the file's own
replacements. Now: the earlier one wins (the file's own replacements come
first), and a later one is notApplied as duplicate. One new phone merge case.

Verified: the reference merger regenerates merge.json with only the new case
added (25 cases); read.json and write.json unchanged; markdownlint clean.

* android(words): say what a blank replacement is, not that it removes words

The review sheet's deletionNotSupported line said "remove words instead of
writing something", which is false for "new paragraph", whose output is two
line breaks. It now reads, as approved: "… write nothing, or only spaces or
line breaks, which this phone can't do yet: …" (zh-CN: "… 项替换不写入任何
内容,或只写入空格或换行,这台手机暂时做不到:…"). Plurals and the %1$d/%2$s
arguments are unchanged; nothing else changes.

Checks: on anomastudio, nice ./gradlew --no-daemon --offline
:app:testDebugUnitTest -x prepareSpeechModel --rerun-tasks: 299 tests,
0 failures (resources merged and compiled).
2026-11-24 19:42:04 -05:00
..
input_method.xml android: password manager suggestions in the strip (labs) (#2695) 2026-11-24 09:10:42 -05:00
words_files.xml Android: Hex words files (Word replacements, review sheet, export) (#2781) 2026-11-24 19:42:04 -05:00