5.54 GB
51,854 files
Updated 20 days ago
Name
Size
.android-user
.git
.github
.gradle
.gradle-home
.gradlehome
.idea
.kotlin
app
docs
gradle
network
.DS_Store6.15 kB
xet
.gitignore3.4 kB
xet
Get0 Bytes
xet
LICENSE1.11 kB
xet
README.md51.8 kB
xet
answers.md23.1 kB
xet
build.gradle1.15 kB
xet
config.pbtx2.38 kB
xet
gradle.properties580 Bytes
xet
gradlew8.76 kB
xet
gradlew.bat2.97 kB
xet
install.sh14.2 kB
xet
keystore.properties110 Bytes
xet
local.properties349 Bytes
xet
measured_report.md5.12 kB
xet
proguard-rules.pro1.4 kB
xet
replace_cards.py23.9 kB
xet
replace_ports.py839 Bytes
xet
scan_kotlin_files.py2.01 kB
xet
settings.gradle432 Bytes
xet
test_android_integration_sim.py3.99 kB
xet
README.md

Air Mouse – Complete Application Documentation

📋 Table of Contents

  1. Project Overview
  2. Architecture
  3. Package Structure
  4. Core Components
  5. Data Flow
  6. Dependency Injection
  7. UI Layer
  8. Domain Layer
  9. Data Layer
  10. Infrastructure Layer
  11. Building & Running
  12. Testing
  13. Contributing

1. Project Overview

1.1 What is Air Mouse?

Air Mouse is a production-ready Android application that turns your smartphone into a wireless mouse, gesture controller, and presentation remote. The app uses device sensors (gyroscope, accelerometer, magnetometer) to detect movement and gestures, then sends commands to a PC server over WebSocket/TCP/UDP.

1.2 Key Features

Category Features
Mouse Control Cursor movement, left/right click, double click, scroll
Gestures Click, double-click, right-click, scroll, swipe, custom gestures
Touchpad Full touchpad simulation with multi-touch gestures
Voice Commands Wake word detection, custom commands, voice feedback
Proximity Lock Auto-lock/unlock PC when you walk away
Calibration Gyroscope, accelerometer, magnetometer calibration
Presentation Mode Laser pointer, annotations, timer, Q&A
Game Profiles Automatic game detection with custom settings
Macro Recorder Record and playback mouse/keyboard macros
Screen Mirroring Real-time screen streaming to PC
Profiles Multiple user profiles with custom settings
Themes 20+ themes with accent colors
Accessibility High contrast, large text, screen reader support
Server Logs Real-time log viewer with filters and export
File Transfer Transfer files between phone and PC
Data Sync Sync calibration, gestures, profiles to server

1.3 Technology Stack

Component Technology
UI Framework Jetpack Compose (Material 3)
Architecture Clean Architecture + MVI
Dependency Injection Dagger Hilt
Database Room (SQLite)
Preferences SharedPreferences + DataStore
Networking OkHttp, WebSocket, TCP, UDP
Concurrency Kotlin Coroutines & Flow
Sensor Fusion Madgwick AHRS
Build Tool Gradle (Kotlin DSL)
Minimum SDK API 24 (Android 7.0)
Target SDK API 34 (Android 14)

1.4 Version Information

Version Release Date Key Changes
3.0.0 2025-01-15 Complete rewrite with Compose, Clean Architecture, MVI

2. Architecture

2.1 Clean Architecture Overview

The application follows Clean Architecture with four distinct layers:

┌─────────────────────────────────────────────────────────────────────────┐
│                         PRESENTATION LAYER                             │
│                    (Compose UI / ViewModels)                           │
│                                                                         │
│                         DEPENDS ON                                     │
└────────────────────────────────┬────────────────────────────────────┘
                                 │
                                 ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                           DOMAIN LAYER                                 │
│                    (Models / Use Cases / Interfaces)                   │
│                                                                         │
│                    INDEPENDENT OF FRAMEWORKS                           │
└────────────────────────────────┬────────────────────────────────────┘
                                 │
                                 ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                            DATA LAYER                                  │
│               (Repository Implementations / Data Sources)              │
│                                                                         │
│                         DEPENDS ON                                     │
└────────────────────────────────┬────────────────────────────────────┘
                                 │
                                 ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                         INFRASTRUCTURE LAYER                           │
│               (Network / Sensors / Database / Utilities)               │
└─────────────────────────────────────────────────────────────────────────┘

2.2 Dependency Direction

Presentation → Domain ← Data ← Infrastructure
     ↓           ↓        ↓          ↓
     └───────────┴────────┴──────────┘
              (Dependency Injection)

2.3 MVI Pattern (Model-View-Intent)

All screens follow the MVI (Model-View-Intent) pattern:

