> For the complete documentation index, see [llms.txt](https://bitboy-1.gitbook.io/bitboy-os-development-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bitboy-1.gitbook.io/bitboy-os-development-guide/getting-started/introduction/introduction-to-bitboy-os/application-development.md).

# Application development

## BitBoy OS supports two types of application development:&#x20;

* **Native Android applications (APK)**&#x20;

  Android applications provide comprehensive system functionality access and optimized performance, suitable for complex games and tools;&#x20;
* **HTML applications.**&#x20;

  HTML applications offer cross-platform compatibility and rapid development advantages, ideal for simple interfaces and lightweight applications. Developers can choose the appropriate development method based on project requirements and technology stack.

## Design Guidelines&#x20;

### UI Design Principles

* Adapt to 640x480 resolution

### Color Guidelines

### Typography&#x20;

* **System Fonts**

  <mark style="color:red;">系统字体</mark>
* **Recommended Font Sizes**

  <mark style="color:red;">建议字号</mark>

### Icon Design

* **Dimensions:**&#x20;

  48x48dp, 72x72dp, 96x96dp
* **Style:**&#x20;

  Flat, minimalist

&#x20;\[<mark style="color:red;">TODO: Add more design specifications and examples</mark>]

## Physical Button Development&#x20;

### BitBoy OS Button Mapping Tools

BitBoy OS SDK provides two core classes for handling physical button mapping: **KeyEventHelper** and **KeyEventActivity**.

#### KeyEventHelper&#x20;

For handling buttons in specific Views:

```kotlin
val keyEventHelper = KeyEventHelper(
    onPress = { code, view -> /* Handle press */ },
    onLongPress = { code, view -> /* Handle long press */ },
    KEY_A, KEY_X, KEY_Y
)
yourView.setOnKeyListener(keyEventHelper)
```

#### KeyEventActivity&#x20;

Base class for global button handling:

```kotlin
class YourActivity : KeyEventActivity() {
    override fun onKeyA() { /* A button press */ }
    override fun onLongKeyA() { /* A button long press */ }
    // Other button methods...
}
```

### Key Features

* Supports press and long-press events
* Predefined common button codes (A, B, X, Y, etc.)
* Day/Night mode switching support
* Customizable button responses

{% hint style="warning" %}
Important Notes

* Default long-press duration is 300ms
* Clear button states in onPause
* Some buttons (like HOME) are disabled by default
  {% endhint %}

### Key Mapping

| Button        | KeyCode                       | Description                      |
| ------------- | ----------------------------- | -------------------------------- |
| A             | KEY\_A / KEY\_GAME\_A         | Confirm / Start                  |
| B             | KEY\_B / KEY\_GAME\_B         | Cancel / Back                    |
| X             | KEY\_X                        | Function 1                       |
| Y             | KEY\_Y                        | Function 2                       |
| Up            | KeyEvent.KEYCODE\_DPAD\_UP    | Up                               |
| Down          | KeyEvent.KEYCODE\_DPAD\_DOWN  | Down                             |
| Left          | KeyEvent.KEYCODE\_DPAD\_LEFT  | Left                             |
| Right         | KeyEvent.KEYCODE\_DPAD\_RIGHT | Right                            |
| L             | KEY\_BACK\_LEFT               | Left shoulder button             |
| R             | KEY\_BACK\_RIGHT              | Right shoulder button            |
| Start         | KEY\_START                    | Start (same as A button)         |
| Select        | KEY\_SELECT                   | Select                           |
| Center button | KEY\_MID\_F                   | Center button (same as B button) |

## Performance Optimization Tips&#x20;

### Graphics Optimization

* Use hardware acceleration
* Minimize transparency usage
* Optimize drawing hierarchy

### Memory Management

* Use SparseArray instead of HashMap
* Release unused resources promptly
* Avoid memory leaks

### Battery Optimization

* Use JobScheduler for background tasks
* Reduce network request frequency
* Optimize Wake Lock usage

&#x20;<mark style="color:red;">\[TODO: Add more performance optimization tips and tool usage guides]</mark>

## Debugging and Testing<br>

### &#x20;Using BitBoy Emulator (in development):

* Download link: \[<mark style="color:red;">Emulator download link</mark>]
* Configuration guide: \[<mark style="color:red;">Configuration doc link</mark>]

### Physical Device Debugging:

* Enable developer options
* Connect device using ADB

### Performance Analysis Tools:

* Using Android Profiler
* BitBoy performance monitoring tools
