Files
SimplicityTools/app/src/main/java/com/lt2333/simplicitytools/tile/AllowScreenshots.kt
2022-03-21 19:45:26 +08:00

40 lines
1.2 KiB
Kotlin

package com.lt2333.simplicitytools.tile
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
class AllowScreenshots : TileService() {
val key = "disable_flag_secure"
override fun onClick() {
super.onClick()
try {
val pref = getSharedPreferences("config", MODE_WORLD_READABLE)
val prefEditor = pref.edit()
if (pref.getBoolean(key, false)) {
prefEditor.putBoolean(key, false)
qsTile.state = Tile.STATE_INACTIVE
} else {
prefEditor.putBoolean(key, true)
qsTile.state = Tile.STATE_ACTIVE
}
prefEditor.commit()
qsTile.updateTile()
} catch (e: SecurityException) {
}
}
override fun onStartListening() {
super.onStartListening()
try {
val pref = getSharedPreferences("config", MODE_WORLD_READABLE)
if (pref.getBoolean(key, false)) {
qsTile.state = Tile.STATE_ACTIVE
} else {
qsTile.state = Tile.STATE_INACTIVE
}
qsTile.updateTile()
} catch (e: SecurityException) {
}
}
}