Skip to content

Commit 8ea5f6c

Browse files
Merge pull request #371 from TonyJiangWJ/master
优化布局分析功能,可以通过悬浮菜单排除部分干扰控件
2 parents ad9a249 + 8d44a0e commit 8ea5f6c

File tree

15 files changed

+71
-2
lines changed

15 files changed

+71
-2
lines changed

app/src/main/java/org/autojs/autojs/core/accessibility/NodeInfo.kt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class NodeInfo(private val resources: Resources?, private val node: UiObject, va
6363
val columnSpan = node.columnSpan()
6464
val drawingOrder = node.drawingOrder
6565
val actionNames = node.actionNames()
66+
var hidden = false
6667

6768
val children = ArrayList<NodeInfo>()
6869

app/src/main/java/org/autojs/autojs/ui/floating/LayoutFloatyWindow.kt

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.autojs.autojs.core.accessibility.WindowInfo.Companion.WindowInfoRootN
1616
import org.autojs.autojs.core.accessibility.WindowInfo.Companion.parseWindowType
1717
import org.autojs.autojs.ui.enhancedfloaty.FloatyService
1818
import org.autojs.autojs.ui.floating.layoutinspector.LayoutBoundsFloatyWindow
19+
import org.autojs.autojs.ui.floating.layoutinspector.LayoutBoundsView
1920
import org.autojs.autojs.ui.floating.layoutinspector.LayoutHierarchyFloatyWindow
2021
import org.autojs.autojs.ui.floating.layoutinspector.NodeInfoView
2122
import org.autojs.autojs.ui.widget.BubblePopupMenu
@@ -128,4 +129,18 @@ abstract class LayoutFloatyWindow(
128129
}
129130
}
130131

132+
133+
protected fun excludeNode() {
134+
mLayoutSelectedNode?.let {
135+
it.hidden = true
136+
mLayoutSelectedNode = null
137+
}
138+
}
139+
140+
protected fun excludeAllBoundsSameNode(layoutBoundsView: LayoutBoundsView ) {
141+
mLayoutSelectedNode?.let {
142+
layoutBoundsView.hideAllBoundsSameNode(it)
143+
mLayoutSelectedNode = null
144+
}
145+
}
131146
}

app/src/main/java/org/autojs/autojs/ui/floating/layoutinspector/LayoutBoundsFloatyWindow.kt

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ open class LayoutBoundsFloatyWindow @JvmOverloads constructor(
2727
R.string.text_show_layout_hierarchy to ::showLayoutHierarchy,
2828
R.string.text_generate_code to ::generateCode,
2929
R.string.text_switch_window to ::switchWindow,
30+
R.string.text_hide_node to ::excludeNode,
31+
R.string.text_hide_same_frame_nodes to ::excludeAllBoundsSameNode,
3032
R.string.text_exit to ::close,
3133
)
3234

@@ -69,4 +71,7 @@ open class LayoutBoundsFloatyWindow @JvmOverloads constructor(
6971
}
7072
}
7173

74+
private fun excludeAllBoundsSameNode() {
75+
excludeAllBoundsSameNode(mLayoutBoundsView)
76+
}
7277
}

app/src/main/java/org/autojs/autojs/ui/floating/layoutinspector/LayoutBoundsView.kt

+28-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ open class LayoutBoundsView : View {
6363
mTouchedNode = null
6464
}
6565

