模块架构
Mooting Android Demo 的模块架构详解。
模块总览
Mooting_android_demo/
├── app/ # 主应用模块
├── BluetoothModule/ # 蓝牙通信核心库
└── DebugModule/ # 调试工具模块App 模块
主应用入口模块,提供设备扫描和绑定 UI。
主要文件
| 文件 | 说明 |
|---|---|
DemoApplication.kt | Application 类,初始化 SDK |
MainActivity.kt | 主界面,设备扫描和连接 |
SearchDeviceListAdapter.java | 设备列表适配器 |
LoadingDialog.kt | 加载对话框 |
依赖关系
kotlin
// app/build.gradle.kts
dependencies {
implementation(project(":BluetoothModule"))
implementation(project(":DebugModule"))
}BluetoothModule
核心蓝牙通信库,封装 MetaBluetoothSDK。
目录结构
BluetoothModule/
├── libs/
│ └── MetaBluetoothSDK.aar # 底层 SDK
├── src/main/java/.../bluetooth/
│ ├── core/ # 核心管理器
│ │ ├── DeviceManager.kt
│ │ ├── MetaGlassDeviceGlobal.kt
│ │ ├── MetaGlassDeviceConnect.kt
│ │ ├── MetaSPPManager.kt
│ │ ├── BlueRingManager.kt
│ │ └── TranscriptionManager.kt
│ ├── bean/ # 数据类
│ │ ├── DeviceType.kt
│ │ ├── DeviceTokenBean.kt
│ │ └── ...
│ ├── listener/ # 回调接口
│ │ ├── GlassDeviceScanListener.java
│ │ ├── GlassDeviceCmdRspListener.java
│ │ └── ...
│ ├── task/ # 任务管理
│ │ ├── CmdTask.java
│ │ └── BTConnectTask.kt
│ ├── message/ # 消息协议
│ │ ├── IMessage.java
│ │ └── MessageType.java
│ └── util/ # 工具类
│ ├── ByteUtil.java
│ ├── PermissionKT.kt
│ └── ...核心类说明
DeviceManager
设备管理单例:
kotlin
object DeviceManager {
fun init(app: Application)
fun getInstance(): DeviceManager
fun startDiscovery()
fun stopDiscovery()
fun buildDevice(name, macBle, macBt, token, status)
fun connect(userId, token, imei, enableBtConnect)
fun disconnect()
fun sendCmd(cmd: CmdReq)
fun isConnected(): Boolean
}MetaGlassDeviceGlobal
全局状态管理:
kotlin
object MetaGlassDeviceGlobal {
fun addGlassDeviceScanListener(listener)
fun removeGlassDeviceScanListener(listener)
fun addGlassDeviceCmdRspListener(listener)
fun removeGlassDeviceCmdRspListener(listener)
fun addGlassDeviceConnectListener(listener)
}DebugModule
调试和测试工具模块。
功能列表
| Fragment | 功能 |
|---|---|
| DebugMainFragment | 功能菜单入口 |
| DebugCmdFragment | 命令测试 |
| DebugAudioGatherFragment | 音频采集 |
| DebugPCMFragment | PCM 音频流 |
| DebugDisplayFragment | 显示控制 |
| DebugLogFragment | 日志查看 |
| DebugPhotosensitivityFragment | 光敏测试 |
导航配置
使用 Navigation Component:
xml
<!-- res/navigation/debug_nav_graph.xml -->
<navigation>
<fragment android:id="@+id/debugMainFragment" />
<fragment android:id="@+id/debugCmdFragment" />
<!-- ... -->
</navigation>模块间通信
┌─────────────────────────────────────────────────────────────┐
│ App 模块 │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ MainActivity │ │
│ │ • 初始化 DeviceManager │ │
│ │ • 注册扫描监听器 │ │
│ │ • 处理设备连接 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ BluetoothModule │ │
│ │ • DeviceManager (设备管理) │ │
│ │ • MetaBluetoothSDK (底层通信) │ │
│ │ • 监听器回调 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ DebugModule │ │
│ │ • 调试界面 │ │
│ │ • 命令测试 │ │
│ │ • 日志查看 │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