布局分析增加多选功能(未完善)

This commit is contained in:
抠脚本人
2023-07-12 11:29:03 +08:00
parent 76163c796e
commit 3794377984
7 changed files with 39 additions and 14 deletions

View File

@@ -70,7 +70,7 @@ public class ReadOnlyUiObject extends UiObject {
@Override @Override
public String id() { public String id() {
return mNodeInfo.getSimpleId(); return mNodeInfo.getId();
} }
@Override @Override

View File

@@ -1,5 +1,6 @@
package org.autojs.autojs.core.accessibility package org.autojs.autojs.core.accessibility
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Resources import android.content.res.Resources
@@ -17,7 +18,7 @@ import java.util.HashMap
* Modified by SuperMonster003 as of Jun 17, 2022. * Modified by SuperMonster003 as of Jun 17, 2022.
*/ */
@Suppress("unused") @Suppress("unused", "MemberVisibilityCanBePrivate")
@Keep @Keep
class NodeInfo(private val resources: Resources?, private val node: UiObject, var parent: NodeInfo?) { class NodeInfo(private val resources: Resources?, private val node: UiObject, var parent: NodeInfo?) {
@@ -27,8 +28,8 @@ class NodeInfo(private val resources: Resources?, private val node: UiObject, va
val bounds = boundsToString(boundsInScreen) val bounds = boundsToString(boundsInScreen)
val children = ArrayList<NodeInfo>() val children = ArrayList<NodeInfo>()
var fullId: String? = node.viewIdResourceName val fullId = node.fullId()
val simpleId = node.simpleId() val id = node.simpleId()
val desc = node.desc() val desc = node.desc()
val text = node.text() val text = node.text()
val className = node.className() val className = node.className()
@@ -59,6 +60,7 @@ class NodeInfo(private val resources: Resources?, private val node: UiObject, va
val childCount = node.childCount() val childCount = node.childCount()
val actionNames = node.actionNames() val actionNames = node.actionNames()
@SuppressLint("DiscouragedApi")
val idHex = takeIf { resources != null && packageName != null && fullId != null }?.let { val idHex = takeIf { resources != null && packageName != null && fullId != null }?.let {
"0x${Integer.toHexString(resources!!.getIdentifier(fullId, null, null))}" "0x${Integer.toHexString(resources!!.getIdentifier(fullId, null, null))}"
} }
@@ -68,7 +70,7 @@ class NodeInfo(private val resources: Resources?, private val node: UiObject, va
"childCount=${children.size}, " + "childCount=${children.size}, " +
"boundsInScreen=$boundsInScreen, " + "boundsInScreen=$boundsInScreen, " +
"boundsInParent=$boundsInParent, " + "boundsInParent=$boundsInParent, " +
"id='$simpleId', " + "id='$id', " +
"desc='$desc', " + "desc='$desc', " +
"packageName='$packageName', " + "packageName='$packageName', " +
"text='$text', " + "text='$text', " +

View File

@@ -13,9 +13,11 @@ import org.autojs.autojs.ui.floating.layoutinspector.LayoutBoundsFloatyWindow
import org.autojs.autojs.ui.floating.layoutinspector.LayoutHierarchyFloatyWindow import org.autojs.autojs.ui.floating.layoutinspector.LayoutHierarchyFloatyWindow
import org.autojs.autojs.ui.floating.layoutinspector.NodeInfoView import org.autojs.autojs.ui.floating.layoutinspector.NodeInfoView
import org.autojs.autojs.ui.widget.BubblePopupMenu import org.autojs.autojs.ui.widget.BubblePopupMenu
import org.autojs.autojs.util.ClipboardUtils
import org.autojs.autojs.util.ViewUtils
import org.autojs.autojs6.R import org.autojs.autojs6.R
abstract class LayoutFloatyWindow(private val rootNode: NodeInfo?, private val context: Context, private val isServiceRelied: Boolean) : FullScreenFloatyWindow() { abstract class LayoutFloatyWindow(private val rootNode: NodeInfo?, private val context: Context, private val isServiceRelied: Boolean) : FullScreenFloatyWindow(){
private lateinit var mServiceContext: Context private lateinit var mServiceContext: Context
private lateinit var mActions: LinkedHashMap<Int, Runnable> private lateinit var mActions: LinkedHashMap<Int, Runnable>
@@ -27,6 +29,12 @@ abstract class LayoutFloatyWindow(private val rootNode: NodeInfo?, private val c
private val mNodeInfoDialog by lazy { private val mNodeInfoDialog by lazy {
AppLevelThemeDialogBuilder(mServiceContext) AppLevelThemeDialogBuilder(mServiceContext)
.customView(mNodeInfoView, false) .customView(mNodeInfoView, false)
.positiveText("生成")
.onPositive { _, _ ->
ViewUtils.showToast(context, "TODO")
val selector = mNodeInfoView.getCheckedDate().joinToString(".")
if (selector.isNotEmpty()) ClipboardUtils.setClip(context, selector)
}
.build() .build()
.also { it.window!!.setType(FloatyWindowManger.getWindowType()) } .also { it.window!!.setType(FloatyWindowManger.getWindowType()) }
} }

View File

@@ -291,8 +291,8 @@ public class LayoutHierarchyView extends MultiLevelListView {
private String extraInfo(NodeInfo nodeInfo) { private String extraInfo(NodeInfo nodeInfo) {
String extra = simplifyClassName(nodeInfo.getClassName()); String extra = simplifyClassName(nodeInfo.getClassName());
ArrayList<String> info = new ArrayList<>(); ArrayList<String> info = new ArrayList<>();
if (nodeInfo.getSimpleId() != null) { if (nodeInfo.getId() != null) {
info.add("id=" + nodeInfo.getSimpleId()); info.add("id=" + nodeInfo.getId());
} }
if (!nodeInfo.getText().equals("")) { if (!nodeInfo.getText().equals("")) {
info.add("text=" + nodeInfo.getText()); info.add("text=" + nodeInfo.getText());

View File

@@ -6,6 +6,7 @@ import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@@ -21,7 +22,7 @@ import java.lang.reflect.Field
* Modified by SuperMonster003 as of Dec 1, 2021. * Modified by SuperMonster003 as of Dec 1, 2021.
*/ */
class NodeInfoView : RecyclerView { class NodeInfoView : RecyclerView {
//todo:调整数据结构,对话框关闭后根据已勾选的属性,生成选择器
private val data = Array(FIELDS.size + 1) { Array(2) { "" } } private val data = Array(FIELDS.size + 1) { Array(2) { "" } }
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@@ -73,6 +74,14 @@ class NodeInfoView : RecyclerView {
} }
} }
fun getCheckedDate(): Array<String> {
//todo:数据增加checked属性区分已选中项目
val checkedArr = data.filter { it[0] == "id" || it[0] == "text" }
return Array(checkedArr.size) {
dataToFx(checkedArr[it])
}
}
private inner class Adapter : RecyclerView.Adapter<ViewHolder>() { private inner class Adapter : RecyclerView.Adapter<ViewHolder>() {
val mViewTypeHeader = 0 val mViewTypeHeader = 0
@@ -86,6 +95,7 @@ class NodeInfoView : RecyclerView {
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.apply { holder.apply {
data[position].let { data[position].let {
//attrChecked.isChecked = false
attrName.text = it[0] attrName.text = it[0]
attrValue.text = it[1] attrValue.text = it[1]
} }
@@ -99,7 +109,7 @@ class NodeInfoView : RecyclerView {
} }
internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
//val attrChecked: CheckBox = itemView.findViewById(R.id.generate)
val attrName: TextView = itemView.findViewById(R.id.name) val attrName: TextView = itemView.findViewById(R.id.name)
val attrValue: TextView = itemView.findViewById(R.id.value) val attrValue: TextView = itemView.findViewById(R.id.value)
@@ -132,7 +142,7 @@ class NodeInfoView : RecyclerView {
private val FIELD_NAMES = arrayOf( private val FIELD_NAMES = arrayOf(
// Common // Common
"packageName", "simpleId", "fullId", "idHex", "packageName", "id", "fullId", "idHex",
"desc", "text", "desc", "text",
"bounds", "className", "bounds", "className",
"clickable", "longClickable", "scrollable", "clickable", "longClickable", "scrollable",

View File

@@ -10,6 +10,11 @@
android:orientation="horizontal" android:orientation="horizontal"
android:padding="8dp"> android:padding="8dp">
<CheckBox
android:id="@+id/generate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="TouchTargetSizeCheck" />
<TextView <TextView
android:id="@+id/name" android:id="@+id/name"
android:layout_width="0dp" android:layout_width="0dp"

View File

@@ -1,8 +1,8 @@
#Tue Jul 11 20:02:39 CST 2023 #Wed Jul 12 11:13:23 CST 2023
BUILD_TIME=1689076959792 BUILD_TIME=1689131603296
COMPILE_SDK_VERSION=33 COMPILE_SDK_VERSION=33
JAVA_VERSION=20 JAVA_VERSION=20
MIN_SDK_VERSION=24 MIN_SDK_VERSION=24
TARGET_SDK_VERSION=33 TARGET_SDK_VERSION=33
VERSION_BUILD=2015 VERSION_BUILD=2020
VERSION_NAME=6.3.2 VERSION_NAME=6.3.2