66+
fun hideAllBoundsSameNode(targetNode: NodeInfo?) {
67+
if (mRootNode == null || targetNode == null) {
68+
return
69+
}
70+
hideNodes(mRootNode, targetNode)
71+
}
72+
73+
private fun hideNodes(parent: NodeInfo?, targetNode: NodeInfo) {
74+
if (parent == null) {
75+
return
76+
}
77+
if (parent.boundsInScreen == targetNode.boundsInScreen) {
78+
parent.hidden = true
79+
}
80+
if (parent.children.size == 0) {
81+
return
82+
}
83+
for (child in parent.children) {
84+
hideNodes(child, targetNode)
85+
}
86+
}
87+
6688
override fun onDraw(canvas: Canvas) {
6789
super.onDraw(canvas)
6890
if (mBoundsInScreen == null) {
@@ -93,7 +115,9 @@ open class LayoutBoundsView : View {
93115

94116
private fun draw(canvas: Canvas, node: NodeInfo?) {
95117
if (node == null) return
96-
drawRect(canvas, node.boundsInScreen, statusBarHeight, boundsPaint)
118+
if (!node.hidden) {
119+
drawRect(canvas, node.boundsInScreen, statusBarHeight, boundsPaint)
120+
}
97121
for (child in node.children) {
98122
draw(canvas, child)
99123
}
@@ -125,7 +149,9 @@ open class LayoutBoundsView : View {
125149
private fun findNodeAt(node: NodeInfo, x: Int, y: Int, list: MutableList<NodeInfo>) {
126150
for (child in node.children) {
127151
if (child.boundsInScreen.contains(x, y)) {
128-
list.add(child)
152+
if (!child.hidden) {
153+
list.add(child)
154+
}
129155
findNodeAt(child, x, y, list)
130156
}
131157
}

app/src/main/res/values-ar/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -993,5 +993,7 @@
993993
<string name="text_write_secure_settings_description">إعدادات النظام الآمنة ، التي تحتوي على تفضيلات النظام التي يمكن أن تقرأها التطبيقات ولكن لا يُسمح لها بالكتابة.\nهذه هي لتفضيلات يجب على المستخدم تعديلها بشكل صريح من خلال واجهة المستخدم لتطبيق النظام.\nمع إذن إعدادات النظام الآمن ، يمكن للتطبيقات العادية تعديل الإعدادات الآمنة مباشرة (مثل خدمة إمكانية الوصول).</string>
994994
<string name="text_write_system_settings">كتابة إعدادات النظام</string>
995995
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">المسار المُحلّ لـ \"%1$s\" لا يمكن أن يكون null</string>
996+
<string name="text_hide_node">إخفاء هذه العقدة</string>
997+
<string name="text_hide_same_frame_nodes">إخفاء العقدة ذات الإطار المماثل</string>
996998

997999
</resources>

app/src/main/res/values-en/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -988,5 +988,7 @@
988988
<string name="text_write_secure_settings_description">Secure system settings, containing system preferences that applications can read but are not allowed to write.\nThese are for preferences that the user must explicitly modify through the UI of a system app.\nWith secure system settings permission, normal applications can directly modify the secure settings (such as accessibility service).</string>
989989
<string name="text_write_system_settings">Write system settings</string>
990990
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">Resolved path for \"%1$s\" cannot be null</string>
991+
<string name="text_hide_node">Hide this node</string>
992+
<string name="text_hide_same_frame_nodes">Hide same frame nodes</string>
991993

992994
</resources>

app/src/main/res/values-es/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -991,5 +991,7 @@
991991
<string name="text_write_secure_settings_description">Ajustes de seguridad del sistema, que contienen preferencias del sistema que las aplicaciones pueden leer pero no pueden escribir.\nSe trata de preferencias que el usuario debe modificar explícitamente a través de la interfaz de usuario de una aplicación del sistema.\nCon el permiso de configuración segura del sistema, las aplicaciones normales pueden modificar directamente la configuración segura (como el servicio de accesibilidad).</string>
992992
<string name="text_write_system_settings">Escribir la configuración del sistema</string>
993993
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">La ruta resuelta para \"%1$s\" no puede ser nula</string>
994+
<string name="text_hide_node">Ocultar este nodo</string>
995+
<string name="text_hide_same_frame_nodes">Ocultar nodo del mismo marco</string>
994996

995997
</resources>

app/src/main/res/values-fr/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -991,5 +991,7 @@
991991
<string name="text_write_secure_settings_description">Paramètres de sécurité du système, contenant les préférences du système que les applications peuvent lire mais ne sont pas autorisées à écrire.\nIl s\'agit des préférences que l\'utilisateur doit explicitement modifier par le biais de l\'interface utilisateur d\'une application système.\nAvec l\'autorisation de paramètres de sécurité du système, les applications normales peuvent directement modifier les paramètres de sécurité (comme le service d\'accessibilité).</string>
992992
<string name="text_write_system_settings">Écrire les paramètres système</string>
993993
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">Le chemin résolu pour \"%1$s\" ne peut pas être nul</string>
994+
<string name="text_hide_node">Masquer ce nœud</string>
995+
<string name="text_hide_same_frame_nodes">Masquer le nœud du même cadre</string>
994996

995997
</resources>

app/src/main/res/values-ja/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -992,5 +992,7 @@
992992
<string name="text_write_secure_settings_description">アプリケーションが読み取ることはできるが, 書き込むことはできないシステム環境設定を含む, 安全なシステム設定です.\nこれは, ユーザーがシステムアプリの UI を通じて明示的に変更する必要がある環境設定のためのものです.\nセキュアなシステム設定を許可すると, 通常のアプリケーションはセキュアな設定 (アクセシビリティサービスなど) を直接変更できるようになります</string>
993993
<string name="text_write_system_settings">システム設定の書き込み</string>
994994
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">\"%1$s\" の解決済みパスは null にできません</string>
995+
<string name="text_hide_node">このノードを隠す</string>
996+
<string name="text_hide_same_frame_nodes">同じフレームのノードを隠す</string>
995997

996998
</resources>

app/src/main/res/values-ko/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -993,5 +993,7 @@
993993
<string name="text_write_secure_settings_description">애플리케이션이 읽을 수 있지만 쓸 수없는 시스템 환경 설정을 포함하는 보안 시스템 설정.\n이들은 사용자가 시스템 앱의 UI 를 통해 명시 적으로 수정 해야하는 선호도입니다.\n보안 시스템 설정 권한을 사용하면 일반 애플리케이션이 보안 설정 (예: 접근성 서비스)을 직접 수정할 수 있습니다.</string>
994994
<string name="text_write_system_settings">시스템 설정을 작성하십시오</string>
995995
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">\"%1$s\" 에 대한 해결된 경로는 null 일 수 없습니다</string>
996+
<string name="text_hide_node">이 노드를 숨기기</string>
997+
<string name="text_hide_same_frame_nodes">동일 프레임의 노드를 숨기기</string>
996998

997999
</resources>

app/src/main/res/values-ru/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -991,5 +991,7 @@
991991
<string name="text_write_secure_settings_description">Настройки безопасности системы, содержащие системные предпочтения, которые приложения могут читать, но не имеют права записывать.\nОни предназначены для параметров, которые пользователь должен явно изменить через пользовательский интерфейс системного приложения.\nПри наличии разрешения на безопасные системные настройки обычные приложения могут напрямую изменять безопасные настройки (например, служба доступности).</string>
992992
<string name="text_write_system_settings">Запись системных настроек</string>
993993
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">Разрешённый путь для \"%1$s\" не может быть равен null</string>
994+
<string name="text_hide_node">Скрыть этот узел</string>
995+
<string name="text_hide_same_frame_nodes">Скрыть узел того же фрейма</string>
994996

995997
</resources>

app/src/main/res/values-zh-rHK/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -989,5 +989,7 @@
989989
<string name="text_write_secure_settings_description">安全設置包含應用程序可讀但不可寫入的設置選項, 這些選項只能由 UI 或系統級別應用修改.\n被授予 \"修改安全設置權限\" 後, 普通應用可直接修改上述安全設置 (例如無障礙服務).</string>
990990
<string name="text_write_system_settings">修改系統設置</string>
991991
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">解析後的路徑 \"%1$s\" 不可為 null</string>
992+
<string name="text_hide_node">隱藏此節點</string>
993+
<string name="text_hide_same_frame_nodes">隱藏同框節點</string>
992994

993995
</resources>

app/src/main/res/values-zh-rTW/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -989,5 +989,7 @@
989989
<string name="text_write_secure_settings_description">安全設定包含應用程式可讀但不可寫入的設定選項, 這些選項只能由 UI 或系統級別應用修改.\n被授予 \"修改安全設定許可權\" 後, 普通應用可直接修改上述安全設定 (例如無障礙服務).</string>
990990
<string name="text_write_system_settings">修改系統設定</string>
991991
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">解析後的路徑 \"%1$s\" 不可為 null</string>
992+
<string name="text_hide_node">隱藏此節點</string>
993+
<string name="text_hide_same_frame_nodes">隱藏同框節點</string>
992994

993995
</resources>

app/src/main/res/values-zh/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -989,5 +989,7 @@
989989
<string name="text_write_secure_settings_description">安全设置包含应用程序可读但不可写入的设置选项, 这些选项只能由 UI 或系统级别应用修改.\n被授予 \"修改安全设置权限\" 后, 普通应用可直接修改上述安全设置 (例如无障碍服务).</string>
990990
<string name="text_write_system_settings">修改系统设置</string>
991991
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">解析后的路径 \"%1$s\" 不可为 null</string>
992+
<string name="text_hide_node">隐藏此节点</string>
993+
<string name="text_hide_same_frame_nodes">隐藏同框节点</string>
992994

993995
</resources>

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -1218,5 +1218,7 @@
12181218
<string name="text_write_secure_settings_description">Secure system settings, containing system preferences that applications can read but are not allowed to write.\nThese are for preferences that the user must explicitly modify through the UI of a system app.\nWith secure system settings permission, normal applications can directly modify the secure settings (such as accessibility service).</string>
12191219
<string name="text_write_system_settings">Write system settings</string>
12201220
<string name="error_resolved_path_for_a_relative_path_cannot_be_null">Resolved path for \"%1$s\" cannot be null</string>
1221+
<string name="text_hide_node">Hide this node</string>
1222+
<string name="text_hide_same_frame_nodes">Hide same frame nodes</string>
12211223

12221224
</resources>

0 commit comments

Comments
 (0)