Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Resizing or toggling the floating keyboard can unexpectedly commit the active composition and change ASCII mode because it reruns keyboard-switch initialization instead of preserving live input state.
4 open issues
What changed in this PR
Adds a floating-card mode to Trime’s keyboard, addressing the landscape floating-keyboard request in #2094.
Changes:
- Enables floating mode by default in landscape, with optional portrait mode and saved geometry.
- Adds dragging, snapping, resizing, collapsing, and docking, with overlay touch bounds and an embedded composer.
- Adds geometry and mode tests, localized labels, and control icons.
| File | Description |
|---|---|
app/src/test/java/com/osfans/trime/ime/keyboard/FloatingKeyboardModeTest.kt |
Tests orientation and preference-based mode selection. |
app/src/test/java/com/osfans/trime/ime/keyboard/FloatingKeyboardGeometryTest.kt |
Tests sizing, positioning, insets, and snapping. |
app/src/main/res/values/strings.xml |
Adds English floating-control labels. |
app/src/main/res/values/input_view_ids.xml |
Adds handle and composer-host IDs. |
app/src/main/res/values-zh-rTW/strings.xml |
Adds Traditional Chinese control labels. |
app/src/main/res/values-zh-rCN/strings.xml |
Adds Simplified Chinese control labels. |
app/src/main/res/drawable/ic_baseline_picture_in_picture_alt_24.xml |
Adds the floating-mode icon. |
app/src/main/res/drawable/ic_baseline_open_in_full_24.xml |
Adds the resize icon. |
app/src/main/res/drawable/ic_baseline_dock_to_bottom_24.xml |
Adds the docking icon. |
app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardWindow.kt |
Passes floating geometry into keyboard construction and adjusts layout selection. |
app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardPrefs.kt |
Uses portrait width for wide-screen detection. |
app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.kt |
Scales floating key height and disables split layouts. |
app/src/main/java/com/osfans/trime/ime/keyboard/FloatingKeyboardPrefs.kt |
Stores floating mode, scale, position, and collapse state. |
app/src/main/java/com/osfans/trime/ime/keyboard/FloatingKeyboardMode.kt |
Defines orientation-driven floating-mode selection. |
app/src/main/java/com/osfans/trime/ime/keyboard/FloatingKeyboardGeometry.kt |
Provides card sizing and positioning helpers. |
app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt |
Handles mode requests and reports overlay insets. |
app/src/main/java/com/osfans/trime/ime/core/InputView.kt |
Implements floating-card layout, controls, and gestures. |
app/src/main/java/com/osfans/trime/ime/composition/PreeditDelegate.kt |
Repositions the composer’s touch receiver. |
app/src/main/java/com/osfans/trime/ime/bar/ui/AlwaysUi.kt |
Adds and styles the floating/docking toggle. |
app/src/main/java/com/osfans/trime/ime/bar/InputBarDelegate.kt |
Connects the toggle to mode changes. |
app/src/main/java/com/osfans/trime/data/prefs/AppPrefs.kt |
Registers floating preferences and includes them in resets. |
Review effort: Balanced
| if (width != keyboardView.layoutParams.width) { | ||
| keyboardWindow.floatingScalePercent = | ||
| FloatingKeyboardGeometry.percentFor(baseWidth, width) | ||
| keyboardView.updateLayoutParams { this.width = width } |
| floatingToggleButton.apply { | ||
| contentDescription = context.getString(R.string.floating_keyboard_float) | ||
| setOnClickListener { | ||
| service.requestFloatingMode(!service.isFloatingKeyboardActive) |
| } | ||
|
|
||
| MotionEvent.ACTION_MOVE -> { | ||
| keyboardView.translationX = |
| // The layout depends on the floating flag (a card is never split), and | ||
| // the card width differs from the docked width. Rebuild the keyboards | ||
| // after the new size has been laid out instead of using the old width. | ||
| scheduleKeyboardRefresh() |
Store the card's portrait mode, scale, collapse state, and per-orientation position. Register the provider through AppPrefs so change listeners work, and include it in the device-encrypted sync list.
Provide pure helpers for the card width, key height, default position, translation clamping, edge snapping, and system inset merging. Cover the calculations with unit tests so the drag and resize rules stay stable.
Float automatically in landscape, allow a session-only dock override there, and use the persisted preference in portrait. Test the mode matrix so a docked landscape card does not change the portrait default.
Use the shorter screen side for the wide-screen check so a phone in landscape does not select tablet keyboard sizes. Add a helper that keeps the floating card on portrait dimensions even when the window is wide.
Use the portrait layout and padding in the card, scale the key height with the card width, and never split the floating keyboard. Rebuild cached layouts when the card width or mode changes.
Add labels for dragging, collapsing, expanding, floating, docking, and resizing the card. Add the picture-in-picture, dock-to-bottom, and resize icons, plus the drag handle id used by the card layout.
Lay the keyboard out as a rounded card that restores its scale and position per orientation. Float in landscape, keep portrait docked by default, and expose a request to switch modes.
Report no covered content area while the card floats and restrict the touchable region to the card. Keep the app content from panning when the card is moved.
Host the preedit below the card's drag strip so the drag control no longer splits the composer text from the candidate bar. Move the preedit between the card and the root view on mode changes, and drop the manual translation.
Move the card with its drag strip, snap it to the edges or center, and resize it with the corner grip. Persist the chosen scale and position per orientation so each orientation keeps its own layout.
Keep one floating/docked toggle in the always-visible bar. Switch its icon and description with the mode and request the opposite mode when tapped, so the input bar is never split by a second control.
a0a3f31 to
16e5d70
Compare
补充审查反馈(在 Copilot 的 4 条意见之上)整体实现质量不错: 阻断 1:几何重建会提交正在输入的 composition 并重置 ascii_mode
if (currentMode != targetMode) {
service.postRimeJob {
commitComposition()
setRuntimeOption("ascii_mode", targetMode)
}
}拖动缩放手柄、切换悬浮/停靠、 阻断 2:resize 的每次 ACTION_MOVE 都触发一次完整键盘重建
建议一并处理
小问题
验证建议现有 508 行单测都是纯函数级,建议补:几何重建不触发 Copilot 的 4 条意见我逐条复核过,均成立;阻断 1/2 是对其第 1 条的调用链补充与放大,其余为额外发现。以上供参考,感谢贡献这个功能。 |
|
This is a good feature but also a large amount of changes, I think it may take longer time to get a closer look. |


Pull request
Issue tracker
Fixes will automatically close the related issues
Part of #2094
Feature
Describe features of this pull request
Add floating feature support, this patch is verified with daily usage.
Assisted by LLM.
Code of conduct
Code style
make style-lintBuild pass
make debugManually test
Code Review
Daily build
Login and download artifact at https://github.com/osfans/trime/actions
Additional Info