Modern Apps git

← Modern-Apps.git

keyboard: fix all lint findings

Commit
9562a767c110b9f983615273f9e6c0834be90532
Author
Vayun Mathur <[email protected]>
When
2026-11-17 04:21 UTC (19 days ago)
Parents
c8bf71e
Fix every lint error and warning reported for the keyboard module's own sources by :keyboard:lintDev, now 0 errors / 0 warnings for keyboard/** (remaining report entries are transitive library findings owned by other clusters). No network dependency or permission was added — the offline guarantee is unchanged.

PackageStructure: moved ime/ (18 files) to platform/ime/ and updated the manifest IME service from .ime.KeyboardService to .platform.ime.KeyboardService; util/ layouts moved to domain/, dictionaries, clipboard, prefs and emojis to data/; matching test directories moved. OneComposablePerFile splits: ClipPreview, EmojiSearchResults, SpaceKey, RepeatKey, ShiftKey, SpecialKeyColor, PressedKeyColor, CharKey and CandidateStrip. Converted KeyboardState.bottomInsetPx to mutableIntStateOf and added POST_NOTIFICATIONS to the manifest.

No resources deleted (all keyboard UnusedResources findings were library-owned). No @SuppressLint added; no lint config or baseline changed; no rule-bug categories.

Verified: ./gradlew :keyboard:lintDev (0 own-module errors/warnings) and :keyboard:testDevUnitTest green.

Diff

