From 47f3a6333047e4386ec818fd338d5764a487a864 Mon Sep 17 00:00:00 2001 From: GuoXiCheng <1377994267@qq.com> Date: Tue, 24 Oct 2023 22:38:26 +0800 Subject: [PATCH] update handler --- .../com/android/skip/handler/BoundsHandler.kt | 1 - .../com/android/skip/handler/IdNodeHandler.kt | 22 ++++++++++++++++++- .../android/skip/handler/TextNodeHandler.kt | 7 ++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/android/skip/handler/BoundsHandler.kt b/app/src/main/java/com/android/skip/handler/BoundsHandler.kt index 4acb7d03..534cf4b4 100644 --- a/app/src/main/java/com/android/skip/handler/BoundsHandler.kt +++ b/app/src/main/java/com/android/skip/handler/BoundsHandler.kt @@ -25,7 +25,6 @@ class BoundsHandler: AbstractHandler() { for (i in 0 until node.childCount) { val result = traverseNode(node.getChild(i), rectList) if (result != null) { - LogManager.i(result.toShortString()) return result } } diff --git a/app/src/main/java/com/android/skip/handler/IdNodeHandler.kt b/app/src/main/java/com/android/skip/handler/IdNodeHandler.kt index 95530169..8adf9a97 100644 --- a/app/src/main/java/com/android/skip/handler/IdNodeHandler.kt +++ b/app/src/main/java/com/android/skip/handler/IdNodeHandler.kt @@ -8,14 +8,34 @@ class IdNodeHandler: AbstractHandler() { override fun handle(node: AccessibilityNodeInfo): List { val skipId = SkipConfigManager.getSkipId(node.packageName.toString()) ?: return super.handle(node) - val listOfRect = node.findAccessibilityNodeInfosByViewId(skipId).map { + val nodes = findAccessibilityNodeInfosContainsViewId(node, skipId) + val listOfRect = nodes.map { val rect = Rect() it.getBoundsInScreen(rect) rect } + nodes.forEach { it.recycle() } return listOfRect.ifEmpty { super.handle(node) } } + + private fun findAccessibilityNodeInfosContainsViewId(node: AccessibilityNodeInfo, viewId: String): MutableList { + val resultList = mutableListOf() + + dfs(node, viewId, resultList) + + return resultList + } + + private fun dfs(node: AccessibilityNodeInfo, viewId: String, resultList: MutableList) { + if (node.viewIdResourceName?.contains(viewId) == true) { + resultList.add(AccessibilityNodeInfo.obtain(node)) + } + + for (i in 0 until node.childCount) { + dfs(node.getChild(i), viewId, resultList) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/android/skip/handler/TextNodeHandler.kt b/app/src/main/java/com/android/skip/handler/TextNodeHandler.kt index f48cf672..8335207d 100644 --- a/app/src/main/java/com/android/skip/handler/TextNodeHandler.kt +++ b/app/src/main/java/com/android/skip/handler/TextNodeHandler.kt @@ -6,13 +6,16 @@ import com.android.skip.manager.SkipConfigManager class TextNodeHandler : AbstractHandler() { override fun handle(node: AccessibilityNodeInfo): List { - val listOfRect = node.findAccessibilityNodeInfosByText( + val nodes = node.findAccessibilityNodeInfosByText( SkipConfigManager.getSkipText(node.packageName.toString()) - ).map { + ) + val listOfRect = nodes.map { val rect = Rect() it.getBoundsInScreen(rect) rect } + nodes.forEach { it.recycle() } + return listOfRect.ifEmpty { super.handle(node) }