Skip to content

Commit

Permalink
Make the tile more responsive
Browse files Browse the repository at this point in the history
Will clean-up / refactor a little after some initial testing.
  • Loading branch information
pcolby committed Jun 20, 2024
1 parent 6c0b819 commit 45c3c6d
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,20 @@ class NfcTileService : TileService() {
Log.i(TAG, "Have WRITE_SECURE_SETTINGS permission")
val adapter: NfcAdapter? = NfcAdapter.getDefaultAdapter(this)
adapter?.apply {
val wasEnabled = adapter.isEnabled
val methodName = if (adapter.isEnabled) "disable" else "enable"
try {
Log.d(TAG, "Invoking NfcAdapter::$methodName()")
val result = NfcAdapter::class.java.getMethod(methodName).invoke(adapter)
Log.d(TAG, "NfcAdapter::$methodName() returned $result")
qsTile?.apply {
Log.d(TAG, "Updating tile")
state = if (!wasEnabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
if (SDK_INT >= Build.VERSION_CODES.Q) subtitle = getText(
if (!wasEnabled) string.tile_subtitle_active else string.tile_subtitle_inactive
)
updateTile()
}
if (result is Boolean && result) return // Success; return early.
} catch (e: Exception) {
Log.e(TAG, "Failed to invoke NfcAdapter::$methodName()", e)
Expand Down

0 comments on commit 45c3c6d

Please sign in to comment.