Skip to content

Commit

Permalink
Merge pull request #66 from GuoXiCheng/dev
Browse files Browse the repository at this point in the history
update handler
  • Loading branch information
GuoXiCheng authored Oct 24, 2023
2 parents 882e6d5 + 47f3a63 commit c984389
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/java/com/android/skip/handler/IdNodeHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,34 @@ class IdNodeHandler: AbstractHandler() {
override fun handle(node: AccessibilityNodeInfo): List<Rect> {
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<AccessibilityNodeInfo> {
val resultList = mutableListOf<AccessibilityNodeInfo>()

dfs(node, viewId, resultList)

return resultList
}

private fun dfs(node: AccessibilityNodeInfo, viewId: String, resultList: MutableList<AccessibilityNodeInfo>) {
if (node.viewIdResourceName?.contains(viewId) == true) {
resultList.add(AccessibilityNodeInfo.obtain(node))
}

for (i in 0 until node.childCount) {
dfs(node.getChild(i), viewId, resultList)
}
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/com/android/skip/handler/TextNodeHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import com.android.skip.manager.SkipConfigManager

class TextNodeHandler : AbstractHandler() {
override fun handle(node: AccessibilityNodeInfo): List<Rect> {
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)
}
Expand Down

0 comments on commit c984389

Please sign in to comment.