keyboard: support all Compose KeyboardType variants
- Commit
465093d185e69a9fa6aeecab79b7216fc14f1d1e- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-24 04:11 UTC (1 month ago)
- Parents
98c6df2
Diff
keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.ktindex d7d64750a3..830a3ede03 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.kt@@ -224,7 +224,11 @@ class KeyboardService : InputMethodService(), } syncComposer() composer?.reset()+ // After the field kind: the composer follows the effective (possibly+ // ASCII-forced) layout, not just the user's layout. configureForEditor(info)+ syncComposer()+ composer?.reset() kbState.suggestions = emptyList() kbState.emojiQuery = null kbState.emojiResults = emptyList()
keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.ktindex abe450fd64..2599a6272b 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.kt@@ -13,7 +13,9 @@ import kotlinx.coroutines.launch /** Point [KeyboardService.composer] at whatever the active layout needs, keeping it across no-op changes. */ internal fun KeyboardService.syncComposer() {- val kind = kbState.settings.activeLayout.composer+ // An ASCII-forced field falls back to plain Latin, so it never composes — even+ // when the user's own layout would (pinyin, kana, hangul).+ val kind = if (kbState.forceAscii) null else kbState.settings.activeLayout.composer if (kind == composerKind && (kind == null || composer != null)) return composerKind = kind composer = when (kind) {@@ -86,11 +88,14 @@ internal fun KeyboardService.finishComposition(ic: InputConnection) { /** * Composing (word tracking) is needed for either suggestions or autocorrect, and only- * makes sense for plain text fields (never passwords or the numeric layout). The only- * dictionary we ship is English, so it also stays off for every other layout rather than- * offering English words to someone writing Greek.+ * makes sense for plain text fields (never passwords, ASCII-only or no-suggestion+ * fields, or the numeric layout). The only dictionary we ship is English, so it also+ * stays off for every other layout rather than offering English words to someone+ * writing Greek. */ internal fun KeyboardService.useComposing(): Boolean = (kbState.settings.showSuggestions || kbState.settings.autoCorrect) &&- !kbState.passwordField && kbState.basePage == KeyboardPage.LETTERS &&- kbState.settings.activeLayout.englishDictionary+ !kbState.passwordField && !kbState.forceAscii &&+ kbState.textVariation != TextVariation.NO_SUGGESTIONS &&+ kbState.basePage == KeyboardPage.LETTERS &&+ kbState.effectiveLayout.englishDictionary
keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.ktindex d1269b4145..213b7ec607 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.kt@@ -97,12 +97,19 @@ internal fun KeyboardService.updateAutoCapShift() { if (kbState.basePage != KeyboardPage.LETTERS) return // Shift is a second character layer, not upper case, in scripts like Devanagari or // Thai — auto-capitalizing there would silently swap the whole layout.- if (!kbState.settings.activeLayout.cased) return- if (kbState.passwordField || kbState.textVariation != TextVariation.NORMAL) return+ if (!kbState.effectiveLayout.cased) return+ if (kbState.passwordField) return if (kbState.shift == ShiftState.CAPS_LOCK) return if (!kbState.settings.autoCapitalize) return if (composing.isNotEmpty()) return- kbState.shift = if (isAtSentenceStart()) ShiftState.SHIFTED else ShiftState.OFF+ // Email/URL fields never capitalize; name fields capitalize every word, everything+ // else capitalizes at sentence starts.+ val atStart = when (kbState.textVariation) {+ TextVariation.EMAIL, TextVariation.URL -> false+ TextVariation.PERSON_NAME -> isAtWordStart()+ else -> isAtSentenceStart()+ }+ kbState.shift = if (atStart) ShiftState.SHIFTED else ShiftState.OFF } internal fun KeyboardService.isAtSentenceStart(): Boolean {@@ -115,6 +122,14 @@ internal fun KeyboardService.isAtSentenceStart(): Boolean { return last == ' ' && (prev == '.' || prev == '?' || prev == '!') } +/** True at the start of any word: empty field, after a newline, or after a space. */+internal fun KeyboardService.isAtWordStart(): Boolean {+ val text = textBeforeCursor()+ if (text.isEmpty()) return true+ val last = text[text.length - 1]+ return last == '\n' || last == ' '+}+ /** * Keypress sound only. Haptics moved to the press site in the key composables * ([rememberKeyHapticTick]): a service has no CompositionLocal, and ticking where the
keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.ktindex bf24394b5d..5680eb5d30 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.kt@@ -12,19 +12,24 @@ import com.vayunmathur.keyboard.util.ShiftState * identical, only the decision tree is named per branch. */ internal fun KeyboardService.configureForEditor(info: EditorInfo) {- val cls = info.inputType and InputType.TYPE_MASK_CLASS- val variation = info.inputType and InputType.TYPE_MASK_VARIATION- applyFieldKind(cls, variation)+ val inputType = info.inputType+ val cls = inputType and InputType.TYPE_MASK_CLASS+ val variation = inputType and InputType.TYPE_MASK_VARIATION+ val flags = inputType and InputType.TYPE_MASK_FLAGS+ applyFieldKind(cls, variation, flags) applyEnterAction(info) kbState.shift = ShiftState.OFF } -/** Page, variation and password flag from the input class/variation. */-private fun KeyboardService.applyFieldKind(cls: Int, variation: Int) {+/** Page, variation and password flag from the input class/variation/flags. */+private fun KeyboardService.applyFieldKind(cls: Int, variation: Int, flags: Int) { kbState.passwordField = isPasswordField(cls, variation) // Phone gets its own dial-pad layout (FUTO phone.yaml); number/datetime share the- // numeric layout (FUTO number.yaml). Everything else uses letters.+ // numeric layout (FUTO number.yaml), with the separator set per datetime variation.+ // Everything else uses letters. kbState.textVariation = textVariationFor(cls, variation)+ kbState.numericMode = numericModeFor(cls, variation)+ kbState.forceAscii = isAsciiField(cls, variation, flags) kbState.basePage = basePageFor(cls) kbState.page = kbState.basePage }@@ -45,10 +50,43 @@ private fun textVariationFor(cls: Int, variation: Int): TextVariation { InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS, InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS -> TextVariation.EMAIL InputType.TYPE_TEXT_VARIATION_URI -> TextVariation.URL+ InputType.TYPE_TEXT_VARIATION_PERSON_NAME -> TextVariation.PERSON_NAME+ // Phonetic fields must not be autocorrected: the spelling is the point.+ InputType.TYPE_TEXT_VARIATION_PHONETIC -> TextVariation.NO_SUGGESTIONS+ // Compose sends Ascii as visible-password (Ascii = "latin characters, visible");+ // PasswordVisible arrives the same way. Neither is a login secret, so both skip+ // suggestion/composing and force the ASCII layout rather than masking anything.+ InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD -> TextVariation.NO_SUGGESTIONS else -> TextVariation.NORMAL } } +/**+ * ASCII-only text field: Compose's Ascii (and the matching VisiblePassword form).+ * No dedicated framework constant exists; what distinguishes them from a real+ * login-visible-password is TYPE_TEXT_FLAG_NO_SUGGESTIONS, which Compose sets for+ * both. PasswordVisible the user opted into stays on their own layout.+ */+private fun isAsciiField(cls: Int, variation: Int, flags: Int): Boolean {+ if (cls != InputType.TYPE_CLASS_TEXT) return false+ return variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &&+ (flags and InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0+}++/**+ * Separator set for the numeric page, from the datetime variation. Number-class+ * variations (normal/decimal/signed/password) need no split: the pad already+ * carries `.` `,` `+` `-` on every row set.+ */+private fun numericModeFor(cls: Int, variation: Int): NumericMode {+ if (cls != InputType.TYPE_CLASS_DATETIME) return NumericMode.NUMBER+ return when (variation) {+ InputType.TYPE_DATETIME_VARIATION_DATE -> NumericMode.DATE+ InputType.TYPE_DATETIME_VARIATION_TIME -> NumericMode.TIME+ else -> NumericMode.DATE_TIME+ }+}+ private fun basePageFor(cls: Int): KeyboardPage = when (cls) { InputType.TYPE_CLASS_PHONE -> KeyboardPage.PHONE InputType.TYPE_CLASS_NUMBER,
keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.ktindex 34de44a4d6..11a37729f0 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.kt@@ -6,6 +6,8 @@ import androidx.compose.runtime.setValue import com.vayunmathur.keyboard.platform.VoiceFailure import com.vayunmathur.keyboard.util.ClipItem import com.vayunmathur.keyboard.util.EmojiData+import com.vayunmathur.keyboard.util.KeyboardLayout+import com.vayunmathur.keyboard.util.KeyboardLayouts import com.vayunmathur.keyboard.util.KeyboardPage import com.vayunmathur.keyboard.util.KeyboardSettings import com.vayunmathur.keyboard.util.ShiftState@@ -15,10 +17,20 @@ enum class EnterAction { RETURN, GO, SEARCH, SEND, NEXT, DONE, PREVIOUS } /** * Text-field flavour that tweaks the letters layout: EMAIL surfaces `@`, URL surfaces- * `/` (both in place of the comma key), NORMAL keeps punctuation. Number/phone fields- * use the dedicated numeric page instead (see [KeyboardState.basePage]).+ * `/` (both in place of the comma key), PERSON_NAME capitalizes each word,+ * NO_SUGGESTIONS turns composing off for fields autocorrect would corrupt (phonetic).+ * Everything else keeps punctuation. Number/phone/date-time fields use the dedicated+ * numeric page instead (see [KeyboardState.basePage]). */-enum class TextVariation { NORMAL, EMAIL, URL }+enum class TextVariation { NORMAL, EMAIL, URL, PERSON_NAME, NO_SUGGESTIONS }++/**+ * Which separators the numeric page offers: NUMBER is the calculator-style pad (its+ * `.` `,` `+` `-` already serve every number/decimal/signed combination), DATE swaps+ * in `/`, TIME swaps in `:`, DATE_TIME offers both. Covers Compose Number through+ * DecimalPasswordSigned (same pad, no suggestions) and Date/DateTime/Time.+ */+enum class NumericMode { NUMBER, DATE, TIME, DATE_TIME } /** * What voice input is doing, or null when it is idle. An IME has no window of its own to put@@ -67,9 +79,33 @@ class KeyboardState { /** True when the target field is a password field (disables suggestions/composing). */ var passwordField by mutableStateOf(false) - /** Field flavour that adapts the letters layout (email/url punctuation). */+ /** Field flavour that adapts the letters layout (email/url punctuation, name caps). */ var textVariation by mutableStateOf(TextVariation.NORMAL) + /** Separator set for the numeric page (date/time fields swap in `/` and `:`). */+ var numericMode by mutableStateOf(NumericMode.NUMBER)++ /**+ * True for ASCII-only fields (Compose Ascii and PasswordVisible, both of which arrive+ * as visible-password). While set the letters page renders a Latin layout regardless+ * of the user's active layout; the setting itself is untouched and restored after.+ */+ var forceAscii by mutableStateOf(false)++ /**+ * The letter layout actually drawn: the user's layout, except ASCII-forced fields+ * fall back to English QWERTY unless the active layout is already plain Latin.+ * Composing layouts are excluded even when their rows are Latin (romaji, pinyin):+ * their engines output kana/hanzi, which an ASCII-only field cannot take.+ */+ val effectiveLayout: KeyboardLayout+ get() {+ val active = settings.activeLayout+ if (!forceAscii) return active+ if (active.isLatinScript && active.composer == null) return active+ return KeyboardLayouts.byId("en_qwerty") ?: active+ }+ /** * Navigation-bar height in pixels, read from the window by the service. In an IME * the window insets are not reliably dispatched to Compose, so we pad the keyboard
keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardBottomRow.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardBottomRow.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardBottomRow.ktindex 161fc822ee..939c648ddd 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardBottomRow.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardBottomRow.kt@@ -51,7 +51,7 @@ internal fun BottomRow( SpaceKey( height = keyHeight, weight = 4f,- label = state.settings.activeLayout.name,+ label = state.effectiveLayout.name, onSpace = actions::onSpace, ) CharKey(
keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardLetters.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardLetters.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardLetters.ktindex b5ee5ef207..1f2117d9e8 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardLetters.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardLetters.kt@@ -25,7 +25,9 @@ import com.vayunmathur.library.ui.IconBackspace */ @Composable internal fun LettersPage(state: KeyboardState, actions: ImeActions, keyHeight: Dp) {- val layout = state.settings.activeLayout+ // ASCII-forced fields (Compose Ascii) fall back to plain Latin regardless of the+ // user's layout; the setting itself is untouched.+ val layout = state.effectiveLayout val rows = layout.rows if (state.settings.numberRow && rows.size < 4) { Row(Modifier.fillMaxWidth()) {@@ -43,7 +45,7 @@ internal fun LettersPage(state: KeyboardState, actions: ImeActions, keyHeight: D val commaChar = when (state.textVariation) { com.vayunmathur.keyboard.ime.TextVariation.EMAIL -> "@" com.vayunmathur.keyboard.ime.TextVariation.URL -> "/"- com.vayunmathur.keyboard.ime.TextVariation.NORMAL -> layout.comma+ else -> layout.comma } BottomRow( state, actions, keyHeight,
keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.ktindex e81c6f8824..f79a10f60a 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt@@ -138,7 +138,9 @@ private fun Strip(state: KeyboardState, actions: ImeActions) { page == KeyboardPage.MORE_SYMBOLS if (!textPage) return // Nor do layouts that have nothing to put in it: the one dictionary we ship is English.- val layout = state.settings.activeLayout+ // The effective layout matters here, not the active one: an ASCII-forced field on a+ // CJK layout shows plain Latin, never candidates.+ val layout = state.effectiveLayout // Candidates are not a suggestion the user can decline — on a Chinese layout they // are the only way a character gets typed — so the "show suggestions" preference // does not apply to them.
keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardSymbolPages.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardSymbolPages.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardSymbolPages.ktindex dec8bd672c..3727fbd242 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardSymbolPages.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardSymbolPages.kt@@ -11,6 +11,7 @@ import androidx.compose.ui.unit.sp import com.vayunmathur.keyboard.R import com.vayunmathur.keyboard.ime.ImeActions import com.vayunmathur.keyboard.ime.KeyboardState+import com.vayunmathur.keyboard.ime.NumericMode import com.vayunmathur.keyboard.util.KeyboardPage import com.vayunmathur.keyboard.util.Layouts import com.vayunmathur.library.ui.IconBackspace@@ -66,6 +67,10 @@ internal fun SymbolPage( * the 2/5/8 column and every row shares the same left/right edges. Column widths are * FUTO's fractions — side keys 0.15, digits 0.2333, comma/period 0.1, the two "grow" * keys splitting the remainder — used directly as (relative) row weights.+ *+ * Date/time fields swap the side-column operators for their separators (`/`, `-` for+ * dates, `:` for times) per [NumericMode]; the shared NUMBER pad already carries every+ * key the number/decimal/signed Compose types need, so it is unchanged. */ @Composable internal fun NumericPage(state: KeyboardState, actions: ImeActions, keyHeight: Dp) {@@ -73,22 +78,31 @@ internal fun NumericPage(state: KeyboardState, actions: ImeActions, keyHeight: D val digit = 0.2333f val reg = 0.1f val grow = 0.1333f+ // Left-column operators per mode. NUMBER keeps the calculator set; date/time swap+ // in their separators (both `/` and `-` occur in dates, `:` in times). The+ // displaced operators stay one tap away on ?123.+ val leftKeys = when (state.numericMode) {+ NumericMode.NUMBER -> listOf("+", "-", "*")+ NumericMode.DATE -> listOf("/", "-", "*")+ NumericMode.TIME -> listOf(":", "-", "*")+ NumericMode.DATE_TIME -> listOf("/", ":", "-")+ } Row(Modifier.fillMaxWidth()) {- NumFunctionKey("+", side, keyHeight, actions)+ NumFunctionKey(leftKeys[0], side, keyHeight, actions) SymbolKey('1', keyHeight, actions, digit) SymbolKey('2', keyHeight, actions, digit) SymbolKey('3', keyHeight, actions, digit) NumFunctionKey("%", side, keyHeight, actions) } Row(Modifier.fillMaxWidth()) {- NumFunctionKey("-", side, keyHeight, actions)+ NumFunctionKey(leftKeys[1], side, keyHeight, actions) SymbolKey('4', keyHeight, actions, digit) SymbolKey('5', keyHeight, actions, digit) SymbolKey('6', keyHeight, actions, digit) SpecialKey(keyHeight, side, onClick = actions::onSpace) { IconSpaceBar() } } Row(Modifier.fillMaxWidth()) {- NumFunctionKey("*", side, keyHeight, actions)+ NumFunctionKey(leftKeys[2], side, keyHeight, actions) SymbolKey('7', keyHeight, actions, digit) SymbolKey('8', keyHeight, actions, digit) SymbolKey('9', keyHeight, actions, digit)
keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.ktindex 514bff9511..3e1f6968b8 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.kt@@ -91,6 +91,14 @@ data class KeyboardLayout( composer == ComposerKind.PINYIN_TRADITIONAL || composer == ComposerKind.BOPOMOFO + /**+ * True when the layout's rows are Latin script (ASCII-forced fields keep these and+ * fall back to English QWERTY for everything else). Detected from the first row+ * rather than the id so transliteration layouts (e.g. romaji) count as Latin.+ */+ val isLatinScript: Boolean =+ rows.firstOrNull()?.any { it in 'A'..'Z' || it in 'a'..'z' } == true+ /** What the key at [col] of [row] produces in the given shift state. */ fun charAt(row: Int, col: Int, shifted: Boolean): String { val base = rows[row][col]
keyboard/src/test/java/com/vayunmathur/keyboard/util/FieldKindParityTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/FieldKindParityTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/util/FieldKindParityTest.ktnew file mode 100644index 0000000000..f9c06ac599--- /dev/null+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/util/FieldKindParityTest.kt@@ -0,0 +1,68 @@+package com.vayunmathur.keyboard.util++import com.vayunmathur.keyboard.ime.NumericMode+import com.vayunmathur.keyboard.ime.TextVariation+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertNotNull+import kotlin.test.assertTrue++/**+ * Guards the Compose-[KeyboardType] parity added on top of the field-kind mapping:+ * every layout must classify as Latin/non-Latin, and the effective-layout/TextVariation+ * contract in [com.vayunmathur.keyboard.ime.KeyboardState] must hold for the new+ * variants (PERSON_NAME caps, NO_SUGGESTIONS, ASCII fallback).+ */+class FieldKindParityTest {++ /** ASCII-forced fields keep plain-Latin user layouts and fall back otherwise. */+ @Test+ fun `effective layout keeps latin and falls back for other scripts`() {+ val state = com.vayunmathur.keyboard.ime.KeyboardState()+ state.forceAscii = true++ state.settings = KeyboardSettings(activeLayoutId = "fr_azerty")+ assertEquals("fr_azerty", state.effectiveLayout.id)++ state.settings = KeyboardSettings(activeLayoutId = "ru")+ assertEquals("en_qwerty", state.effectiveLayout.id)++ state.settings = KeyboardSettings(activeLayoutId = "ja_romaji")+ assertEquals("en_qwerty", state.effectiveLayout.id)++ state.forceAscii = false+ state.settings = KeyboardSettings(activeLayoutId = "ru")+ assertEquals("ru", state.effectiveLayout.id)+ }++ /** Every catalog layout reports whether its first row is Latin script. */+ @Test+ fun `latin script classification covers the catalog`() {+ val latin = assertNotNull(KeyboardLayouts.byId("en_qwerty"))+ assertTrue(latin.isLatinScript)+ val cyrillic = assertNotNull(KeyboardLayouts.byId("ru"))+ assertFalse(cyrillic.isLatinScript)+ val arabic = assertNotNull(KeyboardLayouts.byId("ar"))+ assertFalse(arabic.isLatinScript)+ // Every transliteration layout whose rows are Latin still counts as Latin.+ for (layout in KeyboardLayouts.ALL) {+ val firstRowLatin =+ layout.rows.firstOrNull()?.any { it in 'A'..'Z' || it in 'a'..'z' } == true+ assertEquals(firstRowLatin, layout.isLatinScript, "${layout.id} misclassified")+ }+ }++ /** The new TextVariation/NumericMode members exist with the expected names. */+ @Test+ fun `parity enums carry the new variants`() {+ assertEquals(+ setOf("NORMAL", "EMAIL", "URL", "PERSON_NAME", "NO_SUGGESTIONS"),+ TextVariation.entries.map { it.name }.toSet(),+ )+ assertEquals(+ setOf("NUMBER", "DATE", "TIME", "DATE_TIME"),+ NumericMode.entries.map { it.name }.toSet(),+ )+ }+}