┌─────────────────────────────────────────────────────────────────────────┐
│                         MVI PATTERN                                    │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                         │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                         VIEW                                    │   │
│  │  ┌─────────────────────────────────────────────────────────┐   │   │
│  │  │  Compose Screen                                          │   │   │
│  │  │  • Renders UI based on State                            │   │   │
│  │  │  • Dispatches Events to ViewModel                       │   │   │
│  │  │  • Handles Effects (navigation, toasts)                 │   │   │
│  │  └─────────────────────────────────────────────────────────┘   │   │
│  └────────────────────────────────┬────────────────────────────────┘   │
│                                   │                                     │
│                                   ▼                                     │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                       VIEW MODEL                                │   │
│  │  ┌─────────────────────────────────────────────────────────┐   │   │
│  │  │  StateFlow<UiState>   │  SharedFlow<Effect>             │   │   │
│  │  ├─────────────────────────────────────────────────────────┤   │   │
│  │  │  fun handleEvent(event: Event) {                        │   │   │
│  │  │    when (event) { ... }                                 │   │   │
│  │  │  }                                                      │   │   │
│  │  └─────────────────────────────────────────────────────────┘   │   │
│  └────────────────────────────────┬────────────────────────────────┘   │
│                                   │                                     │
│                                   ▼                                     │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                         MODEL                                   │   │
│  │  ┌─────────────────────────────────────────────────────────┐   │   │
│  │  │  data class UiState(...)                                │   │   │
│  │  │  sealed class Event { ... }                            │   │   │
│  │  │  sealed class Effect { ... }                           │   │   │
│  │  └─────────────────────────────────────────────────────────┘   │   │
│  └─────────────────────────────────────────────────────────────────┘   │
│                                                                         │
└─────────────────────────────────────────────────────────────────────────┘

3. Package Structure

3.1 Complete Package Tree

