mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 11:05:59 +00:00
Bugfix and new APIs
Fix permitted accessibility services and permitted ime, close #165 New APIs, close #166 Optimize shortcuts creation, add ShortcutUtils
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
package com.bintianqi.owndroid
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.core.content.pm.ShortcutInfoCompat
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import android.util.Log
|
||||
|
||||
class ShortcutsReceiverActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -17,50 +13,24 @@ class ShortcutsReceiverActivity : Activity() {
|
||||
when (action) {
|
||||
"LOCK" -> Privilege.DPM.lockNow()
|
||||
"DISABLE_CAMERA" -> {
|
||||
Privilege.DPM.setCameraDisabled(Privilege.DAR, !Privilege.DPM.getCameraDisabled(Privilege.DAR))
|
||||
createShortcuts(this)
|
||||
val state = Privilege.DPM.getCameraDisabled(Privilege.DAR)
|
||||
Privilege.DPM.setCameraDisabled(Privilege.DAR, !state)
|
||||
ShortcutUtils.setShortcut(this, MyShortcut.DisableCamera, state)
|
||||
}
|
||||
"MUTE" -> {
|
||||
Privilege.DPM.setMasterVolumeMuted(Privilege.DAR, !Privilege.DPM.isMasterVolumeMuted(Privilege.DAR))
|
||||
createShortcuts(this)
|
||||
val state = Privilege.DPM.isMasterVolumeMuted(Privilege.DAR)
|
||||
Privilege.DPM.setMasterVolumeMuted(Privilege.DAR, !state)
|
||||
ShortcutUtils.setShortcut(this, MyShortcut.Mute, state)
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Received intent: $action")
|
||||
showOperationResultToast(true)
|
||||
}
|
||||
} finally {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createShortcuts(context: Context) {
|
||||
if (!SP.shortcuts) return
|
||||
val action = "com.bintianqi.owndroid.action"
|
||||
val baseIntent = Intent(context, ShortcutsReceiverActivity::class.java)
|
||||
val cameraDisabled = Privilege.DPM.getCameraDisabled(Privilege.DAR)
|
||||
val muted = Privilege.DPM.isMasterVolumeMuted(Privilege.DAR)
|
||||
val list = listOf(
|
||||
ShortcutInfoCompat.Builder(context, "LOCK")
|
||||
.setIcon(IconCompat.createWithResource(context, R.drawable.screen_lock_portrait_fill0))
|
||||
.setShortLabel(context.getString(R.string.lock_screen))
|
||||
.setIntent(Intent(baseIntent).setAction("$action.LOCK")),
|
||||
ShortcutInfoCompat.Builder(context, "DISABLE_CAMERA")
|
||||
.setIcon(
|
||||
IconCompat.createWithResource(
|
||||
context,
|
||||
if (cameraDisabled) R.drawable.photo_camera_fill0 else R.drawable.no_photography_fill0
|
||||
)
|
||||
)
|
||||
.setShortLabel(context.getString(if (cameraDisabled) R.string.enable_camera else R.string.disable_cam))
|
||||
.setIntent(Intent(baseIntent).setAction("$action.DISABLE_CAMERA")),
|
||||
ShortcutInfoCompat.Builder(context, "MUTE")
|
||||
.setIcon(
|
||||
IconCompat.createWithResource(
|
||||
context,
|
||||
if (muted) R.drawable.volume_up_fill0 else R.drawable.volume_off_fill0
|
||||
)
|
||||
)
|
||||
.setShortLabel(context.getString(if (muted) R.string.unmute else R.string.mute))
|
||||
.setIntent(Intent(baseIntent).setAction("$action.MUTE"))
|
||||
)
|
||||
ShortcutManagerCompat.setDynamicShortcuts(context, list.map { it.build() })
|
||||
companion object {
|
||||
private const val TAG = "ShortcutsReceiver"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user