拓展无障碍事件回调参数

This commit is contained in:
抠脚本人
2023-07-11 00:29:11 +08:00
parent a59b46fd6e
commit 392a4b953d
3 changed files with 21 additions and 15 deletions

View File

@@ -56,9 +56,7 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
} }
override fun onAccessibilityEvent(event: AccessibilityEvent) { override fun onAccessibilityEvent(event: AccessibilityEvent) {
if (instance != this) { if (instance != this) instance = this
instance = this
}
val type = event.eventType val type = event.eventType
eventBox[type]?.onAccessibilityEvent(AccessibilityEventWrapper(event)) eventBox[type]?.onAccessibilityEvent(AccessibilityEventWrapper(event))
if (containsAllEventTypes || eventTypes.contains(type)) { if (containsAllEventTypes || eventTypes.contains(type)) {

View File

@@ -1,27 +1,35 @@
package org.autojs.autojs.core.automator package org.autojs.autojs.core.automator
import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
class AccessibilityEventWrapper(event: AccessibilityEvent) { class AccessibilityEventWrapper(event: AccessibilityEvent) {
private val node = event.source val raw = event
val packageName: CharSequence? = event.packageName
val eventType = event.eventType
val eventTime = event.eventTime
val action = event.action
val isFullScreen = event.isFullScreen
val className = event.className
val source = event.source?.let { UiObject(it, getDepth(it), getIndexInParent(it)) }
val source = if (node != null) UiObject(node, null, getDepth(), getIndexInParent()) else null private fun getDepth(node: AccessibilityNodeInfo): Int {
private fun getDepth(): Int {
var depth = 0 var depth = 0
if (node == null) return 0 var father = node.parent
while (node.parent != null) { while (father != null) {
depth++ depth++
father = father.parent
} }
return depth return depth
} }
private fun getIndexInParent(): Int { private fun getIndexInParent(node: AccessibilityNodeInfo): Int {
val parent = node!!.parent
var index = 0 var index = 0
val parent = node.parent ?: return 0
while (parent.getChild(index) != node) { while (parent.getChild(index) != node) {
index++ index++
} }
return index return index
} }
} }

View File

@@ -1,8 +1,8 @@
#Mon Jul 10 18:23:10 CST 2023 #Tue Jul 11 00:23:06 CST 2023
BUILD_TIME=1688984590330 BUILD_TIME=1689006186217
COMPILE_SDK_VERSION=33 COMPILE_SDK_VERSION=33
JAVA_VERSION=20 JAVA_VERSION=20
MIN_SDK_VERSION=24 MIN_SDK_VERSION=24
TARGET_SDK_VERSION=33 TARGET_SDK_VERSION=33
VERSION_BUILD=2006 VERSION_BUILD=2010
VERSION_NAME=6.3.2 VERSION_NAME=6.3.2