com.airmouse/
├── AirMouseApplication.kt              # Application class
├── PreferencesManager.kt               # Preferences interface
├── SensorService.kt                    # Sensor service interface
│
├── data/                               # DATA LAYER
│   ├── datasource/
│   │   ├── local/                      # Local data sources
│   │   │   ├── AppDatabase.kt          # Room database
│   │   │   ├── Converters.kt           # Room type converters
│   │   │   ├── entities/               # Room entities (8 files)
│   │   │   ├── dao/                    # Room DAOs (8 files)
│   │   │   ├── interfaces/             # Local data source interfaces (6 files)
│   │   │   ├── implementations/        # Local data source impls (6 files)
│   │   │   └── models/                 # Local data models (5 files)
│   │   └── remote/                     # Remote data sources
│   │       ├── interfaces/             # Remote data source interfaces (4 files)
│   │       └── implementations/        # Remote data source impls (4 files)
│   ├── repository/                     # Repository implementations (11 files)
│   └── mapper/                         # Domain ↔ Entity mappers (2 files)
│
├── domain/                             # DOMAIN LAYER
│   ├── model/                          # Domain models (50+ files)
│   ├── repository/                     # Repository interfaces (11 files)
│   ├── usecase/                        # Use cases (16 files)
│   └── feature/                        # Feature orchestrators (10 files)
│
├── presentation/                       # PRESENTATION LAYER
│   ├── ui/                             # UI Screens
│   │   ├── home/                       # Home screen
│   │   ├── settings/                   # Settings screen
│   │   ├── calibration/                # Calibration screens
│   │   ├── touchpad/                   # Touchpad screen
│   │   ├── voice/                      # Voice commands screen
│   │   ├── themes/                     # Themes screen
│   │   ├── accessibility/              # Accessibility screen
│   │   ├── profiles/                   # Profiles screen
│   │   ├── proximity/                  # Proximity screen
│   │   ├── logs/                       # Server logs screen
│   │   ├── help/                       # Help screen
│   │   ├── about/                      # About screen (stub)
│   │   ├── statistics/                 # Statistics screen (stub)
│   │   ├── gesture/                    # Gesture studio (stub)
│   │   ├── edge/                       # Edge gestures (stub)
│   │   ├── network/                    # Network discovery (stub)
│   │   ├── sensor/                     # Sensor visualizer (stub)
│   │   ├── battery/                    # Battery screen (stub)
│   │   ├── files/                      # File transfer (stub)
│   │   ├── onboarding/                 # Onboarding screens
│   │   └── main/                       # Main screen components
│   ├── navigation/                     # Navigation
│   │   ├── Destinations.kt
│   │   ├── NavigationActions.kt
│   │   ├── AirMouseNavHost.kt
│   │   └── AirMouseBottomBar.kt
│   ├── theme/                          # Theming
│   │   ├── Theme.kt
│   │   ├── ThemeColors.kt
│   │   ├── Color.kt
│   │   ├── Dimensions.kt
│   │   └── Shapes.kt
│   ├── components/                     # Reusable UI components (28 files)
│   ├── extensions/                     # Compose extensions
│   └── MainActivity.kt                 # Main activity
│
├── network/                            # INFRASTRUCTURE – NETWORK
│   ├── ConnectionManager.kt            # Core network manager
│   ├── UdpDiscovery.kt                 # UDP server discovery
│   ├── AutoReconnectManager.kt         # Automatic reconnection
│   ├── NetworkQualityMonitor.kt        # Network quality monitoring
│   ├── MessageTypes.kt                 # Protocol constants
│   ├── AirMouseProtocolMessages.kt     # Message builders
│   ├── ConnectionHelper.kt             # Extension functions
│   ├── TcpClient.kt                    # DEPRECATED – TCP client
│   └── WebSocketManager.kt             # DEPRECATED – WebSocket client
│
├── sensors/                            # INFRASTRUCTURE – SENSORS
│   ├── SensorService.kt                # Main sensor service
│   ├── CalibrationHelper.kt            # Sensor calibration
│   ├── EnhancedGestureDetector.kt      # Advanced gesture detection
│   ├── MadgwickAHRS.kt                 # Sensor fusion algorithm
│   ├── MotionAnalyzer.kt               # Motion feature analysis
│   ├── MotionDetector.kt               # Basic motion detection
│   ├── OrientationTracker.kt           # Orientation tracking
│   ├── SensorDataLogger.kt             # CSV logging
│   ├── SensorDataProcessor.kt          # Signal processing filters
│   ├── SensorFusion.kt                 # Static fusion utilities
│   ├── SensorManagerHelper.kt          # Sensor availability
│   └── GestureDetector.kt              # Legacy gesture detector
│
├── utils/                              # INFRASTRUCTURE – UTILITIES
│   ├── PreferencesManager.kt           # Core preferences
│   ├── PreferencesKeys.kt              # Preference keys (138 constants)
│   ├── LogManager.kt                   # Centralized logging
│   ├── PermissionHelper.kt             # Permission management
│   ├── VibrateUtils.kt                 # Haptic feedback
│   ├── AudioUtils.kt                   # Sound playback
│   ├── BluetoothUtils.kt               # Bluetooth operations
│   ├── BatterySaver.kt                 # Battery optimization
│   ├── ConnectedDeviceStore.kt         # Device history
│   ├── QRScanner.kt                    # QR code scanning
│   ├── AnimationUtils.kt               # Animation helpers
│   ├── StringUtils.kt                  # String helpers
│   ├── ValidationUtils.kt              # Validation helpers
│   ├── MathUtils.kt                    # Math helpers
│   ├── ConversionUtils.kt              # Unit conversion
│   ├── DateUtils.kt                    # Date formatting
│   ├── ColorUtils.kt                   # Color manipulation
│   ├── FileHelper.kt                   # File operations
│   ├── JsonHelper.kt                   # JSON serialization
│   ├── NetworkUtils.kt                 # Network utilities
│   ├── ResourceHelper.kt               # Resource access
│   ├── ThemeManager.kt                 # Theme management
│   ├── DialogHelper.kt                 # Dialog helpers
│   ├── ViewHelpers.kt                  # View extensions
│   ├── ResultExtensions.kt             # Result<T> extensions
│   ├── SensorUtils.kt                  # Sensor utilities
│   ├── ErrorHandler.kt                 # Error handling
│   ├── AppConstants.kt                 # Constants
│   ├── ApplicationContext.kt           # Hilt qualifier
│   └── Utils.kt                        # General utilities
│
├── notifications/                      # INFRASTRUCTURE – NOTIFICATIONS
│   └── NotificationManager.kt          # Notification management
│
├── files/                              # INFRASTRUCTURE – FILE TRANSFER
│   └── FileTransferService.kt          # File transfer service
│
├── mirroring/                          # INFRASTRUCTURE – SCREEN MIRRORING
│   └── ScreenMirroringService.kt       # Screen mirroring service
│
├── gaming/                             # INFRASTRUCTURE – GAMING
│   └── GameProfilesManager.kt          # Game profiles management
│
├── macros/                             # INFRASTRUCTURE – MACROS
│   └── MacroRecorder.kt                # Macro recording & playback
│
├── sync/                               # INFRASTRUCTURE – SYNC
│   └── DataSyncManager.kt              # Data synchronization
│
├── di/                                 # DEPENDENCY INJECTION
│   ├── AppContainer.kt
│   ├── AppModule.kt
│   ├── NetworkModule.kt
│   ├── DatabaseModule.kt
│   ├── SensorModule.kt
│   ├── ServiceModule.kt
│   ├── RepositoryModule.kt
│   ├── UseCaseModule.kt
│   ├── FeatureModule.kt
│   ├── ViewModelModule.kt
│   ├── CalibrationModule.kt
│   ├── CoroutineModule.kt
│   └── GestureRepositoryModule.kt
│
└── ui/                                 # UI UTILITIES
    ├── BaseActivity.kt
    ├── DebugOverlay.kt
    ├── SensorCubeView.kt
    ├── UiStyleUtils.kt
    ├── WebViewActivity.kt
    └── onboarding/
        ├── OnboardingActivity.kt
        ├── OnboardingItem.kt
        └── OnboardingPagerAdapter.kt

