Skip to content

MelchnerRoman/SleepButton

Repository files navigation

🌙 Sleep Button – Android App

A persistent floating button that puts your screen to sleep (locks it) instantly with one tap. Works on top of all other apps. Draggable. Snaps to screen edges.

Built for Android head units / car radios / car stereos (aftermarket double-DIN units, Android Auto boxes, etc.): their displays often stay at full brightness at night with no easy way to just turn the screen off, so this puts a one-tap "sleep" / screen-off button always on top.

Keywords: android screen lock, screen off button, car radio dimmer, head unit night mode, floating overlay button, android auto screen off, double-DIN screen lock, car stereo brightness fix.


Download

Grab the latest APK from Releases — no need to build it yourself. Sideload it (enable "install from unknown sources" if prompted).


Features

  • Floating moon button – always visible, overlays every app
  • Drag & snap – drag anywhere, snaps to left/right edge on release
  • Tap to sleep – single tap locks/sleeps screen immediately
  • Haptic feedback – subtle vibration confirms the tap
  • Persistent service – survives app switching; notification with quick Stop action
  • Auto-start on boot – if both permissions are already granted, the button comes back automatically after the head unit reboots
  • Dark space UI – minimal setup screen

Requirements

  • Android 8.0+ (API 26+)
  • Two one-time permissions (no root, no Device Admin):
    1. Draw Over Other Apps – for the floating overlay
    2. Accessibility Service – to call lockScreen() system action

Build Instructions

Android Studio (recommended)

  1. Open Android Studio → File → Open → select the SleepButton folder
  2. Wait for Gradle sync to complete
  3. Connect your Android device (USB debugging on) or start an emulator
  4. Press Run ▶

Command line

cd SleepButton
./gradlew assembleDebug
# APK: app/build/outputs/apk/debug/app-debug.apk
adb install app/build/outputs/apk/debug/app-debug.apk

First-time Setup (in the app)

  1. Grant "Draw Over Other Apps" → tap Grant → toggle the app on → back
  2. Grant Accessibility → tap Grant → find "Sleep Button – Screen Lock" → enable it → back
  3. Tap Start Floating Button
  4. The 🌙 button appears – tap it to sleep, drag it to move

Project Structure

app/src/main/
├── AndroidManifest.xml
├── java/com/sleepbutton/app/
│   ├── MainActivity.kt          ← Setup & permission UI
│   ├── FloatingButtonService.kt ← Foreground service + overlay button
│   └── LockScreenService.kt     ← Accessibility service (screen lock)
└── res/
    ├── layout/
    │   ├── activity_main.xml
    │   └── layout_float_button.xml
    ├── drawable/
    │   ├── ic_sleep.xml          ← Moon icon (vector)
    │   └── bg_float_button.xml   ← Circular button background
    ├── xml/
    │   └── accessibility_service_config.xml
    └── values/
        ├── strings.xml
        └── themes.xml

How the screen lock works

This app uses Android's Accessibility Service API:

performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN)

This is the same mechanism used by many assistive apps to lock the screen without requiring Device Administrator privileges. No user data is accessed.


Customization tips

What Where
Button size layout_float_button.xml – change 56dp
Button color bg_float_button.xml – change #CC1A1A2E / #4FC3F7
Starting position FloatingButtonService.kt – change params.y = 300
Disable snap-to-edge Remove snapToEdge() call in ACTION_UP
Disable vibration Remove vibrate() call in ACTION_UP

License

GPL-3.0 – see LICENSE.

About

One-tap floating button that locks/sleeps the screen instantly — built for Android car radios & head units that stay too bright at night.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages