-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a quick settings tile to toggle Voice Notify (#140)
Add a quick settings tile to toggle Voice Notify Adds a quick settings tile (TileService) that displays the current state of Voice Notify. Clicking on the tile toggles Voice Notify. Long-pressing the tile opens the main screen of Voice Notify.
- Loading branch information
1 parent
5e2ac5b
commit af7d553
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/pilot51/voicenotify/VoiceNotifyTileService.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.pilot51.voicenotify | ||
|
||
import android.os.Build | ||
import android.service.quicksettings.Tile | ||
import android.service.quicksettings.TileService | ||
import androidx.annotation.RequiresApi | ||
|
||
@RequiresApi(Build.VERSION_CODES.N) | ||
class VoiceNotifyTileService : TileService() { | ||
// Called when the tile can be updated | ||
override fun onStartListening() { | ||
super.onStartListening() | ||
updateTile(Service.isSuspended.value) | ||
} | ||
|
||
// Called when the user taps on the tile in an active or inactive state. | ||
override fun onClick() { | ||
super.onClick() | ||
val isSuspended = Service.toggleSuspend() | ||
updateTile(isSuspended) | ||
} | ||
|
||
private fun updateTile(suspended: Boolean) { | ||
val isRunning = Service.isRunning.value | ||
|
||
qsTile.state = when { | ||
!isRunning -> Tile.STATE_UNAVAILABLE | ||
isRunning && suspended -> Tile.STATE_INACTIVE | ||
else -> Tile.STATE_ACTIVE | ||
} | ||
qsTile.updateTile() | ||
} | ||
} |