3.2 File Count Summary

Layer Files Lines of Code (approx)
Domain 87+ ~6,400
Data 60+ ~4,500
Presentation 80+ ~12,000
Infrastructure 100+ ~8,000
Total 327+ ~30,900

4. Core Components

4.1 Domain Layer

Models (50+ files)

Category Models Purpose
Calibration CalibrationStatus, CalibrationQuality, CalibrationData, SensorCalibrationData, CalibrationProgress Sensor calibration
Connection ConnectionStatus, ConnectionProtocol, ConnectionConfig, ConnectionQuality, DiscoveredServer Network connection
Gesture GestureType, GestureEvent, CustomGestureTemplate, GestureTemplate, GestureTrainingStats Gesture detection
Mouse MouseButton, MouseEvent, MovementProfile, MouseStatistics Mouse control
Proximity ProximityState, ProximityConfig, ProximityCalibration Proximity detection
Statistics StatisticsSummary, DailyStats, HistoricalStatistics, GestureStats Usage statistics
Profile UserProfile, ProfileSettings, ProfileSort, ViewMode User profiles
Voice VoiceCommand, VoiceCommandConfig, VoiceCommandHistory Voice commands
Update UpdateResult, VersionInfo, UpdateInfo, UpdateProgress App updates
Bluetooth BluetoothDeviceInfo, BLEService, BLECharacteristic Bluetooth communication
Error ErrorType, AppError Error handling

Repository Interfaces (11 files)

Repository Purpose Key Methods
ICalibrationRepository Sensor calibration calibrateGyroscope(), getCalibrationData()
IConnectionRepository Network connection connect(), disconnect(), sendMove()
IGestureRepository Gesture detection detectGesture(), addCustomGesture()
IMouseRepository Cursor control move(), click(), scroll()
IProfileRepository User profiles createProfile(), updateProfile()
IProximityRepository Proximity detection startMonitoring(), getProximityState()
ISensorRepository Sensor data observeSensorData(), startSensors()
ISettingsRepository App settings getSensitivity(), setTheme()
IStatisticsRepository Usage statistics recordClick(), getCurrentSession()
IUpdateRepository App updates checkForUpdates(), downloadUpdate()
IVoiceCommandRepository Voice commands processVoiceInput(), addCommand()

Use Cases (16 files)

Use Case Purpose
CalibrationUseCase Sensor calibration orchestration
ConnectToServerUseCase Server connection management
SendMovementUseCase Cursor movement and clicks
DetectGestureUseCase Gesture detection
DiscoverServersUseCase UDP server discovery
GetConnectionStatusUseCase Connection status retrieval
GetStatisticsUseCase Usage statistics retrieval
RecordStatisticsUseCase Usage statistics recording
ManageProfileUseCase User profile management
ManageGestureTemplatesUseCase Gesture template management
HandleVoiceCommandUseCase Voice command processing
GetProximityStateUseCase Proximity state retrieval
UpdateProximityConfigUseCase Proximity configuration
TestConnectionUseCase Connection testing
CheckForUpdatesUseCase App update checking
GetGestureStatisticsUseCase Gesture statistics retrieval

4.2 Data Layer

Repository Implementations (11 files)

Repository Data Sources
CalibrationRepositoryImpl ICalibrationDataSource, CalibrationHelper
ConnectionRepositoryImpl IConnectionDataSource
GestureRepositoryImpl IGestureDataSource, EnhancedGestureDetector
MouseRepositoryImpl ConnectionManager
ProfileRepositoryImpl IProfileDataSource
ProximityRepositoryImpl BluetoothAdapter, ConnectionManager
SensorRepositoryImpl SensorManager, CalibrationHelper
SettingsRepositoryImpl IPreferencesDataSource
StatisticsRepositoryImpl IStatisticsDataSource
UpdateRepositoryImpl IPreferencesDataSource
VoiceCommandRepositoryImpl IPreferencesDataSource

Local Data Sources

Data Source Storage Purpose
CalibrationDataSourceImpl Preferences Sensor calibration data
GestureDataSourceImpl Preferences (JSON) Gesture templates, training, stats
ProfileDataSourceImpl Preferences (JSON) User profiles, settings
StatisticsDataSourceImpl Preferences (JSON) Session, daily, historical stats
PreferencesDataSourceImpl Preferences Generic preferences
LocalDataSourceImpl Room + Preferences Unified local data access

Room Database

