Skip to content

Add flashlight timer - #149

Open
mgdx wants to merge 1 commit into
cyb3rko:mainfrom
mgdx:feature_timer
Open

Add flashlight timer#149
mgdx wants to merge 1 commit into
cyb3rko:mainfrom
mgdx:feature_timer

Conversation

@mgdx

@mgdx mgdx commented Aug 6, 2026

Copy link
Copy Markdown

Summary

Adds a timer to the quick actions: pick a duration, the flashlight turns on and
switches itself off when the timer runs out — even if the app is closed in the
meantime.

The countdown is owned by a foreground service (TimerService) so it survives
the activity being destroyed. Responsibilities are split deliberately:

  • MainActivity switches the light on, since it owns the light level and the
    matching UI (seekbar, level indicator);
  • TimerService counts down and switches the light off again.

Every stop path — timer expired, "Stop" in the dialog, "Stop" in the notification,
"Off" button, morse/SOS mode — ends up in the same place, which then reports back
to the UI through a single callback.

Changes

  • New TimerService, TimerDialog, dialog_timer.xml and ic_timer.xml.
  • New "Timer" button in the quick actions, added to all three activity_main.xml
    variants (default, sw600dp, sw900dp).
  • The notification is LOW priority, ongoing, opens the app when tapped and
    carries a "Stop" action. The remaining time is rendered by the system
    (setUsesChronometer + setChronometerCountDown), so the service does not wake
    up to redraw it.

Manifest / permissions

  • Added FOREGROUND_SERVICE, FOREGROUND_SERVICE_SPECIAL_USE and
    POST_NOTIFICATIONS.
  • TimerService is declared as specialUse — there is no dedicated foreground
    service type for the flashlight — together with the
    PROPERTY_SPECIAL_USE_FGS_SUBTYPE property that Android 14+ requires.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant