|
@@ -70,9 +70,14 @@ object AccessibilityUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//编辑EditView(粘贴 不推荐)
|
|
//编辑EditView(粘贴 不推荐)
|
|
|
- fun sendTextForEditText(context: Context, nodeInfo: AccessibilityNodeInfo?, text: String): Boolean {
|
|
|
|
|
|
|
+ fun sendTextForEditText(
|
|
|
|
|
+ context: Context,
|
|
|
|
|
+ nodeInfo: AccessibilityNodeInfo?,
|
|
|
|
|
+ text: String
|
|
|
|
|
+ ): Boolean {
|
|
|
val nodeInfo: AccessibilityNodeInfo = nodeInfo ?: return false
|
|
val nodeInfo: AccessibilityNodeInfo = nodeInfo ?: return false
|
|
|
- val clipboard: ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
|
|
|
|
|
+ val clipboard: ClipboardManager =
|
|
|
|
|
+ context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
|
val clip = ClipData.newPlainText("text", text)
|
|
val clip = ClipData.newPlainText("text", text)
|
|
|
clipboard.setPrimaryClip(clip)
|
|
clipboard.setPrimaryClip(clip)
|
|
|
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_FOCUS)
|
|
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_FOCUS)
|
|
@@ -93,31 +98,42 @@ object AccessibilityUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//寻找第一个文本匹配(关键词)并点击
|
|
//寻找第一个文本匹配(关键词)并点击
|
|
|
- fun findTextAndClick(nodeInfo: AccessibilityNodeInfo?,
|
|
|
|
|
|
|
+ fun findTextAndClick(
|
|
|
|
|
+ nodeInfo: AccessibilityNodeInfo?,
|
|
|
vararg textList: String,
|
|
vararg textList: String,
|
|
|
exact: Boolean = false,
|
|
exact: Boolean = false,
|
|
|
timeout: Long = 5000,
|
|
timeout: Long = 5000,
|
|
|
root: Boolean = true
|
|
root: Boolean = true
|
|
|
): Boolean {
|
|
): Boolean {
|
|
|
- val textView = findOneByText(nodeInfo, *textList, exact = exact, timeout = timeout, root = root) ?: return false
|
|
|
|
|
|
|
+ val textView =
|
|
|
|
|
+ findOneByText(nodeInfo, *textList, exact = exact, timeout = timeout, root = root)
|
|
|
|
|
+ ?: return false
|
|
|
performClick(textView)
|
|
performClick(textView)
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//寻找第一个描述匹配(关键词)并点击
|
|
//寻找第一个描述匹配(关键词)并点击
|
|
|
- fun findDescAndClick(nodeInfo: AccessibilityNodeInfo?,
|
|
|
|
|
- vararg textList: String,
|
|
|
|
|
- exact: Boolean = false,
|
|
|
|
|
- timeout: Long = 5000,
|
|
|
|
|
- root: Boolean = true
|
|
|
|
|
|
|
+ fun findDescAndClick(
|
|
|
|
|
+ nodeInfo: AccessibilityNodeInfo?,
|
|
|
|
|
+ vararg textList: String,
|
|
|
|
|
+ exact: Boolean = false,
|
|
|
|
|
+ timeout: Long = 5000,
|
|
|
|
|
+ root: Boolean = true
|
|
|
): Boolean {
|
|
): Boolean {
|
|
|
- val textView = findOneByDesc(nodeInfo, *textList, exact = exact, timeout = timeout, root = root) ?: return false
|
|
|
|
|
|
|
+ val textView =
|
|
|
|
|
+ findOneByDesc(nodeInfo, *textList, exact = exact, timeout = timeout, root = root)
|
|
|
|
|
+ ?: return false
|
|
|
performClick(textView)
|
|
performClick(textView)
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//寻找第一个EditView编辑框并输入文本
|
|
//寻找第一个EditView编辑框并输入文本
|
|
|
- fun findTextInput(nodeInfo: AccessibilityNodeInfo?, text: String, root: Boolean = true, append: Boolean = false): Boolean {
|
|
|
|
|
|
|
+ fun findTextInput(
|
|
|
|
|
+ nodeInfo: AccessibilityNodeInfo?,
|
|
|
|
|
+ text: String,
|
|
|
|
|
+ root: Boolean = true,
|
|
|
|
|
+ append: Boolean = false
|
|
|
|
|
+ ): Boolean {
|
|
|
val editText = if (root) {
|
|
val editText = if (root) {
|
|
|
findOneByClazz(nodeInfo, "android.widget.EditText") ?: return false
|
|
findOneByClazz(nodeInfo, "android.widget.EditText") ?: return false
|
|
|
} else {
|
|
} else {
|
|
@@ -137,7 +153,11 @@ object AccessibilityUtil {
|
|
|
|
|
|
|
|
//寻找第一个列表并点击指定条目(默认点击第一个条目)
|
|
//寻找第一个列表并点击指定条目(默认点击第一个条目)
|
|
|
fun findListOneAndClick(nodeInfo: AccessibilityNodeInfo, index: Int = 0): Boolean {
|
|
fun findListOneAndClick(nodeInfo: AccessibilityNodeInfo, index: Int = 0): Boolean {
|
|
|
- val list = findOnceByClazz(nodeInfo, "androidx.recyclerview.widget.RecyclerView", "android.widget.ListView")
|
|
|
|
|
|
|
+ val list = findOnceByClazz(
|
|
|
|
|
+ nodeInfo,
|
|
|
|
|
+ "androidx.recyclerview.widget.RecyclerView",
|
|
|
|
|
+ "android.widget.ListView"
|
|
|
|
|
+ )
|
|
|
if (list != null && list.childCount > index) {
|
|
if (list != null && list.childCount > index) {
|
|
|
return performClick(list.getChild(index))
|
|
return performClick(list.getChild(index))
|
|
|
}
|
|
}
|
|
@@ -408,6 +428,20 @@ object AccessibilityUtil {
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 对某个节点或子节点进行长按
|
|
|
|
|
+ */
|
|
|
|
|
+ fun performLongClickWithSon2(nodeInfo: AccessibilityNodeInfo?): Boolean {
|
|
|
|
|
+ var nodeInfo: AccessibilityNodeInfo? = nodeInfo ?: return false
|
|
|
|
|
+ if (nodeInfo != null) {
|
|
|
|
|
+// nodeInfo.performAction(AccessibilityNodeInfo.ACTION_LONG_CLICK)
|
|
|
|
|
+ longClickByNode(WeworkController.weworkService, nodeInfo)
|
|
|
|
|
+ LogUtils.d("performLongClickWithSon: text: ${nodeInfo.text} desc: ${nodeInfo.contentDescription}")
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//对某个节点向上滚动
|
|
//对某个节点向上滚动
|
|
|
fun performScrollUp(nodeInfo: AccessibilityNodeInfo?): Boolean {
|
|
fun performScrollUp(nodeInfo: AccessibilityNodeInfo?): Boolean {
|
|
|
var nodeInfo: AccessibilityNodeInfo? = nodeInfo ?: return false
|
|
var nodeInfo: AccessibilityNodeInfo? = nodeInfo ?: return false
|
|
@@ -537,7 +571,14 @@ object AccessibilityUtil {
|
|
|
timeout: Long = 5000,
|
|
timeout: Long = 5000,
|
|
|
root: Boolean = true
|
|
root: Boolean = true
|
|
|
): AccessibilityNodeInfo? {
|
|
): AccessibilityNodeInfo? {
|
|
|
- return findOneByText(node, *textList, exact = exact, timeout = timeout, root = root, desc = true)
|
|
|
|
|
|
|
+ return findOneByText(
|
|
|
|
|
+ node,
|
|
|
|
|
+ *textList,
|
|
|
|
|
+ exact = exact,
|
|
|
|
|
+ timeout = timeout,
|
|
|
|
|
+ root = root,
|
|
|
|
|
+ desc = true
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -571,7 +612,15 @@ object AccessibilityUtil {
|
|
|
root: Boolean = true,
|
|
root: Boolean = true,
|
|
|
minSize: Int = 1
|
|
minSize: Int = 1
|
|
|
): List<AccessibilityNodeInfo> {
|
|
): List<AccessibilityNodeInfo> {
|
|
|
- return findAllByText(node, *textList, exact = exact, timeout = timeout, root = root, minSize = minSize, desc = true)
|
|
|
|
|
|
|
+ return findAllByText(
|
|
|
|
|
+ node,
|
|
|
|
|
+ *textList,
|
|
|
|
|
+ exact = exact,
|
|
|
|
|
+ timeout = timeout,
|
|
|
|
|
+ root = root,
|
|
|
|
|
+ minSize = minSize,
|
|
|
|
|
+ desc = true
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -701,7 +750,10 @@ object AccessibilityUtil {
|
|
|
}
|
|
}
|
|
|
currentTime = System.currentTimeMillis()
|
|
currentTime = System.currentTimeMillis()
|
|
|
}
|
|
}
|
|
|
- Log.e(tag, "findOneByText ${if (desc) "desc" else "text"}: not found: ${textList.joinToString()}")
|
|
|
|
|
|
|
+ Log.e(
|
|
|
|
|
+ tag,
|
|
|
|
|
+ "findOneByText ${if (desc) "desc" else "text"}: not found: ${textList.joinToString()}"
|
|
|
|
|
+ )
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -773,7 +825,10 @@ object AccessibilityUtil {
|
|
|
}
|
|
}
|
|
|
currentTime = System.currentTimeMillis()
|
|
currentTime = System.currentTimeMillis()
|
|
|
}
|
|
}
|
|
|
- Log.e(tag, "findAllByText ${if (desc) "desc" else "text"}: not found: ${textList.joinToString()}")
|
|
|
|
|
|
|
+ Log.e(
|
|
|
|
|
+ tag,
|
|
|
|
|
+ "findAllByText ${if (desc) "desc" else "text"}: not found: ${textList.joinToString()}"
|
|
|
|
|
+ )
|
|
|
return arrayListOf()
|
|
return arrayListOf()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -888,7 +943,14 @@ object AccessibilityUtil {
|
|
|
val startTime = System.currentTimeMillis()
|
|
val startTime = System.currentTimeMillis()
|
|
|
var currentTime = startTime
|
|
var currentTime = startTime
|
|
|
while (currentTime - startTime <= timeout) {
|
|
while (currentTime - startTime <= timeout) {
|
|
|
- val result = findOnceByClazz(node, *clazzList, limitDepth = limitDepth, depth = depth, minChildCount = minChildCount, firstChildClazz = firstChildClazz)
|
|
|
|
|
|
|
+ val result = findOnceByClazz(
|
|
|
|
|
+ node,
|
|
|
|
|
+ *clazzList,
|
|
|
|
|
+ limitDepth = limitDepth,
|
|
|
|
|
+ depth = depth,
|
|
|
|
|
+ minChildCount = minChildCount,
|
|
|
|
|
+ firstChildClazz = firstChildClazz
|
|
|
|
|
+ )
|
|
|
LogUtils.v("clazz: ${clazzList.joinToString()} result == null: ${result == null}")
|
|
LogUtils.v("clazz: ${clazzList.joinToString()} result == null: ${result == null}")
|
|
|
if (result != null) return result
|
|
if (result != null) return result
|
|
|
sleep(SHORT_INTERVAL)
|
|
sleep(SHORT_INTERVAL)
|
|
@@ -923,13 +985,23 @@ object AccessibilityUtil {
|
|
|
if (node == null) return null
|
|
if (node == null) return null
|
|
|
if (node.className in clazzList) {
|
|
if (node.className in clazzList) {
|
|
|
if ((limitDepth == null || limitDepth == depth) && node.childCount >= minChildCount)
|
|
if ((limitDepth == null || limitDepth == depth) && node.childCount >= minChildCount)
|
|
|
- if (firstChildClazz == null || (node.childCount > 0 && firstChildClazz == node.getChild(0).className)) {
|
|
|
|
|
|
|
+ if (firstChildClazz == null || (node.childCount > 0 && firstChildClazz == node.getChild(
|
|
|
|
|
+ 0
|
|
|
|
|
+ ).className)
|
|
|
|
|
+ ) {
|
|
|
return node
|
|
return node
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
for (i in 0 until node.childCount) {
|
|
for (i in 0 until node.childCount) {
|
|
|
if (limitDepth == null || limitDepth > depth) {
|
|
if (limitDepth == null || limitDepth > depth) {
|
|
|
- val result = findOnceByClazz(node.getChild(i), *clazzList, limitDepth = limitDepth, depth = depth + 1, minChildCount = minChildCount, firstChildClazz = firstChildClazz)
|
|
|
|
|
|
|
+ val result = findOnceByClazz(
|
|
|
|
|
+ node.getChild(i),
|
|
|
|
|
+ *clazzList,
|
|
|
|
|
+ limitDepth = limitDepth,
|
|
|
|
|
+ depth = depth + 1,
|
|
|
|
|
+ minChildCount = minChildCount,
|
|
|
|
|
+ firstChildClazz = firstChildClazz
|
|
|
|
|
+ )
|
|
|
if (result != null) return result
|
|
if (result != null) return result
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -958,7 +1030,8 @@ object AccessibilityUtil {
|
|
|
val startTime = System.currentTimeMillis()
|
|
val startTime = System.currentTimeMillis()
|
|
|
var currentTime = startTime
|
|
var currentTime = startTime
|
|
|
while (currentTime - startTime <= timeout) {
|
|
while (currentTime - startTime <= timeout) {
|
|
|
- val result = findAllOnceByClazz(node, *clazzList, limitDepth = limitDepth, depth = depth)
|
|
|
|
|
|
|
+ val result =
|
|
|
|
|
+ findAllOnceByClazz(node, *clazzList, limitDepth = limitDepth, depth = depth)
|
|
|
LogUtils.v("clazz: ${clazzList.joinToString()} count: " + result.size)
|
|
LogUtils.v("clazz: ${clazzList.joinToString()} count: " + result.size)
|
|
|
if (result.size >= minSize) return result
|
|
if (result.size >= minSize) return result
|
|
|
sleep(SHORT_INTERVAL)
|
|
sleep(SHORT_INTERVAL)
|
|
@@ -988,10 +1061,18 @@ object AccessibilityUtil {
|
|
|
list: ArrayList<AccessibilityNodeInfo> = ArrayList()
|
|
list: ArrayList<AccessibilityNodeInfo> = ArrayList()
|
|
|
): ArrayList<AccessibilityNodeInfo> {
|
|
): ArrayList<AccessibilityNodeInfo> {
|
|
|
if (node == null) return list
|
|
if (node == null) return list
|
|
|
- if ((limitDepth == null || limitDepth == depth) && node.className in clazzList) list.add(node)
|
|
|
|
|
|
|
+ if ((limitDepth == null || limitDepth == depth) && node.className in clazzList) list.add(
|
|
|
|
|
+ node
|
|
|
|
|
+ )
|
|
|
for (i in 0 until node.childCount) {
|
|
for (i in 0 until node.childCount) {
|
|
|
if (limitDepth == null || limitDepth > depth) {
|
|
if (limitDepth == null || limitDepth > depth) {
|
|
|
- findAllOnceByClazz(node.getChild(i), *clazzList, limitDepth = limitDepth, depth = depth + 1, list = list)
|
|
|
|
|
|
|
+ findAllOnceByClazz(
|
|
|
|
|
+ node.getChild(i),
|
|
|
|
|
+ *clazzList,
|
|
|
|
|
+ limitDepth = limitDepth,
|
|
|
|
|
+ depth = depth + 1,
|
|
|
|
|
+ list = list
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return list
|
|
return list
|
|
@@ -1001,7 +1082,10 @@ object AccessibilityUtil {
|
|
|
* 查找节点的前兄弟节点 直到该节点满足子节点数
|
|
* 查找节点的前兄弟节点 直到该节点满足子节点数
|
|
|
* @param node 节点
|
|
* @param node 节点
|
|
|
*/
|
|
*/
|
|
|
- fun findFrontNode(node: AccessibilityNodeInfo?, minChildCount: Int = 0): AccessibilityNodeInfo? {
|
|
|
|
|
|
|
+ fun findFrontNode(
|
|
|
|
|
+ node: AccessibilityNodeInfo?,
|
|
|
|
|
+ minChildCount: Int = 0
|
|
|
|
|
+ ): AccessibilityNodeInfo? {
|
|
|
var findFrontNode = findFrontNode(node) ?: return null
|
|
var findFrontNode = findFrontNode(node) ?: return null
|
|
|
while (findFrontNode.childCount < minChildCount) {
|
|
while (findFrontNode.childCount < minChildCount) {
|
|
|
findFrontNode = findFrontNode(findFrontNode) ?: return null
|
|
findFrontNode = findFrontNode(findFrontNode) ?: return null
|
|
@@ -1088,7 +1172,8 @@ object AccessibilityUtil {
|
|
|
for (i in 0 until depth) {
|
|
for (i in 0 until depth) {
|
|
|
s += "---"
|
|
s += "---"
|
|
|
}
|
|
}
|
|
|
- val temp = "$s depth: $depth className: " + node.className + " isClickable: " + node.isClickable
|
|
|
|
|
|
|
+ val temp =
|
|
|
|
|
+ "$s depth: $depth className: " + node.className + " isClickable: " + node.isClickable
|
|
|
Log.d(tag, temp)
|
|
Log.d(tag, temp)
|
|
|
sb.append(temp).append("\n")
|
|
sb.append(temp).append("\n")
|
|
|
var text = ""
|
|
var text = ""
|
|
@@ -1295,7 +1380,10 @@ object AccessibilityUtil {
|
|
|
}
|
|
}
|
|
|
currentTime = System.currentTimeMillis()
|
|
currentTime = System.currentTimeMillis()
|
|
|
}
|
|
}
|
|
|
- Log.e(tag, "waitForTextMissing ${if (desc) "desc" else "text"}: found: ${textList.joinToString()}")
|
|
|
|
|
|
|
+ Log.e(
|
|
|
|
|
+ tag,
|
|
|
|
|
+ "waitForTextMissing ${if (desc) "desc" else "text"}: found: ${textList.joinToString()}"
|
|
|
|
|
+ )
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1338,7 +1426,9 @@ object AccessibilityUtil {
|
|
|
val startTime = System.currentTimeMillis()
|
|
val startTime = System.currentTimeMillis()
|
|
|
var currentTime = startTime
|
|
var currentTime = startTime
|
|
|
while (currentTime - startTime <= timeout) {
|
|
while (currentTime - startTime <= timeout) {
|
|
|
- if (service.currentClass in clazzList || service.currentClass.split(".").last() in clazzList) {
|
|
|
|
|
|
|
+ if (service.currentClass in clazzList || service.currentClass.split(".")
|
|
|
|
|
+ .last() in clazzList
|
|
|
|
|
+ ) {
|
|
|
} else {
|
|
} else {
|
|
|
Log.v(tag, "pageMissing: ${clazzList.joinToString()}")
|
|
Log.v(tag, "pageMissing: ${clazzList.joinToString()}")
|
|
|
return true
|
|
return true
|
|
@@ -1346,7 +1436,10 @@ object AccessibilityUtil {
|
|
|
sleep(SHORT_INTERVAL)
|
|
sleep(SHORT_INTERVAL)
|
|
|
currentTime = System.currentTimeMillis()
|
|
currentTime = System.currentTimeMillis()
|
|
|
}
|
|
}
|
|
|
- Log.e(tag, "pageMissing: not found: ${clazzList.joinToString()} current: ${service.currentClass}")
|
|
|
|
|
|
|
+ Log.e(
|
|
|
|
|
+ tag,
|
|
|
|
|
+ "pageMissing: not found: ${clazzList.joinToString()} current: ${service.currentClass}"
|
|
|
|
|
+ )
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|