Skip to content

模块架构

Mooting Android Demo 的模块架构详解。

模块总览

Mooting_android_demo/
├── app/                    # 主应用模块
├── BluetoothModule/        # 蓝牙通信核心库
└── DebugModule/            # 调试工具模块

App 模块

主应用入口模块,提供设备扫描和绑定 UI。

主要文件

文件说明
DemoApplication.ktApplication 类,初始化 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音频采集
DebugPCMFragmentPCM 音频流
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                        │   │
│  │  • 调试界面                                         │   │
│  │  • 命令测试                                         │   │
│  │  • 日志查看                                         │   │
│  └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘

Mooting 开发者文档