Entity DAO Purpose
CalibrationEntity CalibrationDao Sensor calibration data
ProfileEntity ProfileDao User profiles
GestureTemplateEntity GestureDao Gesture templates
TrainingSampleEntity TrainingSampleDao ML training data
StatisticsEntity StatisticsDao Session statistics
DailyStatsEntity DailyStatsDao Daily aggregated stats
GestureStatsEntity GestureStatsDao Per-gesture stats
SettingsEntity SettingsDao App settings

4.3 Infrastructure Layer

Network

Component Purpose Protocol
ConnectionManager Core network manager WebSocket/TCP/UDP
UdpDiscovery Server discovery UDP
AutoReconnectManager Reconnection logic -
NetworkQualityMonitor Quality monitoring -

Sensors

Component Purpose
SensorService Central sensor manager
CalibrationHelper Sensor calibration
EnhancedGestureDetector Gesture detection
MadgwickAHRS Sensor fusion algorithm
MotionAnalyzer Motion analysis

Utilities (32 files)

Category Files
Preferences PreferencesManager, PreferencesKeys, PreferencesHelper, SharedPrefsUtils, PreferencesDataStore
Logging LogManager, ErrorHandler
Permissions PermissionHelper, PermissionManager, PermissionUIHelper, PermissionUtils
Bluetooth BluetoothUtils
Network NetworkUtils, NetworkStateHelper
Audio/Vibration VibrateUtils, AudioUtils
Battery BatterySaver, BatteryOptimizer
Math MathUtils, ConversionUtils
Date DateUtils
File FileHelper, JsonHelper
QR QRScanner
Animation AnimationUtils
Color ColorUtils
Validation StringUtils, ValidationUtils

4.4 Presentation Layer

Screens (22+ files)

Screen Status ViewModel
Home ✅ Complete HomeViewModel
Settings ✅ Complete SettingsViewModel
Calibration ✅ Complete CalibrationViewModel
Touchpad ✅ Complete TouchpadViewModel
Voice Commands ✅ Complete VoiceCommandsViewModel
Themes ✅ Complete ThemesViewModel
Accessibility ✅ Complete AccessibilityViewModel
Profiles ✅ Complete ProfilesViewModel
Proximity ✅ Complete ProximityViewModel
Server Logs ✅ Complete ServerLogsViewModel
Help ✅ Complete HelpViewModel
Statistics ⚠️ Stub StatisticsViewModel
About ⚠️ Stub AboutViewModel
Gesture Studio ⚠️ Stub GestureStudioViewModel
Edge Gestures ⚠️ Stub EdgeGesturesViewModel
Network Discovery ⚠️ Stub NetworkDiscoveryViewModel
Sensor Visualizer ⚠️ Stub SensorVisualizerViewModel
Battery ⚠️ Stub BatteryViewModel
File Transfer ⚠️ Stub FileTransferViewModel

UI Components (28 files)

Category Components
Animations AnimatedCheckbox, AnimatedSwitch, AnimatedToast, AnimatedCounter, AnimatedConnectionStatus
Status BatteryLevelIndicator, ConnectionStatusBadge, NotificationBadge
Charts DataChart, GestureWaveform, RadarAnimation
Cards GlassCard, NeumorphicCard, InteractiveTutorialCard
Buttons NeonButton, GradientIconButton, FloatingActionMenu
Effects FloatingParticles, ParticleBackground, VoiceWaveAnimation, HolographicText
Utilities ShimmerEffect, SkeletonScreen, PullToRefresh, SlideUpPanel
Visualization SensorVisualizer, GestureWaveform

5. Data Flow

5.1 Complete Data Flow Diagram

┌─────────────────────────────────────────────────────────────────────────┐
│                         DATA FLOW                                      │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                         │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                       USER INTERACTION                           │   │
│  │                    (Touch / Gesture / Voice)                     │   │
│  └────────────────────────────────┬────────────────────────────────┘   │
│                                   │                                     │
│                                   ▼                                     │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                         VIEW MODEL                               │   │
│  │              (StateFlow / SharedFlow / Events)                   │   │
│  └────────────────────────────────┬────────────────────────────────┘   │
│                                   │                                     │
│                                   ▼                                     │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                         USE CASE                                 │   │
│  │                    (Business Logic)                              │   │
│  └────────────────────────────────┬────────────────────────────────┘   │
│                                   │                                     │
│                                   ▼                                     │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                      REPOSITORY INTERFACE                        │   │
│  │                     (Domain Contract)                            │   │
│  └────────────────────────────────┬────────────────────────────────┘   │
│                                   │                                     │
│                                   ▼                                     │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                   REPOSITORY IMPLEMENTATION                      │   │
│  │                      (Data Layer)                                │   │
│  └────────────────────────────────┬────────────────────────────────┘   │
│                                   │                                     │
│                                   ▼                                     │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                        DATA SOURCE                               │   │
│  │              (Room / Preferences / Network)                      │   │
│  └─────────────────────────────────────────────────────────────────┘   │
│                                                                         │
│  ┌─────────────────────────────────────────────────────────────────┐   │
│  │                      STATE FLOW BACK                             │   │
│  │  Data Source → Repository → Use Case → ViewModel → UI           │   │
│  └─────────────────────────────────────────────────────────────────┘   │
│                                                                         │
└─────────────────────────────────────────────────────────────────────────┘

