update 多控件类型兼容;兼容多版本系统
This commit is contained in:
@@ -108,15 +108,6 @@ object Demo {
|
||||
"$name"
|
||||
],
|
||||
"receivedContent":"你好~我是机器人,你可以@我和我聊天,你也可以通过API文档来让我发送消息或完成建群等任务。接口文档:https://www.apifox.cn/apidoc/project-1035094/api-23520034"
|
||||
},
|
||||
{
|
||||
"type": 206,
|
||||
"groupName": "$groupName",
|
||||
"selectList": [
|
||||
"$name",
|
||||
"尹甲仑"
|
||||
],
|
||||
"groupAnnouncement": "(自动填写群公告) WorkTool欢迎大家~WorkTool管家是机器人,有问题可以在QQ群反馈~@我可以聊天~"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ object WeworkLoopImpl {
|
||||
LogUtils.i("读取首页聊天列表")
|
||||
log("读取首页聊天列表")
|
||||
}
|
||||
val listview = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView)
|
||||
val listview = AccessibilityUtil.findOneByClazz(getRoot(), Views.RecyclerView, Views.ListView)
|
||||
if (listview != null) {
|
||||
if (listview.childCount >= 2) {
|
||||
if (checkUnreadChatRoom(listview)) {
|
||||
@@ -301,7 +301,7 @@ object WeworkLoopImpl {
|
||||
val itemMessageList = arrayListOf<WeworkMessageBean.ItemMessageBean>()
|
||||
LogUtils.v("开始解析一条消息...")
|
||||
//消息头(在消息主体上方 如时间信息)
|
||||
val linearLayoutItem = AccessibilityUtil.findOnceByClazz(node, Views.LinearLayout, 1)
|
||||
val linearLayoutItem = AccessibilityUtil.findOnceByClazz(node, Views.LinearLayout, limitDepth = 1)
|
||||
if (linearLayoutItem != null) {
|
||||
val sb = StringBuilder("消息头: ")
|
||||
val tvList = AccessibilityUtil.findAllOnceByClazz(linearLayoutItem, Views.TextView)
|
||||
@@ -314,14 +314,14 @@ object WeworkLoopImpl {
|
||||
LogUtils.v(sb.toString())
|
||||
}
|
||||
//消息主体
|
||||
val relativeLayoutItem = AccessibilityUtil.findOnceByClazz(node, Views.RelativeLayout, 1)
|
||||
val relativeLayoutItem = AccessibilityUtil.findOnceByClazz(node, Views.RelativeLayout, limitDepth = 1)
|
||||
if (relativeLayoutItem != null && relativeLayoutItem.childCount >= 2) {
|
||||
if (Views.ImageView.equals(relativeLayoutItem.getChild(0).className)) {
|
||||
LogUtils.v("头像在左边 本条消息发送者为其他联系人")
|
||||
nameList.addAll(WeworkTextUtil.getNameList(node))
|
||||
var textType = WeworkMessageBean.TEXT_TYPE_UNKNOWN
|
||||
val relativeLayoutContent =
|
||||
AccessibilityUtil.findOnceByClazz(relativeLayoutItem, Views.RelativeLayout, 2)
|
||||
AccessibilityUtil.findOnceByClazz(relativeLayoutItem, Views.RelativeLayout, limitDepth = 2)
|
||||
if (relativeLayoutContent != null) {
|
||||
textType = WeworkTextUtil.getTextType(relativeLayoutContent)
|
||||
LogUtils.v("textType: $textType")
|
||||
|
||||
@@ -276,6 +276,7 @@ object WeworkOperationImpl {
|
||||
val node = AccessibilityUtil.scrollAndFindByText(getRoot(), "微盘")
|
||||
if (node != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
sleep(Constant.POP_WINDOW_INTERVAL)
|
||||
AccessibilityUtil.clickByNode(WeworkController.weworkService, node)
|
||||
} else {
|
||||
AccessibilityUtil.performClick(node)
|
||||
@@ -322,6 +323,7 @@ object WeworkOperationImpl {
|
||||
val node = AccessibilityUtil.scrollAndFindByText(getRoot(), "微盘")
|
||||
if (node != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
sleep(Constant.POP_WINDOW_INTERVAL)
|
||||
AccessibilityUtil.clickByNode(WeworkController.weworkService, node)
|
||||
} else {
|
||||
AccessibilityUtil.performClick(node)
|
||||
@@ -632,19 +634,23 @@ object WeworkOperationImpl {
|
||||
*/
|
||||
private fun createGroup(): Boolean {
|
||||
goHomeTab("工作台")
|
||||
val groupTv = AccessibilityUtil.scrollAndFindByText(getRoot(), "客户群", "居民群")
|
||||
val node = AccessibilityUtil.scrollAndFindByText(getRoot(), "客户群", "居民群")
|
||||
?: return false
|
||||
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||
&& AccessibilityUtil.clickByNode(WeworkController.weworkService, groupTv))
|
||||
|| AccessibilityUtil.performClick(groupTv)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
sleep(Constant.POP_WINDOW_INTERVAL)
|
||||
if (AccessibilityUtil.clickByNode(WeworkController.weworkService, node)) {
|
||||
LogUtils.d("进入客户群应用")
|
||||
val textView = AccessibilityUtil.findOneByText(getRoot(), "创建一个客户群", "创建一个居民群")
|
||||
return AccessibilityUtil.performClick(textView)
|
||||
} else {
|
||||
}
|
||||
} else if (AccessibilityUtil.performClick(node)) {
|
||||
LogUtils.d("进入客户群应用")
|
||||
val textView = AccessibilityUtil.findOneByText(getRoot(), "创建一个客户群", "创建一个居民群")
|
||||
return AccessibilityUtil.performClick(textView)
|
||||
}
|
||||
LogUtils.d("未找到客户群应用")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改群名称
|
||||
|
||||
@@ -133,27 +133,21 @@ object AccessibilityUtil {
|
||||
|
||||
//输入x, y坐标模拟点击事件
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
fun performXYClick(service: AccessibilityService, x: Float, y: Float) {
|
||||
fun performXYClick(service: AccessibilityService, x: Float, y: Float): Boolean {
|
||||
val path = Path()
|
||||
path.moveTo(x, y)
|
||||
val builder = GestureDescription.Builder()
|
||||
builder.addStroke(GestureDescription.StrokeDescription(path, 0, 1))
|
||||
val gestureDescription = builder.build()
|
||||
service.dispatchGesture(
|
||||
gestureDescription,
|
||||
object : AccessibilityService.GestureResultCallback() {
|
||||
builder.addStroke(StrokeDescription(path, 0, 1))
|
||||
val gesture = builder.build()
|
||||
return service.dispatchGesture(gesture, object : GestureResultCallback() {
|
||||
override fun onCompleted(gestureDescription: GestureDescription) {
|
||||
super.onCompleted(gestureDescription)
|
||||
//Log.i(Constant.TAG, "onCompleted: completed");
|
||||
LogUtils.v("click okk onCompleted")
|
||||
}
|
||||
|
||||
override fun onCancelled(gestureDescription: GestureDescription) {
|
||||
super.onCancelled(gestureDescription)
|
||||
//Log.i(Constant.TAG, "onCancelled: cancelled");
|
||||
LogUtils.v("click okk onCancelled")
|
||||
}
|
||||
},
|
||||
null
|
||||
)
|
||||
}, null)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,7 +482,7 @@ object AccessibilityUtil {
|
||||
*/
|
||||
fun findOneByClazz(
|
||||
node: AccessibilityNodeInfo?,
|
||||
clazz: String,
|
||||
vararg clazzList: String,
|
||||
limitDepth: Int? = null,
|
||||
depth: Int = 0,
|
||||
timeout: Long = 5000,
|
||||
@@ -498,8 +492,8 @@ object AccessibilityUtil {
|
||||
val startTime = System.currentTimeMillis()
|
||||
var currentTime = startTime
|
||||
while (currentTime - startTime <= timeout) {
|
||||
val result = findOnceByClazz(node, clazz, limitDepth, depth)
|
||||
LogUtils.v("clazz: $clazz result == null: ${result == null}")
|
||||
val result = findOnceByClazz(node, *clazzList, limitDepth = limitDepth, depth = depth)
|
||||
LogUtils.v("clazz: ${clazzList.joinToString()} result == null: ${result == null}")
|
||||
if (result != null) return result
|
||||
sleep(SHORT_INTERVAL)
|
||||
if (root) {
|
||||
@@ -522,17 +516,17 @@ object AccessibilityUtil {
|
||||
*/
|
||||
fun findOnceByClazz(
|
||||
node: AccessibilityNodeInfo?,
|
||||
clazz: String,
|
||||
vararg clazzList: String,
|
||||
limitDepth: Int? = null,
|
||||
depth: Int = 0
|
||||
): AccessibilityNodeInfo? {
|
||||
if (node == null) return null
|
||||
if (node.className == clazz) {
|
||||
if (node.className in clazzList) {
|
||||
if (limitDepth == null || limitDepth == depth)
|
||||
return node
|
||||
}
|
||||
for (i in 0 until node.childCount) {
|
||||
val result = findOnceByClazz(node.getChild(i), clazz, limitDepth, depth + 1)
|
||||
val result = findOnceByClazz(node.getChild(i), *clazzList, limitDepth = limitDepth, depth = depth + 1)
|
||||
if (result != null) return result
|
||||
}
|
||||
return null
|
||||
@@ -546,7 +540,7 @@ object AccessibilityUtil {
|
||||
*/
|
||||
fun findAllByClazz(
|
||||
node: AccessibilityNodeInfo?,
|
||||
clazz: String,
|
||||
vararg clazzList: String,
|
||||
timeout: Long = 5000,
|
||||
root: Boolean = true,
|
||||
minSize: Int = 1
|
||||
@@ -555,8 +549,8 @@ object AccessibilityUtil {
|
||||
val startTime = System.currentTimeMillis()
|
||||
var currentTime = startTime
|
||||
while (currentTime - startTime <= timeout) {
|
||||
val result = findAllOnceByClazz(node, clazz)
|
||||
LogUtils.v("clazz: $clazz count: " + result.size)
|
||||
val result = findAllOnceByClazz(node, *clazzList)
|
||||
LogUtils.v("clazz: ${clazzList.joinToString()} count: " + result.size)
|
||||
if (result.size >= minSize) return result
|
||||
sleep(SHORT_INTERVAL)
|
||||
if (root) {
|
||||
@@ -579,13 +573,13 @@ object AccessibilityUtil {
|
||||
*/
|
||||
fun findAllOnceByClazz(
|
||||
node: AccessibilityNodeInfo?,
|
||||
clazz: String,
|
||||
vararg clazzList: String,
|
||||
list: ArrayList<AccessibilityNodeInfo> = ArrayList()
|
||||
): ArrayList<AccessibilityNodeInfo> {
|
||||
if (node == null) return list
|
||||
if (node.className == clazz) list.add(node)
|
||||
if (node.className in clazzList) list.add(node)
|
||||
for (i in 0 until node.childCount) {
|
||||
findAllOnceByClazz(node.getChild(i), clazz, list)
|
||||
findAllOnceByClazz(node.getChild(i), *clazzList, list = list)
|
||||
}
|
||||
return list
|
||||
}
|
||||
@@ -711,11 +705,11 @@ object AccessibilityUtil {
|
||||
val gesture = builder.build()
|
||||
return service.dispatchGesture(gesture, object : GestureResultCallback() {
|
||||
override fun onCompleted(gestureDescription: GestureDescription) {
|
||||
LogUtils.d("click okk onCompleted")
|
||||
LogUtils.v("click okk onCompleted")
|
||||
}
|
||||
|
||||
override fun onCancelled(gestureDescription: GestureDescription) {
|
||||
LogUtils.d("click okk onCancelled")
|
||||
LogUtils.v("click okk onCancelled")
|
||||
}
|
||||
}, null)
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ object WeworkRoomUtil {
|
||||
return true
|
||||
}
|
||||
goHome()
|
||||
val list = findOneByClazz(getRoot(), Views.ListView)
|
||||
val list = findOneByClazz(getRoot(), Views.RecyclerView, Views.ListView)
|
||||
if (list != null) {
|
||||
val frontNode = findFrontNode(list)
|
||||
val textViewList = findAllOnceByClazz(frontNode, Views.TextView)
|
||||
@@ -210,7 +210,7 @@ object WeworkRoomUtil {
|
||||
* listview前兄弟控件 && text包含外部群
|
||||
*/
|
||||
private fun isExternalGroup(): Boolean {
|
||||
val listView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.ListView, null, 0)
|
||||
val listView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.ListView, limitDepth = null, depth = 0)
|
||||
if (listView != null) {
|
||||
val frontNode = findFrontNode(listView)
|
||||
if (frontNode != null) {
|
||||
|
||||
Reference in New Issue
Block a user