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