keyboard/src/main/AndroidManifest.xml
diff --git a/keyboard/src/main/AndroidManifest.xml b/keyboard/src/main/AndroidManifest.xmlindex c865e31c86..0fb23d3943 100644--- a/keyboard/src/main/AndroidManifest.xml+++ b/keyboard/src/main/AndroidManifest.xml@@ -9,6 +9,7 @@     <uses-permission android:name="com.vayunmathur.permission.SENSORS_OPTOUT" />      <uses-permission android:name="android.permission.RECORD_AUDIO" />+    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />      <!-- SpeechRecognizer.isRecognitionAvailable() and the bind behind it both need to see the          recognition service, which package visibility hides by default. -->@@ -49,7 +50,7 @@             android:theme="@android:style/Theme.Translucent.NoTitleBar" />          <service-            android:name=".ime.KeyboardService"+            android:name=".platform.ime.KeyboardService"             android:label="@string/app_name"             android:directBootAware="true"             android:permission="android.permission.BIND_INPUT_METHOD"
keyboard/src/main/java/com/vayunmathur/keyboard/MainActivity.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/MainActivity.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/MainActivity.ktindex a0540e36e6..168f190fff 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/MainActivity.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/MainActivity.kt@@ -5,7 +5,7 @@ import com.vayunmathur.keyboard.ui.SetupScreen import com.vayunmathur.library.ui.MaActivity  /**- * Setup + settings entry point. The IME itself lives in [com.vayunmathur.keyboard.ime.KeyboardService];+ * Setup + settings entry point. The IME itself lives in [com.vayunmathur.keyboard.platform.ime.KeyboardService];  * this activity only helps the user enable/select the keyboard and tune its preferences.  */ class MainActivity : MaActivity() {
keyboard/src/main/java/com/vayunmathur/keyboard/data/Clipboard.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Clipboard.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/data/Clipboard.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/Clipboard.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/data/Clipboard.ktindex 4c1900cc5f..f25b839848 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Clipboard.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/data/Clipboard.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data  import android.content.ClipData import android.content.ClipDescription
keyboard/src/main/java/com/vayunmathur/keyboard/data/Dictionary.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Dictionary.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/data/Dictionary.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/Dictionary.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/data/Dictionary.ktindex 55b7b68106..9b577b6c3f 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Dictionary.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/data/Dictionary.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data  import android.content.Context import kotlinx.coroutines.Dispatchers
keyboard/src/main/java/com/vayunmathur/keyboard/data/Emojis.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Emojis.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/data/Emojis.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/Emojis.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/data/Emojis.ktindex edf061a369..8f549208f1 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Emojis.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/data/Emojis.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data  import android.content.Context import kotlinx.coroutines.Dispatchers
keyboard/src/main/java/com/vayunmathur/keyboard/data/KeyboardPrefs.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardPrefs.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/data/KeyboardPrefs.ktsimilarity index 96%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardPrefs.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/data/KeyboardPrefs.ktindex 8759559e78..e2b76f9bcb 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardPrefs.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/data/KeyboardPrefs.kt@@ -1,4 +1,7 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data++import com.vayunmathur.keyboard.domain.KeyboardLayout+import com.vayunmathur.keyboard.domain.KeyboardLayouts  import com.vayunmathur.library.util.DataStoreUtils 
keyboard/src/main/java/com/vayunmathur/keyboard/data/PinyinDictionary.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/PinyinDictionary.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/data/PinyinDictionary.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/PinyinDictionary.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/data/PinyinDictionary.ktindex 2ce778fed8..28c71a025d 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/PinyinDictionary.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/data/PinyinDictionary.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data  import android.content.Context import kotlinx.coroutines.Dispatchers
keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayout.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayout.ktsimilarity index 98%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayout.ktindex 3e1f6968b8..7e1757309c 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayout.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayout.kt@@ -1,8 +1,8 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain  /**  * The composition engine a layout needs, for scripts where a keystroke is not a character.- * Resolved to an implementation by the IME service (see `com.vayunmathur.keyboard.ime`).+ * Resolved to an implementation by the IME service (see `com.vayunmathur.keyboard.platform.ime`).  */ enum class ComposerKind {     /** Korean: assemble jamo into syllable blocks. */
keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayouts.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayouts.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayouts.ktsimilarity index 91%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayouts.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayouts.ktindex 14baa39dae..edb1177b03 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayouts.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayouts.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain  /**  * The catalogue of layouts the user can enable in settings.@@ -14,7 +14,7 @@ package com.vayunmathur.keyboard.util  * those languages report what the real fingering should be.  *  * Korean, Chinese, Japanese and Ethiopic are typed through the composition engines in- * [com.vayunmathur.keyboard.ime.Composer]: for those the rows are only half the story, since+ * [com.vayunmathur.keyboard.platform.ime.Composer]: for those the rows are only half the story, since  * what a key produces depends on the keys around it.  */ object KeyboardLayouts {
keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsCyrillic.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsCyrillic.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsCyrillic.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsCyrillic.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsCyrillic.ktindex ce8cb68f1a..c27faa28ac 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsCyrillic.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsCyrillic.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain  /** Cyrillic-family layouts, in picker order after Latin. */ internal val cyrillicKeyboardLayouts: List<KeyboardLayout> by lazy {
keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsLatin.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsLatin.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsLatin.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsLatin.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsLatin.ktindex eab035ecae..e9f9807a85 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsLatin.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsLatin.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain  /** Latin-family layouts: Latin first in picker order. Includes the "More Latin" tail. */ internal val latinKeyboardLayouts: List<KeyboardLayout> by lazy {
keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsOther.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsOther.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsOther.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsOther.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsOther.ktindex 38eab20118..5ffb314a54 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/KeyboardLayoutsOther.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/KeyboardLayoutsOther.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain  /** All remaining scripts: Greek through Indic, CJK composers, and the tail. */ internal val otherScriptKeyboardLayouts: List<KeyboardLayout> by lazy {@@ -82,7 +82,7 @@ internal val otherScriptKeyboardLayouts: List<KeyboardLayout> by lazy {             rows = listOf("ๆไำพะัีรนยบลฃ", "ฟหกดเ้่าสวง", "ผปแอิืทมใฝ"),             shiftedRows = listOf("๐\"ฎฑธํ๊ณฯญฐ,ฅ", "ฤฆฏโฌ็๋ษศซ.", "()ฉฮฺ์?ฒฬฦ"),         ),-        // --- Composed scripts (see com.vayunmathur.keyboard.ime.Composer) ---+        // --- Composed scripts (see com.vayunmathur.keyboard.platform.ime.Composer) ---         KeyboardLayout(             id = "ko_dubeolsik",             name = "한국어",
keyboard/src/main/java/com/vayunmathur/keyboard/domain/Layouts.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/Layouts.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/domain/Layouts.ktindex 21c776ecde..37436aac05 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/domain/Layouts.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain  import java.text.Normalizer 
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/Composer.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/Composer.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/Composer.ktsimilarity index 98%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/Composer.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/Composer.ktindex d905ddc234..ded836f60c 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/Composer.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/Composer.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  /**  * What one keystroke did to a composition.
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/EthiopicComposer.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/EthiopicComposer.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/EthiopicComposer.ktsimilarity index 97%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/EthiopicComposer.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/EthiopicComposer.ktindex 7c0700ecea..6fc888c9b2 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/EthiopicComposer.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/EthiopicComposer.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  /**  * Ethiopic (Geʽez) syllable assembly, for Amharic and Tigrinya.
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HanComposer.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HanComposer.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HanComposer.ktsimilarity index 97%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/HanComposer.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HanComposer.ktindex 64cae07203..e99909e30b 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HanComposer.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HanComposer.kt@@ -1,6 +1,6 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime -import com.vayunmathur.keyboard.util.PinyinDictionary+import com.vayunmathur.keyboard.data.PinyinDictionary  /**  * How a Chinese layout spells a syllable before it becomes a character.
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HangulComposer.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HangulComposer.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HangulComposer.ktindex bb93964f32..9bb52f1b2b 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/HangulComposer.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/HangulComposer.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  /**  * Hangul (한글) assembly: turns the jamo the Korean layouts emit into syllable blocks.
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KanaComposers.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KanaComposers.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KanaComposers.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KanaComposers.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KanaComposers.ktindex 9816bfc282..792af62f08 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KanaComposers.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KanaComposers.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  /**  * The two Japanese input styles: romaji typed on a Latin layout, and kana typed directly on
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardActionHandler.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardActionHandler.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardActionHandler.ktsimilarity index 90%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardActionHandler.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardActionHandler.ktindex 19bf02509e..efcf29fab5 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardActionHandler.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardActionHandler.kt@@ -1,7 +1,7 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime -import com.vayunmathur.keyboard.util.ClipItem-import com.vayunmathur.keyboard.util.KeyboardPage+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.domain.KeyboardPage  /**  * The [ImeActions] implementation, delegating to the `KeyboardService*Ops.kt`
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.ktsimilarity index 97%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.ktindex 830a3ede03..a6b6ce1df2 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardService.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.content.ClipboardManager import android.inputmethodservice.InputMethodService@@ -26,13 +26,13 @@ import androidx.savedstate.setViewTreeSavedStateRegistryOwner import com.vayunmathur.keyboard.platform.VoiceInput import com.vayunmathur.keyboard.platform.VoicePermission import com.vayunmathur.keyboard.ui.KeyboardScreen-import com.vayunmathur.keyboard.util.ClipboardStore-import com.vayunmathur.keyboard.util.ComposerKind-import com.vayunmathur.keyboard.util.Dictionary-import com.vayunmathur.keyboard.util.EmojiData-import com.vayunmathur.keyboard.util.KeyboardSettings-import com.vayunmathur.keyboard.util.PinyinDictionary-import com.vayunmathur.keyboard.util.RecentEmoji+import com.vayunmathur.keyboard.data.ClipboardStore+import com.vayunmathur.keyboard.domain.ComposerKind+import com.vayunmathur.keyboard.data.Dictionary+import com.vayunmathur.keyboard.data.EmojiData+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.data.PinyinDictionary+import com.vayunmathur.keyboard.data.RecentEmoji import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.util.DataStoreUtils import kotlinx.coroutines.CoroutineScope
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceClipboardOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceClipboardOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceClipboardOps.ktsimilarity index 97%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceClipboardOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceClipboardOps.ktindex 6a4821ea35..af0937d4aa 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceClipboardOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceClipboardOps.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.content.ClipDescription import android.content.ClipboardManager@@ -8,9 +8,9 @@ import androidx.core.view.inputmethod.EditorInfoCompat import androidx.core.view.inputmethod.InputConnectionCompat import androidx.core.view.inputmethod.InputContentInfoCompat import com.vayunmathur.keyboard.R-import com.vayunmathur.keyboard.util.ClipboardStore-import com.vayunmathur.keyboard.util.ClipItem-import com.vayunmathur.keyboard.util.KeyboardSettings+import com.vayunmathur.keyboard.data.ClipboardStore+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.KeyboardSettings import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceComposerOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceComposerOps.ktsimilarity index 95%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceComposerOps.ktindex 2599a6272b..d70d74ec78 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceComposerOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceComposerOps.kt@@ -1,9 +1,9 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.view.inputmethod.InputConnection-import com.vayunmathur.keyboard.util.ComposerKind-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.PinyinDictionary+import com.vayunmathur.keyboard.domain.ComposerKind+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.data.PinyinDictionary import kotlinx.coroutines.launch  /**
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditOps.ktsimilarity index 96%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditOps.ktindex 213b7ec607..304a698b01 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditOps.kt@@ -1,10 +1,10 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.media.AudioManager import android.view.inputmethod.InputConnection-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.KeyboardSettings-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.domain.ShiftState  /**  * Field-edit and suggestion helpers split from KeyboardService
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditorConfig.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditorConfig.ktsimilarity index 97%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditorConfig.ktindex 5680eb5d30..3514fe12c6 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEditorConfig.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEditorConfig.kt@@ -1,9 +1,9 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.text.InputType import android.view.inputmethod.EditorInfo-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.domain.ShiftState  /**  * Derives the keyboard's page, text variation and enter behaviour from the target field.
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEmojiOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEmojiOps.ktsimilarity index 90%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEmojiOps.ktindex c93b88693c..eda2741d3d 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceEmojiOps.kt@@ -1,9 +1,9 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime -import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.KeyboardSettings-import com.vayunmathur.keyboard.util.RecentEmoji-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.data.RecentEmoji+import com.vayunmathur.keyboard.domain.ShiftState import kotlinx.coroutines.launch  /**
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceKeyOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.ktsimilarity index 98%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceKeyOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.ktindex d69b488e78..1cbdd4c074 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceKeyOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.kt@@ -1,8 +1,8 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.os.SystemClock import android.view.KeyEvent-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.ShiftState  /**  * Letter-key actions split from KeyboardService (LargeClass/TooManyFunctions).
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSetupOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceSetupOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSetupOps.ktsimilarity index 96%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceSetupOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSetupOps.ktindex 3a42692f2b..a0fdf803b6 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceSetupOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSetupOps.kt@@ -1,6 +1,6 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime -import com.vayunmathur.keyboard.util.KeyboardSettings+import com.vayunmathur.keyboard.data.KeyboardSettings import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch 
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSubtypeOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceSubtypeOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSubtypeOps.ktsimilarity index 95%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceSubtypeOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSubtypeOps.ktindex 33daccd32c..60713a89f4 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceSubtypeOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceSubtypeOps.kt@@ -1,13 +1,13 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.os.Build import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodSubtype import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder import com.vayunmathur.keyboard.R-import com.vayunmathur.keyboard.util.KeyboardLayouts-import com.vayunmathur.keyboard.util.KeyboardSettings-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.KeyboardLayouts+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.domain.ShiftState import kotlinx.coroutines.launch  /**
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceVoiceOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceVoiceOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceVoiceOps.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceVoiceOps.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceVoiceOps.ktindex b2ee1757f7..caaab3261e 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceVoiceOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceVoiceOps.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.content.Intent import android.net.Uri
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardState.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardState.ktsimilarity index 94%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardState.ktindex 5e88b8f897..ea1a554d16 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardState.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardState.kt@@ -1,16 +1,17 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf 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+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.EmojiData+import com.vayunmathur.keyboard.domain.KeyboardLayout+import com.vayunmathur.keyboard.domain.KeyboardLayouts+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.domain.ShiftState  /** What the Enter key should do, derived from the target field's [android.view.inputmethod.EditorInfo]. */ enum class EnterAction { RETURN, GO, SEARCH, SEND, NEXT, DONE, PREVIOUS }@@ -111,7 +112,7 @@ class KeyboardState {      * the window insets are not reliably dispatched to Compose, so we pad the keyboard      * bottom by this value ourselves to keep the last row clear of the system bar.      */-    var bottomInsetPx by mutableStateOf(0)+    var bottomInsetPx by mutableIntStateOf(0)      /** The emoji palette, replaced by the generated asset once the service has read it. */     var emojiData by mutableStateOf(EmojiData.BUILTIN)
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursor.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/TextBeforeCursor.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursor.ktsimilarity index 99%rename from keyboard/src/main/java/com/vayunmathur/keyboard/ime/TextBeforeCursor.ktrename to keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursor.ktindex 9403fc92b2..eda776b722 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/TextBeforeCursor.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursor.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  /**  * A local mirror of the text immediately before the cursor, and of whether anything is
keyboard/src/main/java/com/vayunmathur/keyboard/ui/CandidateStrip.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/CandidateStrip.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/CandidateStrip.ktnew file mode 100644index 0000000000..bfcf8b0dcc--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/CandidateStrip.kt@@ -0,0 +1,77 @@+package com.vayunmathur.keyboard.ui++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyRow+import androidx.compose.foundation.lazy.itemsIndexed+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.VerticalDivider++/**+ * The candidate strip for the composed scripts: the characters a pinyin or bopomofo spelling+ * could be, scrolling sideways because a syllable like `shi` has dozens of them.+ *+ * Separate from [SuggestionStrip] because the two are doing different jobs. A word suggestion+ * is an offer you can ignore; a Chinese candidate *is* the input — you have not typed a+ * character until you pick one — so these are sized to their content and never truncated.+ */+@Composable+fun CandidateStrip(+    height: Dp,+    candidates: List<String>,+    onPick: (String) -> Unit,+) {+    val tick = rememberKeyHapticTick()+    LazyRow(+        modifier = Modifier+            .fillMaxWidth()+            .height(height),+        verticalAlignment = Alignment.CenterVertically,+    ) {+        itemsIndexed(candidates) { index, candidate ->+            if (index > 0) {+                VerticalDivider(+                    modifier = Modifier+                        .height(height)+                        .padding(vertical = 8.dp),+                )+            }+            Box(+                modifier = Modifier+                    .fillMaxHeight()+                    .clickable {+                        tick()+                        onPick(candidate)+                    }+                    .padding(horizontal = 14.dp),+                contentAlignment = Alignment.Center,+            ) {+                Text(+                    text = candidate,+                    // The first candidate is what space commits, so it is the one that has+                    // to look chosen rather than merely first in a list.+                    color = if (index == 0) {+                        MaterialTheme.colorScheme.primary+                    } else {+                        MaterialTheme.colorScheme.onSurface+                    },+                    fontSize = 22.sp,+                    maxLines = 1,+                )+            }+        }+    }+}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/CharKey.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/CharKey.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/CharKey.ktnew file mode 100644index 0000000000..d33e78df62--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/CharKey.kt@@ -0,0 +1,280 @@+@file:OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)++package com.vayunmathur.keyboard.ui++import android.os.SystemClock+import androidx.compose.foundation.background+import androidx.compose.foundation.gestures.awaitEachGesture+import androidx.compose.foundation.gestures.awaitFirstDown+import androidx.compose.foundation.interaction.MutableInteractionSource+import androidx.compose.foundation.interaction.PressInteraction+import androidx.compose.foundation.interaction.collectIsPressedAsState+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberUpdatedState+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.input.pointer.PointerInputChange+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.layout.onGloballyPositioned+import androidx.compose.ui.layout.positionInWindow+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.platform.LocalWindowInfo+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.keyboard.domain.Layouts+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import kotlinx.coroutines.withTimeoutOrNull++/**+ * A letter/symbol key: tap commits [label]; holding it opens the [alternates] — the accented+ * or related characters that key can also produce — and sliding onto one picks it, the way+ * every phone keyboard does accents. An optional [hint] draws a small secondary label beneath+ * the main one (the ABC/DEF letters on the phone dial-pad, matching FUTO's phone layout), and+ * [cornerHint] draws one in the top-left corner instead (the digit a letter key doubles as+ * when the persistent number row is off).+ *+ * The popup always opens with [label] itself as its leftmost entry, so a long press that+ * turns out to have been a mistake can still be finished with the plain letter instead of+ * forcing the user to release onto an accent and delete it.+ *+ * The whole thing is one gesture: press, hold, slide, release. Nothing has to dismiss the+ * popup, which matters in an IME — a focusable popup would take focus away from the very+ * field being typed into, and a non-focusable one has no way to learn about a tap outside it.+ */+@Composable+fun RowScope.CharKey(+    label: String,+    height: Dp,+    weight: Float = 1f,+    hint: String? = null,+    cornerHint: String? = null,+    alternates: String = "",+    onClick: () -> Unit,+    onAlternate: ((String) -> Unit)? = null,+) {+    val interaction = remember { MutableInteractionSource() }+    val pressed by interaction.collectIsPressedAsState()+    // -1 while the popup is closed, otherwise the alternate under the finger.+    var selected by remember { mutableIntStateOf(-1) }+    // Where the key sits, recorded on layout. Deliberately *not* snapshot state: writing+    // state from onGloballyPositioned that composition then reads schedules another+    // recomposition and another layout pass, and with every key on the keyboard doing it+    // that doubles the cost of every relayout. Nothing needs these until a long press has+    // opened the popup, by which point the key has long since been positioned.+    val bounds = remember { KeyBounds() }++    val density = LocalDensity.current+    val screenWidth = LocalWindowInfo.current.containerSize.width.toFloat()++    // What the popup actually offers: the key's own character first, then its alternates.+    // Each entry has to be one character for the index maths below to hold, so the handful+    // of layouts whose comma or period is a multi-character string keep the bare list.+    val options = remember(label, alternates) {+        when {+            alternates.isEmpty() -> ""+            label.length == 1 -> label + alternates+            else -> alternates+        }+    }++    // Every entry gets its full width unless the row would run off the screen, in which case+    // they share what there is. Clamping the row's position alone is not enough: a long list+    // on a narrow phone would put the last entries past the edge, where no finger can reach.+    val itemWidth = remember(options, screenWidth, density) {+        val full = with(density) { AlternateWidth.toPx() }+        if (options.isEmpty()) full else minOf(full, screenWidth / options.length)+    }+    // Key tick at each commit site below — the gesture runs in pointerInput where+    // LocalHapticFeedback can't be read, so it comes through this captured lambda.+    val tick = rememberKeyHapticTick()+    val currentTick by rememberUpdatedState(tick)++    // The gesture below reads all of these through snapshots rather than capturing them, so it+    // never has to be restarted to pick up a new value. See the note on `pointerInput(Unit)`.+    val currentOnClick by rememberUpdatedState(onClick)+    val currentOnAlternate by rememberUpdatedState(onAlternate)+    val currentOptions by rememberUpdatedState(options)+    val currentItemWidth by rememberUpdatedState(itemWidth)+    val currentScreenWidth by rememberUpdatedState(screenWidth)++    Box(+        modifier = Modifier+            .weight(weight)+            // The whole weighted cell — including the KeyPadding gap — takes the touch, so+            // there are no dead strips between keys. The gap is reinstated as padding further+            // down, but only for the visual (clip + background), never for hit-testing.+            .height(height + KeyPadding * 2)+            .onGloballyPositioned {+                bounds.left = it.positionInWindow().x+                bounds.width = it.size.width.toFloat()+            }+            // Written out rather than assembled from detectTapGestures because tap and+            // long-press are one continuous gesture here: the long press opens the popup+            // and the *same* touch goes on to choose from it.+            //+            // Keyed on Unit, deliberately. Keying it on the callbacks instead restarts the+            // gesture whenever a recomposition reallocates them, and `ImeActions` is an+            // interface so Compose treats it as unstable and reallocates them every time.+            // A restart cancels this coroutine, and if that lands between the down and the+            // up — a suggestion arriving, auto-capitalise flipping shift, a settings flow+            // emitting, all of which happen mid-keypress — the Press interaction is never+            // released and the key stays lit with its preview stuck above it until it+            // leaves composition (i.e. until the user switches to another page).+            //+            // One gesture per awaitEachGesture iteration, deliberately. The previous code+            // waited out the long-press timeout and then started a *second* wait for the+            // lift; an up landing in between left the second wait holding a stale+            // still-pressed snapshot, so it hung until the next touch on the same key —+            // the stuck popup — and that next touch was then consumed as the old+            // gesture's release position, committing a phantom variant. A tap whose up+            // arrived as a cancellation (second thumb down mid-tap) also read as a+            // timeout and opened the menu. Bounding each down→up to one iteration+            // removes all three.+            .pointerInput(Unit) {+                awaitEachGesture {+                    val down = awaitFirstDown(requireUnconsumed = false)+                    val press = PressInteraction.Press(down.position)+                    try {+                        // tryEmit, not emit: awaitEachGesture's block is a restricted+                        // suspend scope, so member suspend calls on other objects+                        // (like emit) do not compile here.+                        interaction.tryEmit(press)+                        val timeout = viewConfiguration.longPressTimeoutMillis+                        val start = SystemClock.uptimeMillis()+                        var up: PointerInputChange? = null+                        var lastX = down.position.x+                        while (up == null && SystemClock.uptimeMillis() - start < timeout) {+                            val remaining = timeout - (SystemClock.uptimeMillis() - start)+                            val event = withTimeoutOrNull(remaining.coerceAtLeast(0L)) {+                                awaitPointerEvent()+                            } ?: break+                            val change = event.changes.firstOrNull { it.id == down.id } ?: continue+                            lastX = change.position.x+                            if (!change.pressed) up = change+                        }+                        if (up != null) {+                            if (up.position.isInside(size)) {+                                currentTick()+                                currentOnClick()+                            }+                            return@awaitEachGesture+                        }+                        val opts = currentOptions+                        val onAlt = currentOnAlternate+                        if (opts.isEmpty() || onAlt == null) {+                            // A hold with nothing to offer still types the key; the old+                            // code waited for the lift and then committed nothing.+                            currentTick()+                            currentOnClick()+                            return@awaitEachGesture+                        }+                        val offset = alternatesOffset(bounds, currentItemWidth, opts.length, currentScreenWidth)+                        var picked = indexAt(lastX, offset, currentItemWidth, opts.length)+                        selected = picked+                        while (true) {+                            val event = awaitPointerEvent()+                            val change = event.changes.firstOrNull { it.id == down.id }+                            if (change == null) {+                                // Only other pointers speaking. A fresh down here means+                                // our own up was lost in the timeout race; abandon rather+                                // than hang on a gesture that is already over.+                                if (event.changes.any { it.pressed && !it.previousPressed }) {+                                    return@awaitEachGesture+                                }+                                continue+                            }+                            if (!change.pressed) {+                                currentTick()+                                onAlt(opts[picked].toString())+                                break+                            }+                            picked = indexAt(change.position.x, offset, currentItemWidth, opts.length)+                            selected = picked+                        }+                    } finally {+                        // tryEmit, not emit: this also has to run on the cancellation path,+                        // where a suspending emit would itself be cancelled and leave the+                        // key stuck.+                        selected = -1+                        interaction.tryEmit(PressInteraction.Release(press))+                    }+                }+            }+            .padding(KeyPadding)+            .clip(KeyShape)+            .background(if (pressed) pressedKeyColor() else charKeyColor()),+        contentAlignment = Alignment.Center,+    ) {+        if (hint != null) {+            Column(horizontalAlignment = Alignment.CenterHorizontally) {+                Text(text = label, color = MaterialTheme.colorScheme.onSurface, fontSize = 18.sp)+                Text(text = hint, color = MaterialTheme.colorScheme.onSurfaceVariant, fontSize = 9.sp)+            }+        } else {+            Text(text = label, color = MaterialTheme.colorScheme.onSurface, fontSize = 20.sp)+        }+        if (cornerHint != null) {+            Text(+                text = cornerHint,+                color = MaterialTheme.colorScheme.onSurfaceVariant,+                fontSize = 10.sp,+                modifier = Modifier+                    .align(Alignment.TopStart)+                    .padding(top = 2.dp, start = 6.dp),+            )+        }+        // What a long press gets you, previewed in the corner so the alternates are+        // discoverable instead of folklore. Accented forms of the letter itself are not+        // worth the clutter — every vowel would wear one and it tells you nothing you+        // couldn't guess — so those fall back to a plain dot.+        val altHint = remember(alternates, label, cornerHint) {+            Layouts.alternatePreview(alternates, label, cornerHint)+        }+        when {+            altHint != null -> Text(+                text = altHint,+                color = MaterialTheme.colorScheme.onSurfaceVariant,+                fontSize = 10.sp,+                modifier = Modifier+                    .align(Alignment.BottomEnd)+                    .padding(bottom = 2.dp, end = 5.dp),+            )+            alternates.isNotEmpty() -> Box(+                Modifier+                    .align(Alignment.BottomEnd)+                    .padding(bottom = 5.dp, end = 5.dp)+                    .size(3.dp)+                    .clip(CircleShape)+                    .background(MaterialTheme.colorScheme.onSurfaceVariant),+            )+        }+        when {+            selected >= 0 -> AlternatesPopup(+                options = options,+                selected = selected,+                itemWidth = with(density) { itemWidth.toDp() },+                offsetX = alternatesOffset(bounds, itemWidth, options.length, screenWidth).toInt(),+            )+            // FUTO/AOSP-style preview: while held, balloon the character above the key so+            // the finger doesn't hide it. clippingEnabled=false lets it float above the+            // top row (outside the keyboard bounds).+            pressed -> KeyPreview(label)+        }+    }+}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipPreview.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipPreview.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipPreview.ktnew file mode 100644index 0000000000..7d3bd0dd23--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipPreview.kt@@ -0,0 +1,116 @@+package com.vayunmathur.keyboard.ui++import androidx.compose.foundation.Image+import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.produceState+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.blur+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.ImageBitmap+import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.TextUnit+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.keyboard.R+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.ClipboardStore+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.IconPaste+import com.vayunmathur.library.ui.IconVisibilityOff+import com.vayunmathur.library.ui.IconVisible+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * A clip rendered as one line of text or a thumbnail. Sensitive text is blurred until the+ * eye is tapped; the reveal is local to this composable and resets whenever it leaves the+ * screen, so nothing stays unblurred behind the user's back.+ */+@Composable+fun ClipPreview(+    item: ClipItem,+    modifier: Modifier = Modifier,+    fontSize: TextUnit = 14.sp,+) {+    var revealed by remember(item.id) { mutableStateOf(false) }+    val thumbnail = rememberClipThumbnail(item)+    Row(modifier = modifier, verticalAlignment = Alignment.CenterVertically) {+        val hidden = item.sensitive && !revealed+        Box(Modifier.weight(1f), contentAlignment = Alignment.CenterStart) {+            when {+                thumbnail != null -> Image(+                    bitmap = thumbnail,+                    contentDescription = null,+                    contentScale = ContentScale.Fit,+                    alignment = Alignment.CenterStart,+                    modifier = Modifier+                        .fillMaxHeight()+                        .then(if (hidden) Modifier.blur(10.dp) else Modifier),+                )+                item.isImage -> Text(+                    text = stringResource(R.string.image),+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                    fontSize = fontSize,+                )+                else -> Text(+                    text = item.preview,+                    color = MaterialTheme.colorScheme.onSurface,+                    fontSize = fontSize,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                    // RenderEffect-backed blur, which needs API 31 — the module's minSdk.+                    modifier = if (hidden) Modifier.blur(8.dp) else Modifier,+                )+            }+        }+        if (item.sensitive) {+            Box(+                modifier = Modifier+                    .fillMaxHeight()+                    .clip(RoundedCornerShape(8.dp))+                    .clickable { revealed = !revealed }+                    .padding(horizontal = 6.dp),+                contentAlignment = Alignment.Center,+            ) {+                val tint = MaterialTheme.colorScheme.onSurfaceVariant+                if (revealed) {+                    IconVisibilityOff(modifier = Modifier.size(18.dp), tint = tint)+                } else {+                    IconVisible(modifier = Modifier.size(18.dp), tint = tint)+                }+            }+        }+    }+}++/** Decode an image clip's thumbnail off the main thread, once per clip. */+@Composable+private fun rememberClipThumbnail(item: ClipItem): ImageBitmap? {+    val file = item.imageFile ?: return null+    return produceState<ImageBitmap?>(initialValue = null, key1 = item.id) {+        value = withContext(Dispatchers.IO) {+            ClipboardStore.decodeThumbnail(file, THUMBNAIL_PX)?.asImageBitmap()+        }+    }.value+}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardPage.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardPage.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardPage.ktindex 1a2eb260e9..3c01ca7b59 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardPage.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardPage.kt@@ -24,7 +24,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.keyboard.R-import com.vayunmathur.keyboard.util.ClipItem+import com.vayunmathur.keyboard.data.ClipItem import com.vayunmathur.library.ui.IconBackspace import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.ui.IconHistory
keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardStrip.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardStrip.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardStrip.ktindex 8328023e48..bbfedd0b5a 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardStrip.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ClipboardStrip.kt@@ -31,8 +31,8 @@ import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.keyboard.R-import com.vayunmathur.keyboard.util.ClipItem-import com.vayunmathur.keyboard.util.ClipboardStore+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.ClipboardStore import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.ui.IconPaste import com.vayunmathur.library.ui.IconVisibilityOff@@ -43,7 +43,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext  /** Longest side, in pixels, that a cached clipboard image is decoded down to for previews. */-private const val THUMBNAIL_PX = 256+internal const val THUMBNAIL_PX = 256  /**  * The chip that appears in the strip right after a copy: tap the icon to open the full@@ -118,76 +118,3 @@ fun ClipboardStrip(         }     } }--/**- * A clip rendered as one line of text or a thumbnail. Sensitive text is blurred until the- * eye is tapped; the reveal is local to this composable and resets whenever it leaves the- * screen, so nothing stays unblurred behind the user's back.- */-@Composable-fun ClipPreview(-    item: ClipItem,-    modifier: Modifier = Modifier,-    fontSize: TextUnit = 14.sp,-) {-    var revealed by remember(item.id) { mutableStateOf(false) }-    val thumbnail = rememberClipThumbnail(item)-    Row(modifier = modifier, verticalAlignment = Alignment.CenterVertically) {-        val hidden = item.sensitive && !revealed-        Box(Modifier.weight(1f), contentAlignment = Alignment.CenterStart) {-            when {-                thumbnail != null -> Image(-                    bitmap = thumbnail,-                    contentDescription = null,-                    contentScale = ContentScale.Fit,-                    alignment = Alignment.CenterStart,-                    modifier = Modifier-                        .fillMaxHeight()-                        .then(if (hidden) Modifier.blur(10.dp) else Modifier),-                )-                item.isImage -> Text(-                    text = stringResource(R.string.image),-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                    fontSize = fontSize,-                )-                else -> Text(-                    text = item.preview,-                    color = MaterialTheme.colorScheme.onSurface,-                    fontSize = fontSize,-                    maxLines = 1,-                    overflow = TextOverflow.Ellipsis,-                    // RenderEffect-backed blur, which needs API 31 — the module's minSdk.-                    modifier = if (hidden) Modifier.blur(8.dp) else Modifier,-                )-            }-        }-        if (item.sensitive) {-            Box(-                modifier = Modifier-                    .fillMaxHeight()-                    .clip(RoundedCornerShape(8.dp))-                    .clickable { revealed = !revealed }-                    .padding(horizontal = 6.dp),-                contentAlignment = Alignment.Center,-            ) {-                val tint = MaterialTheme.colorScheme.onSurfaceVariant-                if (revealed) {-                    IconVisibilityOff(modifier = Modifier.size(18.dp), tint = tint)-                } else {-                    IconVisible(modifier = Modifier.size(18.dp), tint = tint)-                }-            }-        }-    }-}--/** Decode an image clip's thumbnail off the main thread, once per clip. */-@Composable-private fun rememberClipThumbnail(item: ClipItem): ImageBitmap? {-    val file = item.imageFile ?: return null-    return produceState<ImageBitmap?>(initialValue = null, key1 = item.id) {-        value = withContext(Dispatchers.IO) {-            ClipboardStore.decodeThumbnail(file, THUMBNAIL_PX)?.asImageBitmap()-        }-    }.value-}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiPage.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiPage.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiPage.ktindex 9deb9637a1..39639dc697 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiPage.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiPage.kt@@ -23,9 +23,9 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.keyboard.R-import com.vayunmathur.keyboard.util.EmojiCategory-import com.vayunmathur.keyboard.util.EmojiData-import com.vayunmathur.keyboard.util.RecentEmoji+import com.vayunmathur.keyboard.data.EmojiCategory+import com.vayunmathur.keyboard.data.EmojiData+import com.vayunmathur.keyboard.data.RecentEmoji import com.vayunmathur.library.ui.IconBackspace import com.vayunmathur.library.ui.IconSearch import com.vayunmathur.library.ui.MaterialTheme
keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearch.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearch.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearch.ktindex 66d25f1a91..c40409e479 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearch.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearch.kt@@ -78,30 +78,3 @@ fun EmojiSearchBar(height: Dp, query: String, onClose: () -> Unit) {         }     } }--/** The matches for the current query, scrolling sideways. Tapping one commits it. */-@Composable-fun EmojiSearchResults(height: Dp, results: List<String>, onPick: (String) -> Unit) {-    val tick = rememberKeyHapticTick()-    LazyRow(-        modifier = Modifier-            .fillMaxWidth()-            .height(height),-        verticalAlignment = Alignment.CenterVertically,-    ) {-        items(results) { emoji ->-            Box(-                modifier = Modifier-                    .fillMaxHeight()-                    .clickable {-                        tick()-                        onPick(emoji)-                    }-                    .padding(horizontal = 10.dp),-                contentAlignment = Alignment.Center,-            ) {-                Text(text = emoji, fontSize = 26.sp)-            }-        }-    }-}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearchResults.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearchResults.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearchResults.ktnew file mode 100644index 0000000000..6b9878945b--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/EmojiSearchResults.kt@@ -0,0 +1,52 @@+package com.vayunmathur.keyboard.ui++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.lazy.LazyRow+import androidx.compose.foundation.lazy.items+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.keyboard.R+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.IconSearch+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text++/** The matches for the current query, scrolling sideways. Tapping one commits it. */+@Composable+fun EmojiSearchResults(height: Dp, results: List<String>, onPick: (String) -> Unit) {+    val tick = rememberKeyHapticTick()+    LazyRow(+        modifier = Modifier+            .fillMaxWidth()+            .height(height),+        verticalAlignment = Alignment.CenterVertically,+    ) {+        items(results) { emoji ->+            Box(+                modifier = Modifier+                    .fillMaxHeight()+                    .clickable {+                        tick()+                        onPick(emoji)+                    }+                    .padding(horizontal = 10.dp),+                contentAlignment = Alignment.Center,+            ) {+                Text(text = emoji, fontSize = 26.sp)+            }+        }+    }+}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/FunctionKeys.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/FunctionKeys.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/FunctionKeys.ktindex 0347c07c31..2e68f6b5de 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/FunctionKeys.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/FunctionKeys.kt@@ -27,7 +27,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.ShiftState import com.vayunmathur.library.ui.IconShift import com.vayunmathur.library.ui.LocalContentColor import com.vayunmathur.library.ui.MaterialTheme@@ -84,155 +84,3 @@ fun RowScope.SpecialKey(         ) { content() }     } }--/**- * Space bar: tap inserts a space. [label] names the active layout, which is how the user- * can tell at a glance which language they are typing.- */-@Composable-fun RowScope.SpaceKey(-    height: Dp,-    weight: Float,-    label: String,-    onSpace: () -> Unit,-) {-    val interaction = remember { MutableInteractionSource() }-    val pressed by interaction.collectIsPressedAsState()-    val tick = rememberKeyHapticTick()-    Box(-        modifier = Modifier-            .weight(weight)-            .height(height + KeyPadding * 2)-            .clickable(-                interactionSource = interaction,-                indication = null,-                onClick = {-                    tick()-                    onSpace()-                },-            )-            .padding(KeyPadding)-            .clip(KeyShape)-            .background(if (pressed) pressedKeyColor() else charKeyColor()),-        contentAlignment = Alignment.Center,-    ) {-        Text(-            text = label,-            color = MaterialTheme.colorScheme.onSurfaceVariant,-            fontSize = 14.sp,-            maxLines = 1,-            overflow = TextOverflow.Ellipsis,-        )-    }-}--/** Backspace with press-and-hold repeat delete. */-@Composable-fun RowScope.RepeatKey(-    height: Dp,-    weight: Float,-    onRepeat: () -> Unit,-    content: @Composable () -> Unit,-) {-    val interaction = remember { MutableInteractionSource() }-    val pressed by interaction.collectIsPressedAsState()-    val scope = androidx.compose.runtime.rememberCoroutineScope()-    // Captured for the pointerInput block below, which can't read CompositionLocals itself.-    val currentTick by androidx.compose.runtime.rememberUpdatedState(rememberKeyHapticTick())-    Box(-        modifier = Modifier-            .weight(weight)-            .height(height + KeyPadding * 2)-            .pointerInput(Unit) {-                detectTapGestures(onPress = { offset ->-                    val press = PressInteraction.Press(offset)-                    interaction.emit(press)-                    // Once per press, not per repeat: holding backspace buzzes once, then-                    // deletes silently the way Gboard does.-                    currentTick()-                    onRepeat()-                    val job = scope.launch {-                        delay(350)-                        while (true) {-                            onRepeat()-                            delay(45)-                        }-                    }-                    val released = tryAwaitRelease()-                    job.cancel()-                    interaction.emit(-                        if (released) PressInteraction.Release(press) else PressInteraction.Cancel(press),-                    )-                })-            }-            .padding(KeyPadding)-            .clip(KeyShape)-            .background(if (pressed) pressedKeyColor() else specialKeyColor()),-        contentAlignment = Alignment.Center,-    ) {-        CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) { content() }-    }-}--/** Shift key: single tap toggles shift, double tap latches caps-lock. */-@Composable-fun RowScope.ShiftKey(-    height: Dp,-    weight: Float,-    shift: ShiftState,-    onShift: () -> Unit,-) {-    val active = shift != ShiftState.OFF-    val interaction = remember { MutableInteractionSource() }-    val pressed by interaction.collectIsPressedAsState()-    val container = when {-        pressed -> pressedKeyColor()-        active -> MaterialTheme.colorScheme.primaryContainer-        else -> specialKeyColor()-    }-    val content = when {-        pressed -> MaterialTheme.colorScheme.onSurface-        active -> MaterialTheme.colorScheme.onPrimaryContainer-        else -> MaterialTheme.colorScheme.onSurface-    }-    // Captured for the pointerInput block below, which can't read CompositionLocals itself.-    val currentTick by androidx.compose.runtime.rememberUpdatedState(rememberKeyHapticTick())-    Box(-        modifier = Modifier-            .weight(weight)-            .height(height + KeyPadding * 2)-            .pointerInput(Unit) {-                // Fire on press-up immediately (no double-tap wait). Caps-lock is detected-                // from tap timing in the service, so shift responds instantly.-                detectTapGestures(-                    onPress = { offset ->-                        val press = PressInteraction.Press(offset)-                        interaction.emit(press)-                        val released = tryAwaitRelease()-                        interaction.emit(-                            if (released) PressInteraction.Release(press) else PressInteraction.Cancel(press),-                        )-                        if (released) {-                            currentTick()-                            onShift()-                        }-                    },-                )-            }-            .padding(KeyPadding)-            .clip(KeyShape)-            .background(container),-        contentAlignment = Alignment.Center,-    ) {-        IconShift(tint = content)-        if (shift == ShiftState.CAPS_LOCK) {-            Box(-                Modifier-                    .align(Alignment.BottomCenter)-                    .padding(bottom = 7.dp)-                    .size(width = 14.dp, height = 2.dp)-                    .background(content),-            )-        }-    }-}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyButton.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyButton.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyButton.ktindex 6b3b847fbb..d7ac4b8f77 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyButton.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyButton.kt@@ -36,7 +36,7 @@ import androidx.compose.ui.platform.LocalWindowInfo import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp-import com.vayunmathur.keyboard.util.Layouts+import com.vayunmathur.keyboard.domain.Layouts import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import kotlinx.coroutines.withTimeoutOrNull@@ -54,249 +54,3 @@ internal val KeyShape = RoundedCornerShape(11.dp) /** Resting colour for letter/symbol keys (slightly raised above the keyboard surface). */ @Composable fun charKeyColor(): Color = MaterialTheme.colorScheme.surfaceContainerHigh--/** Resting colour for function keys (dimmer, so they read as secondary). */-@Composable-fun specialKeyColor(): Color = MaterialTheme.colorScheme.surfaceContainer--/** The whole-key highlight shown while a key is held down. */-@Composable-fun pressedKeyColor(): Color = MaterialTheme.colorScheme.surfaceBright--/**- * A letter/symbol key: tap commits [label]; holding it opens the [alternates] — the accented- * or related characters that key can also produce — and sliding onto one picks it, the way- * every phone keyboard does accents. An optional [hint] draws a small secondary label beneath- * the main one (the ABC/DEF letters on the phone dial-pad, matching FUTO's phone layout), and- * [cornerHint] draws one in the top-left corner instead (the digit a letter key doubles as- * when the persistent number row is off).- *- * The popup always opens with [label] itself as its leftmost entry, so a long press that- * turns out to have been a mistake can still be finished with the plain letter instead of- * forcing the user to release onto an accent and delete it.- *- * The whole thing is one gesture: press, hold, slide, release. Nothing has to dismiss the- * popup, which matters in an IME — a focusable popup would take focus away from the very- * field being typed into, and a non-focusable one has no way to learn about a tap outside it.- */-@Composable-fun RowScope.CharKey(-    label: String,-    height: Dp,-    weight: Float = 1f,-    hint: String? = null,-    cornerHint: String? = null,-    alternates: String = "",-    onClick: () -> Unit,-    onAlternate: ((String) -> Unit)? = null,-) {-    val interaction = remember { MutableInteractionSource() }-    val pressed by interaction.collectIsPressedAsState()-    // -1 while the popup is closed, otherwise the alternate under the finger.-    var selected by remember { mutableIntStateOf(-1) }-    // Where the key sits, recorded on layout. Deliberately *not* snapshot state: writing-    // state from onGloballyPositioned that composition then reads schedules another-    // recomposition and another layout pass, and with every key on the keyboard doing it-    // that doubles the cost of every relayout. Nothing needs these until a long press has-    // opened the popup, by which point the key has long since been positioned.-    val bounds = remember { KeyBounds() }--    val density = LocalDensity.current-    val screenWidth = LocalWindowInfo.current.containerSize.width.toFloat()--    // What the popup actually offers: the key's own character first, then its alternates.-    // Each entry has to be one character for the index maths below to hold, so the handful-    // of layouts whose comma or period is a multi-character string keep the bare list.-    val options = remember(label, alternates) {-        when {-            alternates.isEmpty() -> ""-            label.length == 1 -> label + alternates-            else -> alternates-        }-    }--    // Every entry gets its full width unless the row would run off the screen, in which case-    // they share what there is. Clamping the row's position alone is not enough: a long list-    // on a narrow phone would put the last entries past the edge, where no finger can reach.-    val itemWidth = remember(options, screenWidth, density) {-        val full = with(density) { AlternateWidth.toPx() }-        if (options.isEmpty()) full else minOf(full, screenWidth / options.length)-    }-    // Key tick at each commit site below — the gesture runs in pointerInput where-    // LocalHapticFeedback can't be read, so it comes through this captured lambda.-    val tick = rememberKeyHapticTick()-    val currentTick by rememberUpdatedState(tick)--    // The gesture below reads all of these through snapshots rather than capturing them, so it-    // never has to be restarted to pick up a new value. See the note on `pointerInput(Unit)`.-    val currentOnClick by rememberUpdatedState(onClick)-    val currentOnAlternate by rememberUpdatedState(onAlternate)-    val currentOptions by rememberUpdatedState(options)-    val currentItemWidth by rememberUpdatedState(itemWidth)-    val currentScreenWidth by rememberUpdatedState(screenWidth)--    Box(-        modifier = Modifier-            .weight(weight)-            // The whole weighted cell — including the KeyPadding gap — takes the touch, so-            // there are no dead strips between keys. The gap is reinstated as padding further-            // down, but only for the visual (clip + background), never for hit-testing.-            .height(height + KeyPadding * 2)-            .onGloballyPositioned {-                bounds.left = it.positionInWindow().x-                bounds.width = it.size.width.toFloat()-            }-            // Written out rather than assembled from detectTapGestures because tap and-            // long-press are one continuous gesture here: the long press opens the popup-            // and the *same* touch goes on to choose from it.-            //-            // Keyed on Unit, deliberately. Keying it on the callbacks instead restarts the-            // gesture whenever a recomposition reallocates them, and `ImeActions` is an-            // interface so Compose treats it as unstable and reallocates them every time.-            // A restart cancels this coroutine, and if that lands between the down and the-            // up — a suggestion arriving, auto-capitalise flipping shift, a settings flow-            // emitting, all of which happen mid-keypress — the Press interaction is never-            // released and the key stays lit with its preview stuck above it until it-            // leaves composition (i.e. until the user switches to another page).-            //-            // One gesture per awaitEachGesture iteration, deliberately. The previous code-            // waited out the long-press timeout and then started a *second* wait for the-            // lift; an up landing in between left the second wait holding a stale-            // still-pressed snapshot, so it hung until the next touch on the same key —-            // the stuck popup — and that next touch was then consumed as the old-            // gesture's release position, committing a phantom variant. A tap whose up-            // arrived as a cancellation (second thumb down mid-tap) also read as a-            // timeout and opened the menu. Bounding each down→up to one iteration-            // removes all three.-            .pointerInput(Unit) {-                awaitEachGesture {-                    val down = awaitFirstDown(requireUnconsumed = false)-                    val press = PressInteraction.Press(down.position)-                    try {-                        // tryEmit, not emit: awaitEachGesture's block is a restricted-                        // suspend scope, so member suspend calls on other objects-                        // (like emit) do not compile here.-                        interaction.tryEmit(press)-                        val timeout = viewConfiguration.longPressTimeoutMillis-                        val start = SystemClock.uptimeMillis()-                        var up: PointerInputChange? = null-                        var lastX = down.position.x-                        while (up == null && SystemClock.uptimeMillis() - start < timeout) {-                            val remaining = timeout - (SystemClock.uptimeMillis() - start)-                            val event = withTimeoutOrNull(remaining.coerceAtLeast(0L)) {-                                awaitPointerEvent()-                            } ?: break-                            val change = event.changes.firstOrNull { it.id == down.id } ?: continue-                            lastX = change.position.x-                            if (!change.pressed) up = change-                        }-                        if (up != null) {-                            if (up.position.isInside(size)) {-                                currentTick()-                                currentOnClick()-                            }-                            return@awaitEachGesture-                        }-                        val opts = currentOptions-                        val onAlt = currentOnAlternate-                        if (opts.isEmpty() || onAlt == null) {-                            // A hold with nothing to offer still types the key; the old-                            // code waited for the lift and then committed nothing.-                            currentTick()-                            currentOnClick()-                            return@awaitEachGesture-                        }-                        val offset = alternatesOffset(bounds, currentItemWidth, opts.length, currentScreenWidth)-                        var picked = indexAt(lastX, offset, currentItemWidth, opts.length)-                        selected = picked-                        while (true) {-                            val event = awaitPointerEvent()-                            val change = event.changes.firstOrNull { it.id == down.id }-                            if (change == null) {-                                // Only other pointers speaking. A fresh down here means-                                // our own up was lost in the timeout race; abandon rather-                                // than hang on a gesture that is already over.-                                if (event.changes.any { it.pressed && !it.previousPressed }) {-                                    return@awaitEachGesture-                                }-                                continue-                            }-                            if (!change.pressed) {-                                currentTick()-                                onAlt(opts[picked].toString())-                                break-                            }-                            picked = indexAt(change.position.x, offset, currentItemWidth, opts.length)-                            selected = picked-                        }-                    } finally {-                        // tryEmit, not emit: this also has to run on the cancellation path,-                        // where a suspending emit would itself be cancelled and leave the-                        // key stuck.-                        selected = -1-                        interaction.tryEmit(PressInteraction.Release(press))-                    }-                }-            }-            .padding(KeyPadding)-            .clip(KeyShape)-            .background(if (pressed) pressedKeyColor() else charKeyColor()),-        contentAlignment = Alignment.Center,-    ) {-        if (hint != null) {-            Column(horizontalAlignment = Alignment.CenterHorizontally) {-                Text(text = label, color = MaterialTheme.colorScheme.onSurface, fontSize = 18.sp)-                Text(text = hint, color = MaterialTheme.colorScheme.onSurfaceVariant, fontSize = 9.sp)-            }-        } else {-            Text(text = label, color = MaterialTheme.colorScheme.onSurface, fontSize = 20.sp)-        }-        if (cornerHint != null) {-            Text(-                text = cornerHint,-                color = MaterialTheme.colorScheme.onSurfaceVariant,-                fontSize = 10.sp,-                modifier = Modifier-                    .align(Alignment.TopStart)-                    .padding(top = 2.dp, start = 6.dp),-            )-        }-        // What a long press gets you, previewed in the corner so the alternates are-        // discoverable instead of folklore. Accented forms of the letter itself are not-        // worth the clutter — every vowel would wear one and it tells you nothing you-        // couldn't guess — so those fall back to a plain dot.-        val altHint = remember(alternates, label, cornerHint) {-            Layouts.alternatePreview(alternates, label, cornerHint)-        }-        when {-            altHint != null -> Text(-                text = altHint,-                color = MaterialTheme.colorScheme.onSurfaceVariant,-                fontSize = 10.sp,-                modifier = Modifier-                    .align(Alignment.BottomEnd)-                    .padding(bottom = 2.dp, end = 5.dp),-            )-            alternates.isNotEmpty() -> Box(-                Modifier-                    .align(Alignment.BottomEnd)-                    .padding(bottom = 5.dp, end = 5.dp)-                    .size(3.dp)-                    .clip(CircleShape)-                    .background(MaterialTheme.colorScheme.onSurfaceVariant),-            )-        }-        when {-            selected >= 0 -> AlternatesPopup(-                options = options,-                selected = selected,-                itemWidth = with(density) { itemWidth.toDp() },-                offsetX = alternatesOffset(bounds, itemWidth, options.length, screenWidth).toInt(),-            )-            // FUTO/AOSP-style preview: while held, balloon the character above the key so-            // the finger doesn't hide it. clippingEnabled=false lets it float above the-            // top row (outside the keyboard bounds).-            pressed -> KeyPreview(label)-        }-    }-}
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 939c648ddd..71eb0fb31f 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardBottomRow.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardBottomRow.kt@@ -9,11 +9,11 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.sp import com.vayunmathur.keyboard.R-import com.vayunmathur.keyboard.ime.EnterAction-import com.vayunmathur.keyboard.ime.ImeActions-import com.vayunmathur.keyboard.ime.KeyboardState-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.Layouts+import com.vayunmathur.keyboard.platform.ime.EnterAction+import com.vayunmathur.keyboard.platform.ime.ImeActions+import com.vayunmathur.keyboard.platform.ime.KeyboardState+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.domain.Layouts import com.vayunmathur.library.ui.IconArrowForward import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.IconEmoji
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 1f2117d9e8..81d447431b 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardLetters.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardLetters.kt@@ -7,11 +7,11 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.Dp-import com.vayunmathur.keyboard.ime.ImeActions-import com.vayunmathur.keyboard.ime.KeyboardState-import com.vayunmathur.keyboard.util.KeyboardLayout-import com.vayunmathur.keyboard.util.Layouts-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.platform.ime.ImeActions+import com.vayunmathur.keyboard.platform.ime.KeyboardState+import com.vayunmathur.keyboard.domain.KeyboardLayout+import com.vayunmathur.keyboard.domain.Layouts+import com.vayunmathur.keyboard.domain.ShiftState import com.vayunmathur.library.ui.IconBackspace  /**@@ -43,13 +43,13 @@ internal fun LettersPage(state: KeyboardState, actions: ImeActions, keyHeight: D     LetterRows(state, layout, actions, keyHeight, topRowDigits)     // Email/URL fields surface @ or / where the comma usually sits.     val commaChar = when (state.textVariation) {-        com.vayunmathur.keyboard.ime.TextVariation.EMAIL -> "@"-        com.vayunmathur.keyboard.ime.TextVariation.URL -> "/"+        com.vayunmathur.keyboard.platform.ime.TextVariation.EMAIL -> "@"+        com.vayunmathur.keyboard.platform.ime.TextVariation.URL -> "/"         else -> layout.comma     }     BottomRow(         state, actions, keyHeight,-        leftLabel = "?123", leftTarget = com.vayunmathur.keyboard.util.KeyboardPage.SYMBOLS,+        leftLabel = "?123", leftTarget = com.vayunmathur.keyboard.domain.KeyboardPage.SYMBOLS,         commaChar = commaChar, periodChar = layout.period,     ) }
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 4559e12929..8826f71237 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt@@ -23,10 +23,10 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp-import com.vayunmathur.keyboard.ime.ImeActions-import com.vayunmathur.keyboard.ime.KeyboardState-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.Layouts+import com.vayunmathur.keyboard.platform.ime.ImeActions+import com.vayunmathur.keyboard.platform.ime.KeyboardState+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.domain.Layouts import com.vayunmathur.library.ui.IconPaste import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Surface
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 3727fbd242..23751a674e 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardSymbolPages.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardSymbolPages.kt@@ -9,11 +9,11 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.Dp 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.keyboard.platform.ime.ImeActions+import com.vayunmathur.keyboard.platform.ime.KeyboardState+import com.vayunmathur.keyboard.platform.ime.NumericMode+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.domain.Layouts import com.vayunmathur.library.ui.IconBackspace import com.vayunmathur.library.ui.IconSpaceBar import com.vayunmathur.library.ui.Text
keyboard/src/main/java/com/vayunmathur/keyboard/ui/PressedKeyColor.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/PressedKeyColor.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/PressedKeyColor.ktnew file mode 100644index 0000000000..767b7114a3--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/PressedKeyColor.kt@@ -0,0 +1,9 @@+package com.vayunmathur.keyboard.ui++import androidx.compose.runtime.Composable+import androidx.compose.ui.graphics.Color+import com.vayunmathur.library.ui.MaterialTheme++/** The whole-key highlight shown while a key is held down. */+@Composable+fun pressedKeyColor(): Color = MaterialTheme.colorScheme.surfaceBright
keyboard/src/main/java/com/vayunmathur/keyboard/ui/RepeatKey.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/RepeatKey.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/RepeatKey.ktnew file mode 100644index 0000000000..d1953325e2--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/RepeatKey.kt@@ -0,0 +1,84 @@+@file:OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)++package com.vayunmathur.keyboard.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.combinedClickable+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.foundation.interaction.MutableInteractionSource+import androidx.compose.foundation.interaction.PressInteraction+import androidx.compose.foundation.interaction.collectIsPressedAsState+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.keyboard.domain.ShiftState+import com.vayunmathur.library.ui.IconShift+import com.vayunmathur.library.ui.LocalContentColor+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import kotlinx.coroutines.delay+import kotlinx.coroutines.launch++/** Backspace with press-and-hold repeat delete. */+@Composable+fun RowScope.RepeatKey(+    height: Dp,+    weight: Float,+    onRepeat: () -> Unit,+    content: @Composable () -> Unit,+) {+    val interaction = remember { MutableInteractionSource() }+    val pressed by interaction.collectIsPressedAsState()+    val scope = androidx.compose.runtime.rememberCoroutineScope()+    // Captured for the pointerInput block below, which can't read CompositionLocals itself.+    val currentTick by androidx.compose.runtime.rememberUpdatedState(rememberKeyHapticTick())+    Box(+        modifier = Modifier+            .weight(weight)+            .height(height + KeyPadding * 2)+            .pointerInput(Unit) {+                detectTapGestures(onPress = { offset ->+                    val press = PressInteraction.Press(offset)+                    interaction.emit(press)+                    // Once per press, not per repeat: holding backspace buzzes once, then+                    // deletes silently the way Gboard does.+                    currentTick()+                    onRepeat()+                    val job = scope.launch {+                        delay(350)+                        while (true) {+                            onRepeat()+                            delay(45)+                        }+                    }+                    val released = tryAwaitRelease()+                    job.cancel()+                    interaction.emit(+                        if (released) PressInteraction.Release(press) else PressInteraction.Cancel(press),+                    )+                })+            }+            .padding(KeyPadding)+            .clip(KeyShape)+            .background(if (pressed) pressedKeyColor() else specialKeyColor()),+        contentAlignment = Alignment.Center,+    ) {+        CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) { content() }+    }+}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/SetupScreen.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SetupScreen.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SetupScreen.ktindex 07110dbf27..133bd000cf 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SetupScreen.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SetupScreen.kt@@ -26,9 +26,9 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.compose.LocalLifecycleOwner-import com.vayunmathur.keyboard.util.KeyboardLayouts-import com.vayunmathur.keyboard.util.KeyboardSettings-import com.vayunmathur.keyboard.ime.KeyboardService+import com.vayunmathur.keyboard.domain.KeyboardLayouts+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.platform.ime.KeyboardService import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.SettingsRow import com.vayunmathur.library.ui.SettingsSwitchRow
keyboard/src/main/java/com/vayunmathur/keyboard/ui/ShiftKey.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ShiftKey.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ShiftKey.ktnew file mode 100644index 0000000000..a683eb4066--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/ShiftKey.kt@@ -0,0 +1,99 @@+@file:OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)++package com.vayunmathur.keyboard.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.combinedClickable+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.foundation.interaction.MutableInteractionSource+import androidx.compose.foundation.interaction.PressInteraction+import androidx.compose.foundation.interaction.collectIsPressedAsState+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.keyboard.domain.ShiftState+import com.vayunmathur.library.ui.IconShift+import com.vayunmathur.library.ui.LocalContentColor+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import kotlinx.coroutines.delay+import kotlinx.coroutines.launch++/** Shift key: single tap toggles shift, double tap latches caps-lock. */+@Composable+fun RowScope.ShiftKey(+    height: Dp,+    weight: Float,+    shift: ShiftState,+    onShift: () -> Unit,+) {+    val active = shift != ShiftState.OFF+    val interaction = remember { MutableInteractionSource() }+    val pressed by interaction.collectIsPressedAsState()+    val container = when {+        pressed -> pressedKeyColor()+        active -> MaterialTheme.colorScheme.primaryContainer+        else -> specialKeyColor()+    }+    val content = when {+        pressed -> MaterialTheme.colorScheme.onSurface+        active -> MaterialTheme.colorScheme.onPrimaryContainer+        else -> MaterialTheme.colorScheme.onSurface+    }+    // Captured for the pointerInput block below, which can't read CompositionLocals itself.+    val currentTick by androidx.compose.runtime.rememberUpdatedState(rememberKeyHapticTick())+    Box(+        modifier = Modifier+            .weight(weight)+            .height(height + KeyPadding * 2)+            .pointerInput(Unit) {+                // Fire on press-up immediately (no double-tap wait). Caps-lock is detected+                // from tap timing in the service, so shift responds instantly.+                detectTapGestures(+                    onPress = { offset ->+                        val press = PressInteraction.Press(offset)+                        interaction.emit(press)+                        val released = tryAwaitRelease()+                        interaction.emit(+                            if (released) PressInteraction.Release(press) else PressInteraction.Cancel(press),+                        )+                        if (released) {+                            currentTick()+                            onShift()+                        }+                    },+                )+            }+            .padding(KeyPadding)+            .clip(KeyShape)+            .background(container),+        contentAlignment = Alignment.Center,+    ) {+        IconShift(tint = content)+        if (shift == ShiftState.CAPS_LOCK) {+            Box(+                Modifier+                    .align(Alignment.BottomCenter)+                    .padding(bottom = 7.dp)+                    .size(width = 14.dp, height = 2.dp)+                    .background(content),+            )+        }+    }+}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpaceKey.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpaceKey.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpaceKey.ktnew file mode 100644index 0000000000..74cc379ec5--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpaceKey.kt@@ -0,0 +1,77 @@+@file:OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)++package com.vayunmathur.keyboard.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.combinedClickable+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.foundation.interaction.MutableInteractionSource+import androidx.compose.foundation.interaction.PressInteraction+import androidx.compose.foundation.interaction.collectIsPressedAsState+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.keyboard.domain.ShiftState+import com.vayunmathur.library.ui.IconShift+import com.vayunmathur.library.ui.LocalContentColor+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import kotlinx.coroutines.delay+import kotlinx.coroutines.launch++/**+ * Space bar: tap inserts a space. [label] names the active layout, which is how the user+ * can tell at a glance which language they are typing.+ */+@Composable+fun RowScope.SpaceKey(+    height: Dp,+    weight: Float,+    label: String,+    onSpace: () -> Unit,+) {+    val interaction = remember { MutableInteractionSource() }+    val pressed by interaction.collectIsPressedAsState()+    val tick = rememberKeyHapticTick()+    Box(+        modifier = Modifier+            .weight(weight)+            .height(height + KeyPadding * 2)+            .clickable(+                interactionSource = interaction,+                indication = null,+                onClick = {+                    tick()+                    onSpace()+                },+            )+            .padding(KeyPadding)+            .clip(KeyShape)+            .background(if (pressed) pressedKeyColor() else charKeyColor()),+        contentAlignment = Alignment.Center,+    ) {+        Text(+            text = label,+            color = MaterialTheme.colorScheme.onSurfaceVariant,+            fontSize = 14.sp,+            maxLines = 1,+            overflow = TextOverflow.Ellipsis,+        )+    }+}
keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpecialKeyColor.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpecialKeyColor.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpecialKeyColor.ktnew file mode 100644index 0000000000..6baa22eb18--- /dev/null+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SpecialKeyColor.kt@@ -0,0 +1,9 @@+package com.vayunmathur.keyboard.ui++import androidx.compose.runtime.Composable+import androidx.compose.ui.graphics.Color+import com.vayunmathur.library.ui.MaterialTheme++/** Resting colour for function keys (dimmer, so they read as secondary). */+@Composable+fun specialKeyColor(): Color = MaterialTheme.colorScheme.surfaceContainer
keyboard/src/main/java/com/vayunmathur/keyboard/ui/SuggestionStrip.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SuggestionStrip.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SuggestionStrip.ktindex b365746438..bd7f37250a 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SuggestionStrip.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/SuggestionStrip.kt@@ -19,63 +19,6 @@ import androidx.compose.ui.unit.sp import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.VerticalDivider--/**- * The candidate strip for the composed scripts: the characters a pinyin or bopomofo spelling- * could be, scrolling sideways because a syllable like `shi` has dozens of them.- *- * Separate from [SuggestionStrip] because the two are doing different jobs. A word suggestion- * is an offer you can ignore; a Chinese candidate *is* the input — you have not typed a- * character until you pick one — so these are sized to their content and never truncated.- */-@Composable-fun CandidateStrip(-    height: Dp,-    candidates: List<String>,-    onPick: (String) -> Unit,-) {-    val tick = rememberKeyHapticTick()-    LazyRow(-        modifier = Modifier-            .fillMaxWidth()-            .height(height),-        verticalAlignment = Alignment.CenterVertically,-    ) {-        itemsIndexed(candidates) { index, candidate ->-            if (index > 0) {-                VerticalDivider(-                    modifier = Modifier-                        .height(height)-                        .padding(vertical = 8.dp),-                )-            }-            Box(-                modifier = Modifier-                    .fillMaxHeight()-                    .clickable {-                        tick()-                        onPick(candidate)-                    }-                    .padding(horizontal = 14.dp),-                contentAlignment = Alignment.Center,-            ) {-                Text(-                    text = candidate,-                    // The first candidate is what space commits, so it is the one that has-                    // to look chosen rather than merely first in a list.-                    color = if (index == 0) {-                        MaterialTheme.colorScheme.primary-                    } else {-                        MaterialTheme.colorScheme.onSurface-                    },-                    fontSize = 22.sp,-                    maxLines = 1,-                )-            }-        }-    }-}- /**  * The strip above the keys showing up to three candidate words. Tapping one replaces the  * word being typed. Its height is reserved even when empty so the keyboard doesn't jump.
keyboard/src/main/java/com/vayunmathur/keyboard/ui/VoiceStrip.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/VoiceStrip.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/VoiceStrip.ktindex 86d32639d6..8512fd28be 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/VoiceStrip.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/VoiceStrip.kt@@ -19,7 +19,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.keyboard.R-import com.vayunmathur.keyboard.ime.VoiceState+import com.vayunmathur.keyboard.platform.ime.VoiceState import com.vayunmathur.keyboard.platform.VoiceFailure import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.ui.IconMic
keyboard/src/screenshotTest/kotlin/com/vayunmathur/keyboard/ui/MetadataPreviews.kt
diff --git a/keyboard/src/screenshotTest/kotlin/com/vayunmathur/keyboard/ui/MetadataPreviews.kt b/keyboard/src/screenshotTest/kotlin/com/vayunmathur/keyboard/ui/MetadataPreviews.ktindex 70451135d0..f0ef66d767 100644--- a/keyboard/src/screenshotTest/kotlin/com/vayunmathur/keyboard/ui/MetadataPreviews.kt+++ b/keyboard/src/screenshotTest/kotlin/com/vayunmathur/keyboard/ui/MetadataPreviews.kt@@ -8,12 +8,12 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import com.android.tools.screenshot.PreviewTest-import com.vayunmathur.keyboard.ime.EnterAction-import com.vayunmathur.keyboard.ime.ImeActions-import com.vayunmathur.keyboard.ime.KeyboardState-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.KeyboardSettings-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.platform.ime.EnterAction+import com.vayunmathur.keyboard.platform.ime.ImeActions+import com.vayunmathur.keyboard.platform.ime.KeyboardState+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.domain.ShiftState import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.DynamicTheme 
keyboard/src/test/java/com/vayunmathur/keyboard/data/ClipboardTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/ClipboardTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/data/ClipboardTest.ktsimilarity index 99%rename from keyboard/src/test/java/com/vayunmathur/keyboard/util/ClipboardTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/data/ClipboardTest.ktindex 3926d5f74d..9247f17e0f 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/ClipboardTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/data/ClipboardTest.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data  import kotlin.test.Test import kotlin.test.assertEquals
keyboard/src/test/java/com/vayunmathur/keyboard/data/DictionaryTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/DictionaryTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/data/DictionaryTest.ktsimilarity index 99%rename from keyboard/src/test/java/com/vayunmathur/keyboard/util/DictionaryTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/data/DictionaryTest.ktindex e16c9a652d..e27aeab26e 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/DictionaryTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/data/DictionaryTest.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data  import kotlin.test.Test import kotlin.test.assertEquals
keyboard/src/test/java/com/vayunmathur/keyboard/data/EmojiSearchTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/EmojiSearchTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/data/EmojiSearchTest.ktsimilarity index 99%rename from keyboard/src/test/java/com/vayunmathur/keyboard/util/EmojiSearchTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/data/EmojiSearchTest.ktindex 3f028363df..0dc00603e8 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/EmojiSearchTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/data/EmojiSearchTest.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.data  import kotlin.test.Test import kotlin.test.assertEquals
keyboard/src/test/java/com/vayunmathur/keyboard/domain/FieldKindParityTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/FieldKindParityTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/domain/FieldKindParityTest.ktsimilarity index 86%rename from keyboard/src/test/java/com/vayunmathur/keyboard/util/FieldKindParityTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/domain/FieldKindParityTest.ktindex f9c06ac599..e0937ae8c8 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/FieldKindParityTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/domain/FieldKindParityTest.kt@@ -1,7 +1,8 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain+import com.vayunmathur.keyboard.data.KeyboardSettings -import com.vayunmathur.keyboard.ime.NumericMode-import com.vayunmathur.keyboard.ime.TextVariation+import com.vayunmathur.keyboard.platform.ime.NumericMode+import com.vayunmathur.keyboard.platform.ime.TextVariation import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse@@ -11,7 +12,7 @@ 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+ * contract in [com.vayunmathur.keyboard.platform.ime.KeyboardState] must hold for the new  * variants (PERSON_NAME caps, NO_SUGGESTIONS, ASCII fallback).  */ class FieldKindParityTest {@@ -19,7 +20,7 @@ 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()+        val state = com.vayunmathur.keyboard.platform.ime.KeyboardState()         state.forceAscii = true          state.settings = KeyboardSettings(activeLayoutId = "fr_azerty")
keyboard/src/test/java/com/vayunmathur/keyboard/domain/KeyboardLayoutTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/domain/KeyboardLayoutTest.ktsimilarity index 98%rename from keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/domain/KeyboardLayoutTest.ktindex 9e02b086d9..17653263a5 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/domain/KeyboardLayoutTest.kt@@ -1,4 +1,5 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain+import com.vayunmathur.keyboard.data.KeyboardSettings  import kotlin.test.Test import kotlin.test.assertEquals
keyboard/src/test/java/com/vayunmathur/keyboard/domain/PlatformRoboTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/domain/PlatformRoboTest.ktsimilarity index 96%rename from keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/domain/PlatformRoboTest.ktindex a98c5c7282..73a7bedbfb 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/domain/PlatformRoboTest.kt@@ -1,4 +1,10 @@-package com.vayunmathur.keyboard.util+package com.vayunmathur.keyboard.domain+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.ClipboardStore+import com.vayunmathur.keyboard.data.Dictionary+import com.vayunmathur.keyboard.data.EmojiData+import com.vayunmathur.keyboard.data.KeyboardSettings+import com.vayunmathur.keyboard.data.PinyinDictionary  import android.content.ClipData import android.content.Context
keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ComposerTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ComposerTest.ktsimilarity index 98%rename from keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ComposerTest.ktindex 9e294a4489..bd33c01a9c 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ComposerTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ComposerTest.kt@@ -1,13 +1,13 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime -import com.vayunmathur.keyboard.util.PinyinDictionary+import com.vayunmathur.keyboard.data.PinyinDictionary import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull import kotlin.test.assertTrue  /**- * The composition engines, driven the way [com.vayunmathur.keyboard.ime.KeyboardService] drives+ * The composition engines, driven the way [com.vayunmathur.keyboard.platform.ime.KeyboardService] drives  * them: feed keys, apply each [ComposeResult] to a model of the text field, and check what the  * field ends up holding.  *
keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceLifecycleTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceLifecycleTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceLifecycleTest.ktsimilarity index 97%rename from keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceLifecycleTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceLifecycleTest.ktindex 6fa17630b0..109ab978ab 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceLifecycleTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceLifecycleTest.kt@@ -1,11 +1,11 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.os.Looper import android.text.InputType import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodSubtype import androidx.lifecycle.Lifecycle-import com.vayunmathur.keyboard.util.KeyboardLayouts+import com.vayunmathur.keyboard.domain.KeyboardLayouts import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner
keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.ktsimilarity index 96%rename from keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.ktindex 75d69b50d8..27f1376f08 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.kt@@ -1,4 +1,4 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime  import android.os.Bundle import android.text.InputType@@ -11,11 +11,11 @@ import android.view.inputmethod.ExtractedTextRequest import android.view.inputmethod.InputConnection import android.view.inputmethod.InputContentInfo import androidx.test.core.app.ApplicationProvider-import com.vayunmathur.keyboard.util.ClipItem-import com.vayunmathur.keyboard.util.Dictionary-import com.vayunmathur.keyboard.util.KeyboardLayouts-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.Dictionary+import com.vayunmathur.keyboard.domain.KeyboardLayouts+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.domain.ShiftState import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner@@ -239,7 +239,7 @@ class ServiceOpsTest {      @Test     fun `commitEmoji remembers recent and leaves search`() {-        service.kbState.emojiData = com.vayunmathur.keyboard.util.EmojiData.BUILTIN+        service.kbState.emojiData = com.vayunmathur.keyboard.data.EmojiData.BUILTIN         service.startEmojiSearch()         service.commitEmoji("😀")         assertNull(service.kbState.emojiQuery)@@ -259,16 +259,16 @@ class ServiceOpsTest {             // force rebuild             service.syncComposer()         }-        val hangul = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.util.ComposerKind.HANGUL }+        val hangul = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.domain.ComposerKind.HANGUL }         setLayout(hangul.id)         assertTrue(service.composer is HangulComposer)-        val romaji = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.util.ComposerKind.ROMAJI }+        val romaji = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.domain.ComposerKind.ROMAJI }         setLayout(romaji.id)         assertTrue(service.composer is RomajiComposer)-        val kana = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.util.ComposerKind.KANA }+        val kana = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.domain.ComposerKind.KANA }         setLayout(kana.id)         assertTrue(service.composer is KanaKeyComposer)-        val eth = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.util.ComposerKind.ETHIOPIC }+        val eth = KeyboardLayouts.ALL.first { it.composer == com.vayunmathur.keyboard.domain.ComposerKind.ETHIOPIC }         setLayout(eth.id)         assertTrue(service.composer is EthiopicComposer)         setLayout("en_qwerty")@@ -285,7 +285,7 @@ class ServiceOpsTest {     fun `applyComposition commits settled text and updates candidates`() {         val ic = FakeInputConnection()         val han = HanComposer(-            com.vayunmathur.keyboard.util.PinyinDictionary.fromEntries(listOf("ni" to "你尼", "hao" to "好")),+            com.vayunmathur.keyboard.data.PinyinDictionary.fromEntries(listOf("ni" to "你尼", "hao" to "好")),             SpellingScheme.Pinyin,         )         val r1 = han.accept("n")@@ -522,20 +522,20 @@ class ServiceOpsTest {     @Test     fun `pinyin layout loads chinese data and rebuilds composer`() {         val pinyin = KeyboardLayouts.ALL.first {-            it.composer == com.vayunmathur.keyboard.util.ComposerKind.PINYIN_SIMPLIFIED+            it.composer == com.vayunmathur.keyboard.domain.ComposerKind.PINYIN_SIMPLIFIED         }         service.kbState.settings = service.kbState.settings.copy(activeLayoutId = pinyin.id)         service.syncComposer()         assertTrue(service.composer is HanComposer)         // The asset load runs on the service scope (main + IO); wait for it to land.         val deadline = System.currentTimeMillis() + 10_000-        while (service.pinyinSimplified === com.vayunmathur.keyboard.util.PinyinDictionary.EMPTY &&+        while (service.pinyinSimplified === com.vayunmathur.keyboard.data.PinyinDictionary.EMPTY &&             System.currentTimeMillis() < deadline         ) {             ShadowLooper.idleMainLooper()             Thread.sleep(25)         }-        assertTrue(service.pinyinSimplified !== com.vayunmathur.keyboard.util.PinyinDictionary.EMPTY)+        assertTrue(service.pinyinSimplified !== com.vayunmathur.keyboard.data.PinyinDictionary.EMPTY)         assertTrue(service.pinyinSimplified.candidates("ni").isNotEmpty())         assertTrue(service.composer is HanComposer)         service.kbState.settings = service.kbState.settings.copy(activeLayoutId = "en_qwerty")
keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursorTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/TextBeforeCursorTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursorTest.ktsimilarity index 95%rename from keyboard/src/test/java/com/vayunmathur/keyboard/ime/TextBeforeCursorTest.ktrename to keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursorTest.ktindex 1cc744bed0..ac9fe16139 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/TextBeforeCursorTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/TextBeforeCursorTest.kt@@ -1,8 +1,8 @@-package com.vayunmathur.keyboard.ime+package com.vayunmathur.keyboard.platform.ime -import com.vayunmathur.keyboard.util.KeyboardLayouts-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.KeyboardLayouts+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.domain.ShiftState import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse@@ -189,8 +189,8 @@ class KeyboardStateTest {         a.onChar("x"); a.onBackspace(); a.onEnter(); a.onSpace(); a.onShift()         a.setPage(KeyboardPage.EMOJI); a.commitSuggestion("word")         a.startEmojiSearch(); a.endEmojiSearch(); a.commitEmoji("😀")-        a.pasteClip(com.vayunmathur.keyboard.util.ClipItem(id = 1, text = "t"))-        a.deleteClip(com.vayunmathur.keyboard.util.ClipItem(id = 1, text = "t"))+        a.pasteClip(com.vayunmathur.keyboard.data.ClipItem(id = 1, text = "t"))+        a.deleteClip(com.vayunmathur.keyboard.data.ClipItem(id = 1, text = "t"))         a.clearClips(); a.dismissClipSuggestion()         a.onVoiceInput(); a.stopVoiceInput(); a.dismissVoice(); a.openVoiceSettings()     }
keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyComponentsTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyComponentsTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyComponentsTest.ktindex 7ff64c2b90..ae1f91c2ce 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyComponentsTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyComponentsTest.kt@@ -9,7 +9,7 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.unit.dp-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.domain.ShiftState import com.vayunmathur.library.ui.Text import org.junit.Rule import org.junit.runner.RunWith
keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.ktindex c49c16be9f..2a176db59e 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt@@ -7,17 +7,17 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.test.swipeLeft-import com.vayunmathur.keyboard.ime.EnterAction-import com.vayunmathur.keyboard.ime.ImeActions-import com.vayunmathur.keyboard.ime.KeyboardState-import com.vayunmathur.keyboard.ime.NumericMode-import com.vayunmathur.keyboard.ime.TextVariation-import com.vayunmathur.keyboard.ime.VoiceState+import com.vayunmathur.keyboard.platform.ime.EnterAction+import com.vayunmathur.keyboard.platform.ime.ImeActions+import com.vayunmathur.keyboard.platform.ime.KeyboardState+import com.vayunmathur.keyboard.platform.ime.NumericMode+import com.vayunmathur.keyboard.platform.ime.TextVariation+import com.vayunmathur.keyboard.platform.ime.VoiceState import com.vayunmathur.keyboard.platform.VoiceFailure-import com.vayunmathur.keyboard.util.ClipItem-import com.vayunmathur.keyboard.util.EmojiData-import com.vayunmathur.keyboard.util.KeyboardPage-import com.vayunmathur.keyboard.util.ShiftState+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.EmojiData+import com.vayunmathur.keyboard.domain.KeyboardPage+import com.vayunmathur.keyboard.domain.ShiftState import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner@@ -138,7 +138,7 @@ class KeyboardScreenTest {     @Test     fun `four row layout replaces digit row`() {         val actions = RecordingActions()-        val fourRow = com.vayunmathur.keyboard.util.KeyboardLayouts.ALL.firstOrNull { it.rows.size >= 4 }+        val fourRow = com.vayunmathur.keyboard.domain.KeyboardLayouts.ALL.firstOrNull { it.rows.size >= 4 }         if (fourRow != null) {             rule.setContent {                 KeyboardScreen(state { settings = settings.copy(activeLayoutId = fourRow.id) }, actions)@@ -219,7 +219,7 @@ class KeyboardScreenTest {         rule.onNodeWithText("hello").performClick()         assertEquals(listOf("hello"), actions.suggestions) -        val pinyin = com.vayunmathur.keyboard.util.KeyboardLayouts.ALL+        val pinyin = com.vayunmathur.keyboard.domain.KeyboardLayouts.ALL             .first { it.offersCandidates }         rule.runOnIdle {             st.settings = st.settings.copy(activeLayoutId = pinyin.id)
keyboard/src/test/java/com/vayunmathur/keyboard/ui/PagesAndSetupTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/PagesAndSetupTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/PagesAndSetupTest.ktindex 8f6841a191..fc8a5bfaf2 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/PagesAndSetupTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/PagesAndSetupTest.kt@@ -21,10 +21,10 @@ import androidx.compose.ui.unit.IntRect import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp-import com.vayunmathur.keyboard.util.ClipItem-import com.vayunmathur.keyboard.util.EmojiCategory-import com.vayunmathur.keyboard.util.EmojiData-import com.vayunmathur.keyboard.util.EmojiEntry+import com.vayunmathur.keyboard.data.ClipItem+import com.vayunmathur.keyboard.data.EmojiCategory+import com.vayunmathur.keyboard.data.EmojiData+import com.vayunmathur.keyboard.data.EmojiEntry import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner@@ -200,8 +200,8 @@ class PagesAndSetupTest {     @Test     fun `enter action icon renders for every action`() {         val idx = androidx.compose.runtime.mutableIntStateOf(0)-        rule.setContent { EnterActionIcon(com.vayunmathur.keyboard.ime.EnterAction.entries[idx.intValue]) }-        for (i in com.vayunmathur.keyboard.ime.EnterAction.entries.indices) {+        rule.setContent { EnterActionIcon(com.vayunmathur.keyboard.platform.ime.EnterAction.entries[idx.intValue]) }+        for (i in com.vayunmathur.keyboard.platform.ime.EnterAction.entries.indices) {             rule.runOnIdle { idx.intValue = i }             rule.waitForIdle()         }