Compare commits

..

1 Commits

Author SHA1 Message Date
pengxiaolong
e381b45a0b 埋点 2026-01-13 18:26:24 +08:00
484 changed files with 13092 additions and 114424 deletions

View File

@@ -1,13 +0,0 @@
{
"permissions": {
"allow": [
"Bash(dir:*)",
"Bash(powershell:*)",
"Bash(find /d/Test/MyApplication/app/src/main/assets -name \"vocab.txt\" -exec wc -l {} ;)",
"WebSearch",
"Bash(grep:*)",
"Bash(find:*)",
"Bash(ls:*)"
]
}
}

BIN
.gitignore vendored

Binary file not shown.

View File

@@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-01-19T05:47:34.214081500Z">
<DropdownSelection timestamp="2026-01-12T07:53:30.395553200Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=3B15A70100N00000" />
<DeviceId pluginId="PhysicalDevice" identifier="serial=7PRDU19930003674" />
</handle>
</Target>
</DropdownSelection>

128
CLAUDE.md
View File

@@ -1,128 +0,0 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## 项目概述
Android 输入法应用IME包含自定义键盘和社交圈Circle功能模块。Kotlin 开发Jetpack Compose + XML 混合 UI。
- **包名**: `com.boshan.key.of.love`
- **命名空间**: `com.example.myapplication`
- **编译配置**: compileSdk 34, minSdk 21, targetSdk 34
## 构建命令
```bash
gradlew assembleDebug # 构建 Debug APK
gradlew assembleRelease # 构建 Release APK
gradlew installDebug # 安装到设备
gradlew clean # 清理
gradlew lint # Lint 检查
```
## 核心架构
### 应用入口流程
```
SplashActivity → GuideActivity/ImeGuideActivity → OnboardingActivity → MainActivity
```
### 键盘模块 (keyboard/)
**继承体系**
```
BaseKeyboard (抽象基类,提供震动、主题应用、递归设置文字颜色)
├── MainKeyboard (主键盘,拼音/英文输入)
├── AiKeyboard (AI 辅助键盘)
├── EmojiKeyboard (表情/颜文字键盘)
├── NumberKeyboard (数字键盘)
└── SymbolKeyboard (符号键盘)
```
**核心服务 `MyInputMethodService.kt`**
- 键盘懒加载 + 缓存机制(`ensureMainKeyboard()` 等)
- 智能联想流程:`commitKey()``updateCompletionsAndRender()` → 后台计算候选词 → `showCompletionSuggestions()`
- 特殊交互Emoji 按 Unicode 代码点删除、长按连删 + 上滑清空、回填功能
### 语言模型 (data/)
**N-gram 模型架构**`LanguageModel.kt` + `LanguageModelLoader.kt`
- 词表:`assets/vocab.txt`(每行一词,行号=词ID按频率降序
- Unigram`assets/uni_logp.bin`u16 分数数组0-1000越高越常用
- Bigram`assets/bi_rowptr.bin`[u32 offset, u16 length] + `bi_data.bin`[u32 next_id, u16 score]
- Trigram`assets/tri_ctx.bin`[u32 ctx1, u32 ctx2] + `tri_rowptr.bin` + `tri_data.bin`
**预测算法**3-gram → 2-gram → 1-gram 回退机制,结合用户点击学习排序
**Trie 优化**`Trie.kt`
- 每个节点记录 `maxFreq`(子树最高词频)
- 优先级队列遍历快速获取 top-K
- 用户点击权重 1000远超静态词频
### 网络层 (network/)
**双客户端架构**
- `RetrofitClient.kt`:常规 HTTP30s 超时)
- `NetworkClient.kt`SSE 流式响应(无超时,用于 AI 聊天)
**请求签名机制**`HttpInterceptors.kt`
1. 生成 timestamp + nonceUUID 前 16 位)
2. 合并参数appId + timestamp + nonce + query + body 扁平化)
3. 按 key 字典序拼接HMAC-SHA256 签名
4. 添加 HeaderX-App-Id, X-Timestamp, X-Nonce, X-Sign
**SSE 解析**`NetworkClient.kt`):支持 JSON 和纯文本 chunk自动识别 `[done]` 结束标记
**Token 过期处理**:响应拦截器检测 code=40102/40103 → 清除本地 token → `AuthEventBus.emit(TokenExpired)`
### 社交圈 Repository (ui/circle/)
**缓存策略**`CircleChatRepository.kt`
- 自适应 LRU 缓存大小(根据设备内存 32-120 页)
- 预加载当前页前后 N 页
- 防重加载机制(`inFlight``pageInFlight` HashSet
### 主题系统 (theme/)
- `ThemeManager.kt`:观察者模式通知主题变更
- 各键盘实现 `applyKeyBackgroundsForTheme()` 应用主题
- `ThemeDownloadWorker.kt`WorkManager 后台下载
### UI 模块 (ui/)
| 模块 | 说明 |
|------|------|
| `circle/` | 社交圈AI 角色聊天、评论系统 |
| `shop/` | 主题商店 |
| `mine/` | 个人中心 |
| `login/` | 登录注册 |
| `recharge/` | 充值 |
| `home/` | 首页 |
导航图:`res/navigation/circle_graph.xml`
## 关键配置
**build.gradle.kts**
```kotlin
androidResources {
noCompress += listOf("bin") // 禁止压缩 .bin允许 FileChannel 内存映射
}
```
**输入法配置**`res/xml/method.xml`
**网络安全**`res/xml/network_security_config.xml`
## 辅助脚本
```bash
python scripts/clean_vocab.py <输入文件> <输出文件> # 词表清洗(过滤无效词)
```
## 开发注意事项
- 输入法服务需用户在系统设置中手动启用
- 语言模型使用 `FileChannel.map()` 内存映射加载,修改 .bin 文件需重新生成
- 网络请求签名使用 Body 扁平化(支持嵌套 JSON 和数组)
- `NetworkClient.init(context)` 必须在使用 SSE 前调用(通常在 Application.onCreate
- 项目当前无单元测试配置

0
_nul
View File

View File

@@ -7,12 +7,7 @@ plugins {
android {
namespace = "com.example.myapplication"
compileSdk = 34
// 禁止压缩 .bin 文件,允许内存映射加载
androidResources {
noCompress += listOf("bin")
}
defaultConfig {
applicationId = "com.boshan.key.of.love"
minSdk = 21
@@ -60,7 +55,6 @@ dependencies {
implementation("com.google.android.material:material:1.12.0")
implementation("de.hdodenhof:circleimageview:3.1.0")
implementation("com.google.android.flexbox:flexbox:3.0.0")
implementation("com.github.Dimezis:BlurView:version-2.0.2")
// Jetpack Compose
implementation("androidx.activity:activity-compose:1.8.0")
@@ -83,7 +77,6 @@ dependencies {
// lifecycle
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.0")
implementation("androidx.work:work-runtime-ktx:2.9.0")
// 加密 SharedPreferences
implementation("androidx.security:security-crypto:1.1.0-alpha06")
// Glide for image loading

View File

@@ -2,10 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
@@ -51,9 +52,8 @@
<!-- 主界面 -->
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="true"
android:windowSoftInputMode="stateHidden|adjustResize">
android:screenOrientation="portrait"
android:exported="true">
</activity>
<!-- 输入法服务 -->
@@ -61,7 +61,8 @@
android:name=".MyInputMethodService"
android:label="@string/app_name"
android:exported="false"
android:permission="android.permission.BIND_INPUT_METHOD">
android:permission="android.permission.BIND_INPUT_METHOD"
android:foregroundServiceType="connectedDevice">
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Some files were not shown because too many files have changed in this diff Show More