5.2 Example: Connect to Server

1. User taps "Connect" button
        ↓
2. HomeViewModel.connect()
        ↓
3. ConnectToServerUseCase(config)
        ↓
4. ConnectionRepository.connect(config)
        ↓
5. ConnectionDataSourceImpl.connect(ip, port)
        ↓
6. ConnectionManager.connect(ip, port)
        ↓
7. WebSocket/TCP/UDP connection
        ↓
8. ConnectionManager emits status update
        ↓
9. ConnectionRepository observes status change
        ↓
10. ConnectToServerUseCase returns Result<Boolean>
        ↓
11. HomeViewModel updates UI state
        ↓
12. HomeScreen shows "Connected" status

5.3 Example: Gesture Detection

1. User performs gesture
        ↓
2. EnhancedGestureDetector detects gesture
        ↓
3. GestureRepositoryImpl.detectGesture(sensorData)
        ↓
4. DetectGestureUseCase(sensorData)
        ↓
5. HomeViewModel receives gesture event
        ↓
6. HomeViewModel updates UI state
        ↓
7. HomeScreen shows gesture notification
        ↓
8. GestureDataSourceImpl.incrementGestureCount(gesture, confidence)
        ↓
9. PreferencesManager updates statistics

6. Dependency Injection

6.1 Hilt Modules

Module Purpose Key Dependencies
AppModule Core dependencies Context, PreferencesManager, Vibrator, BluetoothAdapter, UsbManager
NetworkModule Network dependencies OkHttpClient, ConnectionManager, UdpDiscovery, NetworkStateHelper
DatabaseModule Room database AppDatabase, all DAOs
SensorModule Sensor dependencies SensorManager, CalibrationHelper, EnhancedGestureDetector
ServiceModule Service dependencies SensorService, PresentationModeService
RepositoryModule Repository bindings All repository implementations
UseCaseModule Use case providers All use cases
FeatureModule Feature orchestrators ConnectionFeature, MouseControlFeature, etc.
ViewModelModule ViewModel bindings All ViewModels
CalibrationModule Calibration dependencies ICalibrationDataSource
CoroutineModule Coroutine dispatchers IoDispatcher, MainDispatcher, DefaultDispatcher
GestureRepositoryModule Gesture repository IGestureRepository, GestureRepositoryImpl

6.2 Dependency Injection Example

// In ViewModel
@HiltViewModel
class HomeViewModel @Inject constructor(
    private val connectionFeature: ConnectionFeature,
    private val sensorFeature: SensorFeature,
    private val prefs: PreferencesManager
) : ViewModel() { ... }

// In Activity
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    @Inject
    lateinit var prefs: PreferencesManager

    @Inject
    lateinit var sensorService: SensorService
}

7. UI Layer

7.1 Navigation

The app uses Jetpack Compose Navigation with a sealed class for type-safe routing.

sealed class Destinations(
    val route: String,
    val title: String,
    val icon: ImageVector
) {
    object Home : Destinations("home", "Home", Icons.Default.Home)
    object Settings : Destinations("settings", "Settings", Icons.Default.Settings)
    // ... 20+ destinations
}

Bottom Navigation Destinations:

  • Home
  • Statistics
  • Settings
  • Help

Full Destinations List (23):

  1. Home
  2. Statistics
  3. Settings
  4. Help
  5. About
  6. Calibration
  7. Calibration Result
  8. Sensor Visualizer
  9. Gesture Studio
  10. Edge Gestures
  11. Touchpad
  12. Touchpad Settings
  13. Network Discovery
  14. Server Logs
  15. Proximity
  16. Voice Commands
  17. Profiles
  18. Themes
  19. Battery
  20. Accessibility
  21. Onboarding
  22. File Transfer

7.2 Theming

The app supports 20+ themes with dynamic accent colors.

@Composable
fun AirMouseTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    useDynamicColor: Boolean = true,
    themeColors: ThemeColorScheme? = null,
    content: @Composable () -> Unit
) { ... }

Supported Themes:

Category Themes
Standard System, Light, Dark, Pure Black, High Contrast
Nature Ocean, Sunset, Forest, Mint, Peach, Sky
Vibrant Purple Haze, Cherry, Neon, Lavender
Premium Midnight, Gold, Matrix, Cotton Candy, Coffee

