# rkkr/simple-keyboard architecture

> Architecture diagram of the GitHub repository rkkr/simple-keyboard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rkkr/simple-keyboard
- Repository: https://github.com/rkkr/simple-keyboard

## Overview

##### Project Type & Purpose
- Native Android Input Method (IME) app (Simple Keyboard)
- Purpose: lightweight, customizable on-screen keyboard without extra permissions or ads

##### File Structure
- app/src/main/java/rkr/simplekeyboard/inputmethod
– Core IME service classes (LatinIME extends InputMethodService)
– Compatibility helpers for different Android versions
- app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard
– UI classes: KeyboardView, MainKeyboardView, MoreKeysPanel
– Keyboard model: Key, KeyboardLayoutSet, KeyboardTheme, KeyboardState
- app/src/main/java/rkr/simplekeyboard/inputmethod/event
– Event dispatcher & transaction (touch → key detection)
- app/src/main/java/rkr/simplekeyboard/inputmethod/latin
– Input logic: InputLogic, RichInputConnection, AudioAndHapticFeedbackManager
– Settings fragments & manager for themes, languages, preferences
- app/src/main/res
– XML layouts, keyboard definitions, themes, localizations

##### Key Insights from README
- Built on AOSP LatinIME
- No network calls, no external dependencies (ads, emoji, spell-checker)
- Minimal permissions: Vibrate only

##### Main Components
a. Android System (IME framework & Services)
b. IME Service Layer
– LatinIME (extends InputMethodService)
– SystemBroadcastReceiver (e.g., language change)
c. UI Layer
– KeyboardView / MainKeyboardView / MoreKeysKeyboardView
– Preview & drawing helpers (KeyPreviewView, DrawingProxy)
d. Input & Event Pipeline
– Touch events → Event.java → InputTransaction → KeyDetector → MoreKeysDetector
– ProximityInfo, PointerTracker, BogusMoveEventDetector
e. Business Logic Layer
– InputLogic (character composition, pointer moves, delete swipe)
– AudioAndHapticFeedbackManager
f. Configuration & Resource Layer
– PreferenceManagerCompat / SettingsActivity & fragments
g. Android Services & APIs
– VibratorService, AudioManager, InputConnection API

##### Relationships & Data Flow
1. User Touch → Android OS → InputMethodService.onTouchEvent
2. onTouchEvent → Event dispatcher → InputTransaction
3. InputTransaction → KeyDetector → identify Key → send to KeyboardActionListener
4. KeyboardActionListener → InputLogic processes (e.g., character vs delete)
5. InputLogic → RichInputConnection.commitText or sendKeyEvent → Host application
6. InputLogic → AudioAndHapticFeedbackManager.vibrate/playSound
7. Settings changes (via SettingsActivity) → PreferenceManager → LatinIME reloads config
8. XML layouts & themes loaded at startup / on configuration change

##### Architectural Patterns & Principles
- Separation of Concerns: UI rendering vs event detection vs input logic vs configuration
- Plug-in-style resource architecture: keyboard definitions & themes in XML → parsed by KeyboardBuilder
- Compatibility Layer: isolated helpers for Android version differences

