Skip to content

Commit

Permalink
Add a quick settings tile to toggle Voice Notify (#140)
Browse files Browse the repository at this point in the history
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
thezeroalpha authored Sep 21, 2024
1 parent 5e2ac5b commit af7d553
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -51,6 +52,18 @@
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<service
android:name=".VoiceNotifyTileService"
android:exported="true"
android:label="@string/app_name"
android:icon="@drawable/widget"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<meta-data android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true" />
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<receiver
android:name=".AppWidgetReceiver"
android:exported="true">
Expand Down
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()
}
}

0 comments on commit af7d553

Please sign in to comment.