7.3 Screen Architecture (MVI)

All screens follow the MVI pattern:

// State
data class SettingsUiState(
    val sensitivity: Float = 0.5f,
    val hapticEnabled: Boolean = true,
    val isLoading: Boolean = false
)

// Event
sealed class SettingsEvent {
    data class UpdateSensitivity(val value: Float) : SettingsEvent()
    object ToggleHaptic : SettingsEvent()
}

// Effect
sealed class SettingsEffect {
    data class ShowToast(val message: String) : SettingsEffect()
}

// ViewModel
@HiltViewModel
class SettingsViewModel @Inject constructor(
    private val settingsRepository: ISettingsRepository
) : ViewModel() {
    private val _uiState = MutableStateFlow(SettingsUiState())
    val uiState: StateFlow<SettingsUiState> = _uiState.asStateFlow()
    
    fun handleEvent(event: SettingsEvent) { ... }
}

8. Domain Layer

8.1 Repository Interfaces

Repository Purpose Key Methods
ICalibrationRepository Sensor calibration calibrateGyroscope(), getCalibrationData()
IConnectionRepository Network connection connect(), disconnect(), sendMove()
IGestureRepository Gesture detection detectGesture(), addCustomGesture()
IMouseRepository Cursor control move(), click(), scroll()
IProfileRepository User profiles createProfile(), updateProfile()
IProximityRepository Proximity detection startMonitoring(), getProximityState()
ISensorRepository Sensor data observeSensorData(), startSensors()
ISettingsRepository App settings getSensitivity(), setTheme()
IStatisticsRepository Usage statistics recordClick(), getCurrentSession()
IUpdateRepository App updates checkForUpdates(), downloadUpdate()
IVoiceCommandRepository Voice commands processVoiceInput(), addCommand()

8.2 Use Cases

Use Case Purpose
CalibrationUseCase Sensor calibration orchestration
ConnectToServerUseCase Server connection management
SendMovementUseCase Cursor movement and clicks
DetectGestureUseCase Gesture detection
DiscoverServersUseCase UDP server discovery
GetConnectionStatusUseCase Connection status retrieval
GetStatisticsUseCase Usage statistics retrieval
RecordStatisticsUseCase Usage statistics recording
ManageProfileUseCase User profile management
ManageGestureTemplatesUseCase Gesture template management
HandleVoiceCommandUseCase Voice command processing
GetProximityStateUseCase Proximity state retrieval
UpdateProximityConfigUseCase Proximity configuration
TestConnectionUseCase Connection testing
CheckForUpdatesUseCase App update checking
GetGestureStatisticsUseCase Gesture statistics retrieval

9. Data Layer

9.1 Data Sources

Data Source Storage Purpose
CalibrationDataSourceImpl Preferences Sensor calibration data
GestureDataSourceImpl Preferences (JSON) Gesture templates, training, stats
ProfileDataSourceImpl Preferences (JSON) User profiles, settings
StatisticsDataSourceImpl Preferences (JSON) Session, daily, historical stats
PreferencesDataSourceImpl Preferences Generic preferences
LocalDataSourceImpl Room + Preferences Unified local data access

9.2 Room Database

Entity DAO Purpose
CalibrationEntity CalibrationDao Sensor calibration data
ProfileEntity ProfileDao User profiles
GestureTemplateEntity GestureDao Gesture templates
TrainingSampleEntity TrainingSampleDao ML training data
StatisticsEntity StatisticsDao Session statistics
DailyStatsEntity DailyStatsDao Daily aggregated stats
GestureStatsEntity GestureStatsDao Per-gesture stats
SettingsEntity SettingsDao App settings

10. Infrastructure Layer

10.1 Network

Component Purpose Protocol
ConnectionManager Core network manager WebSocket/TCP/UDP
UdpDiscovery Server discovery UDP
AutoReconnectManager Reconnection logic -
NetworkQualityMonitor Quality monitoring -

ConnectionManager Features:

  • Multi-protocol (WebSocket/TCP/UDP)
  • Auto-reconnection with exponential backoff
  • Heartbeat (Ping/Pong)
  • Reliable message delivery (ACK-based retransmission)
  • Connection quality monitoring
  • StateFlow for reactive UI updates

10.2 Sensors

Component Purpose
SensorService Central sensor manager
CalibrationHelper Sensor calibration (gyro, accel, mag)
EnhancedGestureDetector Gesture detection (click, scroll, swipe)
MadgwickAHRS Sensor fusion algorithm
MotionAnalyzer Motion analysis
SensorDataLogger CSV logging for debugging

10.3 Utilities (32 files)

