Appearance
命名规范
本文档定义 v4 版本三层库架构下的统一命名规范,确保通过类名即可识别其所在模块和职能。所有设计文档和代码实现必须遵循本规范。
1 三层模块命名
| 模块 | 命名规则 | 示例 |
|---|---|---|
:ime-engine | 公开 class 以 Ime 为前缀 | ImeEngine, ImeConfig, ImeOutput, ImeState, ImeIntent, ImeOutputBridge |
:ime-ui | 不使用 Ime 前缀,贴近 UI 业务命名 | KeyboardPanel, EditTextBridge, GestureFeedbackPanel, CandidateListPanel |
:app | 不使用 Ime 前缀,贴近应用业务命名 | IMEService, ConfigDataStore, InputConnectionBridge |
1.1 engine 模块
所有对外的 class(包括 sealed class、data class、enum、interface)均以 Ime 作为前缀,作为引擎库的命名空间标识。内部实现类(如 KeyboardStateMachine、InputListOperator、FeatureRegistry)不强制使用 Ime 前缀,因为它们不对外暴露。
1.2 ui 模块
组件命名贴近其 UI 职能,使用业务语义化的名称:
| 后缀 | 含义 | 示例 |
|---|---|---|
Panel | 容器 / 组合器(组合多个子组件) | KeyboardPanel, GestureInputPanel, CandidateListPanel, InputListPanel, KeyGridPanel, GestureFeedbackPanel |
Screen | 全屏界面(UI 库或应用层页面) | KeyboardScreen, SettingsScreen, MainScreen, ExerciseScreen |
注意:
KeyboardPanel和KeyboardScreen均为完整的输入法组件,包含候选栏、输入栏、工具栏和键盘区域,只是形式和交互不同(叠加 vs 全屏分离)。
主题系统使用 Keyboard 前缀(如 KeyboardColors、KeyboardTheme),与 Material3 的 MaterialTheme 等系统命名区分。
1.3 app 模块
Android 系统服务类沿用平台命名惯例(如 IMEService),配置类使用职能名称(如 ConfigDataStore),桥接类使用目标对象 + Bridge 后缀命名(如 InputConnectionBridge),实现 ImeOutputBridge 接口。页面以 Screen 为后缀(如 SettingsScreen、MainScreen)。
2 KeyGridPanel 子类命名
KeyGridPanel 的子类以 KeyGridPanel 为后缀,前缀表达键盘变体类型:
| 类名 | 说明 |
|---|---|
StandardKeyGridPanel | 标准键盘(拼音、拉丁、数字、符号、编辑器、数学) |
EmojiKeyGridPanel | Emoji 面板 |
CandidateKeyGridPanel | 候选键盘 |
CommitOptionKeyGridPanel | 提交选项键盘 |
3 引擎 API 命名
| 类型 | 命名 | 说明 |
|---|---|---|
| Intent | ImeIntent.PerformEdit(EditorAction) | 不是 ImeIntent.EditorAction(EditorActionType) |
| Output | ImeOutput.PerformEdit(EditorAction) | PerformEdit 与 Output 对称使用同一 EditorAction 枚举 |
| 手势输入 | ImeEngine.handleGesture(InputGesture) | 不是 onKeyPress / handleKeyPress |
| 意图处理 | ImeEngine.handleIntent(ImeIntent) | 直接发送意图 |
4 包命名
- 格式:
org.crazydan.studio.app.ime.kuaizi.<module>.<submodule> :app模块无子模块名,直接使用顶级包名- 全小写,不使用下划线
- 模块划分与功能对应,不按技术层划分
org.crazydan.studio.app.ime.kuaizi.engine.core
org.crazydan.studio.app.ime.kuaizi.engine.domain
org.crazydan.studio.app.ime.kuaizi.engine.dict
org.crazydan.studio.app.ime.kuaizi.ui.theme
org.crazydan.studio.app.ime.kuaizi.ui.keyboard
org.crazydan.studio.app.ime.kuaizi.ui.integration
org.crazydan.studio.app.ime.kuaizi ← :app 模块(无子模块名)5 禁止使用的名称
以下名称已废弃,不得在设计文档和代码中使用:
KeyPanel(使用KeyGridPanel)StandardKeyboard/StandardKeyPanel(使用StandardKeyGridPanel)InputPanel(使用GestureInputPanel)KeyboardView(使用KeyboardPanel)CandidateBar/InputBar(使用CandidateListPanel/InputListPanel)EditorActionType(使用EditorAction)ImeEngineConfig(使用ImeConfig)onKeyPress(使用handleGesture/handleIntent)disable*/enable*前缀配置字段(使用*Enabled后缀)EditorField(使用EditTextBridge)EditorHost(使用 Bridge 接入示例,见 030-三层模块划分)InputHostView(使用 Bridge 接入示例,见 030-三层模块划分)ImeEditText/ImeSupportEditText(使用EditTextBridge)EditorState(撤销状态由 BaseImeOutputBridge 内部管理)AppLog/AppLogger(使用ImeLog/ImeLogger,详见 080-日志系统)LogExportActivity(使用LogExportScreen)CandidateState(使用CandidateList)FavoritesState(使用FavoriteList)CandidatePanel(使用CandidateListPanel)FavoritesPanel(使用FavoriteListPanel)CandidatePager(使用CandidateListPager)ImeOutput.EditAction(使用ImeOutput.PerformEdit)InputScreen(使用KeyboardPanel叠加模式 /KeyboardScreen全屏模式,两者均为完整输入法组件)ThreeLayerKeyboardArea(使用KeyboardPanel,其内部已包含三层面板叠加区域)KeyboardArea(使用KeyboardPanel,其内部已包含三层面板叠加区域)