Add flashlight timer - #149
Open
mgdx wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 survivesthe activity being destroyed. Responsibilities are split deliberately:
MainActivityswitches the light on, since it owns the light level and thematching UI (seekbar, level indicator);
TimerServicecounts 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
TimerService,TimerDialog,dialog_timer.xmlandic_timer.xml.activity_main.xmlvariants (default,
sw600dp,sw900dp).LOWpriority, ongoing, opens the app when tapped andcarries a "Stop" action. The remaining time is rendered by the system
(
setUsesChronometer+setChronometerCountDown), so the service does not wakeup to redraw it.
Manifest / permissions
FOREGROUND_SERVICE,FOREGROUND_SERVICE_SPECIAL_USEandPOST_NOTIFICATIONS.TimerServiceis declared asspecialUse— there is no dedicated foregroundservice type for the flashlight — together with the
PROPERTY_SPECIAL_USE_FGS_SUBTYPEproperty that Android 14+ requires.