Category Files Purpose
Preferences PreferencesManager, PreferencesKeys, PreferencesHelper Persistent storage
Permissions PermissionHelper, PermissionManager Runtime permissions
Bluetooth BluetoothUtils Bluetooth operations
Network NetworkUtils, NetworkStateHelper Network connectivity
Audio AudioUtils Sound playback
Haptic VibrateUtils Haptic feedback
Battery BatterySaver, BatteryOptimizer Power management
Math MathUtils, ConversionUtils Mathematical operations
Date DateUtils Date/time formatting
File FileHelper, JsonHelper File operations
QR QRScanner QR code scanning
Animation AnimationUtils Animation helpers
Color ColorUtils Color manipulation
Validation StringUtils, ValidationUtils Input validation
Logging LogManager, ErrorHandler Error handling

11. Building & Running

11.1 Prerequisites

Tool Version
Android Studio Hedgehog or newer
JDK 17 or newer
Gradle 8.4+
Android SDK API 34
Kotlin 1.9.24

11.2 Build Commands

# Clean build
./gradlew clean

# Build debug APK
./gradlew assembleDebug

# Build release APK
./gradlew assembleRelease

# Run all tests
./gradlew test

# Run instrumentation tests
./gradlew connectedAndroidTest

# Generate signed release APK
./gradlew bundleRelease

11.3 Gradle Configuration

// Project build.gradle
buildscript {
    ext.kotlin_version = '1.9.24'
    ext.hilt_version = '2.52'
    
    dependencies {
        classpath 'com.android.tools.build:gradle:8.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
        classpath "com.google.devtools.ksp:ksp-gradle-plugin:1.9.24-1.0.20"
    }
}

// App build.gradle
android {
    compileSdk 34
    minSdk 24
    targetSdk 34
    versionCode 30
    versionName "3.0.0"
}

dependencies {
    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
    implementation 'androidx.activity:activity-compose:1.8.0'
    implementation platform('androidx.compose:compose-bom:2024.02.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    implementation 'com.google.dagger:hilt-android:2.52'
    implementation 'androidx.room:room-runtime:2.6.0'
    implementation 'androidx.room:room-ktx:2.6.0'
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
    implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
}

12. Testing

12.1 Test Structure

app/src/test/
├── domain/
│   ├── model/          # Model tests
│   ├── repository/     # Repository interface tests
│   └── usecase/        # Use case tests
├── data/
│   ├── datasource/     # Data source tests
│   └── repository/     # Repository implementation tests
└── presentation/
    ├── ui/             # UI tests
    └── viewmodel/      # ViewModel tests

app/src/androidTest/
└── presentation/
    └── ui/             # Instrumentation UI tests

12.2 Key Test Classes

Test Class Purpose
CalibrationUseCaseTest Test calibration business logic
ConnectionManagerTest Test network connection
GestureDetectorTest Test gesture detection
SettingsViewModelTest Test settings ViewModel
HomeScreenTest Test home screen UI

12.3 Running Tests

# Run unit tests
./gradlew testDebugUnitTest

# Run instrumentation tests
./gradlew connectedAndroidTest

# Run a specific test class
./gradlew test --tests "com.airmouse.domain.usecase.CalibrationUseCaseTest"

13. Contributing

13.1 Code Style

  • Kotlin with official Kotlin coding conventions
  • Jetpack Compose with Material 3 guidelines
  • Clean Architecture with clear layer separation
  • MVI pattern for all screens
  • Kotlin Coroutines & Flow for concurrency
  • Dagger Hilt for dependency injection

13.2 Commit Message Format

<type>(<scope>): <subject>

<body>

<footer>

Types:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation
  • style: Code style
  • refactor: Code refactoring
  • test: Tests
  • chore: Build/CI

13.3 Development Guidelines

  1. Domain Layer:

    • Models should be pure Kotlin (no Android dependencies)
    • Repository interfaces should be in domain
    • Use cases should contain business logic
  2. Data Layer:

    • Repository implementations should be in data
    • Data sources should abstract storage
    • Room entities should be in data
  3. Presentation Layer:

    • Screens should follow MVI pattern
    • ViewModels should handle UI state
    • Effects should be used for side effects
  4. Testing:

    • Unit tests for all use cases
    • Integration tests for repositories
    • UI tests for critical flows

✅ Summary

Aspect Description
Project Air Mouse – Wireless mouse and gesture control
Architecture Clean Architecture + MVI
UI Jetpack Compose Material 3
DI Dagger Hilt
Database Room
Network WebSocket, TCP, UDP
Sensors Gyroscope, Accelerometer, Magnetometer
Features 20+ screens, 65 settings, 16 use cases
Files 327+ files
Lines of Code ~30,900
Platform Android 7.0+
Version 3.0.0

Air Mouse is a complete, production-ready application that demonstrates best practices in Android development with Clean Architecture, Jetpack Compose, and MVI pattern.

Total size
5.54 GB
Files
51,854
Last updated
Sep 12
Pre-warmed CDN
US EU US EU

Contributors