port for material expressive
This commit is contained in:
parent
bf6e2f60cb
commit
a017d1e27f
|
@ -2,21 +2,13 @@ package rip.min.digica.service
|
|||
|
||||
import android.accessibilityservice.AccessibilityService
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.ActivityManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Handler
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.SurfaceControl
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import androidx.core.util.forEach
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Calendar
|
||||
import kotlin.toString
|
||||
|
||||
@SuppressLint("AccessibilityPolicy")
|
||||
class DigicaService : AccessibilityService() {
|
||||
|
@ -40,8 +32,6 @@ class DigicaService : AccessibilityService() {
|
|||
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
|
||||
if (event == null || event.packageName == null) return
|
||||
|
||||
Log.d("DigicaService", "$event")
|
||||
|
||||
// Get time
|
||||
val cal = Calendar.getInstance()
|
||||
val day = cal.get(Calendar.DAY_OF_WEEK)
|
||||
|
@ -85,10 +75,15 @@ class DigicaService : AccessibilityService() {
|
|||
// Check if the last app info page visited was this app's
|
||||
if (pkgName == "com.android.settings"
|
||||
&& className == "com.android.settings.spa.SpaActivity"
|
||||
&& commonSettingsRoot?.childCount == 1
|
||||
) {
|
||||
val settingsText = when (commonSettingsRoot?.childCount) {
|
||||
// Material Expressive
|
||||
0 -> commonSettingsRoot.text
|
||||
1 -> commonSettingsRoot.getChild(0).text
|
||||
else -> null
|
||||
}
|
||||
wasLastViewingThisAppInfo =
|
||||
commonSettingsRoot.getChild(0)?.text.toString() == appLabel
|
||||
settingsText?.toString() == appLabel
|
||||
}
|
||||
|
||||
// Is user trying to uninstall this app?
|
||||
|
@ -98,7 +93,8 @@ class DigicaService : AccessibilityService() {
|
|||
|
||||
// Is user trying to disable the service?
|
||||
val attemptingDisableService = pkgName == "com.android.settings"
|
||||
&& className == "android.app.AlertDialog"
|
||||
&& (className == "android.app.AlertDialog"
|
||||
|| className == "androidx.appcompat.app.AlertDialog")
|
||||
&& event.text.size == 3
|
||||
&& event.text[0].contains(serviceLabel)
|
||||
|
||||
|
@ -123,6 +119,13 @@ class DigicaService : AccessibilityService() {
|
|||
}
|
||||
}
|
||||
|
||||
// fun printTree(node: AccessibilityNodeInfo, depth: Int) {
|
||||
// Log.d("DigicaService", "${"=".repeat(depth)}> text ${node.text}")
|
||||
// for (i in 0 until node.childCount) {
|
||||
// printTree(node.getChild(i), depth + 1)
|
||||
// }
|
||||
// }
|
||||
|
||||
fun leaveDelayed(delayMillis: Long) {
|
||||
Handler(mainLooper).postDelayed({
|
||||
performGlobalAction(GLOBAL_ACTION_BACK)
|
||||
|
|
Loading…
Reference in New Issue