##### Elements
– Clear component names (Android IME Framework, LatinIME Service, KeyboardView)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Android Framework
    subgraph "Android Framework & Services"
        AndroidSystem["Android IME Framework & Services"]:::blue
        VibratorService["VibratorService"]:::blue
        AudioManager["AudioManager"]:::blue
        InputConnectionAPI["InputConnection API"]:::blue
    end

    %% IME Service Layer
    subgraph "IME Service Layer"
        LatinIME["LatinIME (InputMethodService)"]:::green
        SystemBroadcastReceiver["SystemBroadcastReceiver"]:::green
        RichIMM["RichInputMethodManager"]:::green
    end

    %% UI Layer
    subgraph "UI Layer"
        KeyboardView["KeyboardView"]:::orange
        MainKeyboardView["MainKeyboardView"]:::orange
        MoreKeysKeyboardView["MoreKeysKeyboardView"]:::orange
        KeyPreviewView["KeyPreviewView"]:::orange
        DrawingProxy["DrawingProxy"]:::orange
    end

    %% Event Pipeline
    subgraph "Event Pipeline"
        Event["Event.java"]:::orange
        InputTransaction["InputTransaction.java"]:::orange
        KeyDetector["KeyDetector"]:::orange
        MoreKeysDetector["MoreKeysDetector"]:::orange
        ProximityInfo["ProximityInfo"]:::orange
        PointerTracker["PointerTracker"]:::orange
        BogusMoveEventDetector["BogusMoveEventDetector"]:::orange
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        InputLogic["InputLogic"]:::green
        AudioHaptic["AudioAndHapticFeedbackManager"]:::green
    end

    %% Configuration & Resource Layer
    subgraph "Config & Resource Layer"
        SettingsActivity["SettingsActivity"]:::yellow
        PrefCompat["PreferenceManagerCompat"]:::yellow
        PrefsXML["prefs.xml"]:::yellow
        XMLResources["XML Resources (layouts, keyboards, themes)"]:::yellow
    end

    %% Host App
    HostApp["Host Application"]:::blue

    %% Flows
    AndroidSystem -->|"bindService/onTouchEvent"| LatinIME
    LatinIME -->|"dispatchTouch ->"| Event
    Event -->|"startTransaction"| InputTransaction
    InputTransaction -->|"detectKey"| KeyDetector
    KeyDetector -->|"detectMoreKeys"| MoreKeysDetector
    KeyDetector -->|"useProximity"| ProximityInfo
    KeyDetector -->|"trackPointers"| PointerTracker
    Event -->|"filterBogus"| BogusMoveEventDetector
    KeyDetector -->|"sendTo"| LatinIME
    LatinIME -->|"onKey ->"| InputLogic
    InputLogic -->|"commitText/sendKeyEvent via"| InputConnectionAPI
    InputLogic -->|"provideFeedback"| AudioHaptic
    AudioHaptic -->|"vibrate"| VibratorService
    AudioHaptic -->|"playSound"| AudioManager
    SettingsActivity -->|"savePrefs"| PrefCompat
    PrefCompat -->|"update ->"| LatinIME
    XMLResources -->|"load at startup/config change"| LatinIME
    XMLResources -->|"build UI"| KeyboardView
    KeyboardView -->|renders| MainKeyboardView
    MainKeyboardView -->|handles more keys| MoreKeysKeyboardView
    KeyPreviewView -->|shows preview| KeyboardView
    DrawingProxy -->|draws UI| KeyboardView
    InputLogic -->|text to| HostApp

    %% Click Events
    click AndroidSystem "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/AndroidManifest.xml"
    click LatinIME "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/LatinIME.java"
    click SystemBroadcastReceiver "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/SystemBroadcastReceiver.java"
    click RichIMM "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/RichInputMethodManager.java"
    click KeyboardView "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardView.java"
    click MainKeyboardView "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/MainKeyboardView.java"
    click MoreKeysKeyboardView "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/MoreKeysKeyboardView.java"
    click KeyPreviewView "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyPreviewView.java"
    click DrawingProxy "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/DrawingProxy.java"
    click Event "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/event/Event.java"
    click InputTransaction "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/event/InputTransaction.java"
    click KeyDetector "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyDetector.java"
    click MoreKeysDetector "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/MoreKeysDetector.java"
    click ProximityInfo "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/ProximityInfo.java"
    click PointerTracker "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/PointerTracker.java"
    click BogusMoveEventDetector "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/BogusMoveEventDetector.java"
    click InputLogic "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/inputlogic/InputLogic.java"
    click AudioHaptic "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/AudioAndHapticFeedbackManager.java"
    click SettingsActivity "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/settings/SettingsActivity.java"
    click PrefCompat "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/compat/PreferenceManagerCompat.java"
    click PrefsXML "https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/res/xml/prefs.xml"

    %% Styles
    classDef blue fill:#E8F1FA,stroke:#36A,stroke-width:1px
    classDef green fill:#E8FAE8,stroke:#2A7,stroke-width:1px
    classDef orange fill:#FFE8BA,stroke:#E68A00,stroke-width:1px
    classDef yellow fill:#FEF5BA,stroke:#CE9E00,stroke-width:1px
```
