填充表单 visible
This commit is contained in:
6
.idea/MarsCodeWorkspaceAppSettings.xml
generated
6
.idea/MarsCodeWorkspaceAppSettings.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="com.codeverse.userSettings.MarscodeWorkspaceAppSettingsState">
|
||||
<option name="progress" value="1.0" />
|
||||
</component>
|
||||
</project>
|
||||
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
||||
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||
|
||||
@@ -6,6 +6,49 @@ import android.view.accessibility.AccessibilityNodeInfo
|
||||
|
||||
class AccessibilityTool {
|
||||
companion object {
|
||||
|
||||
fun ensureNodeVisible(node: AccessibilityNodeInfo) {
|
||||
// 判断当前控件是否可见
|
||||
if (node.isVisibleToUser) {
|
||||
return // 如果已经可见,直接返回
|
||||
}
|
||||
|
||||
// 如果不可见,向上查找可展开的父级控件
|
||||
var parent: AccessibilityNodeInfo? = node.parent
|
||||
while (parent != null) {
|
||||
// 检查父级控件是否支持展开操作
|
||||
if (parent.isExpandable()) {
|
||||
// 如果父级控件未展开,则执行展开操作
|
||||
if (!parent.isChecked && !parent.isSelected) {
|
||||
clickButton(parent)
|
||||
// 等待展开动画完成
|
||||
Thread.sleep(500)
|
||||
break
|
||||
}
|
||||
}
|
||||
parent = parent.parent
|
||||
}
|
||||
|
||||
// 展开后如果控件仍不可见,滚动到可见位置
|
||||
if (!node.isVisibleToUser) {
|
||||
// 查找可滚动的父级容器
|
||||
var scrollableParent: AccessibilityNodeInfo? = node.parent
|
||||
while (scrollableParent != null) {
|
||||
if (scrollableParent.isScrollable) {
|
||||
// 执行滚动操作,使节点可见
|
||||
scrollableParent.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD)
|
||||
break
|
||||
}
|
||||
scrollableParent = scrollableParent.parent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 扩展函数:判断节点是否可展开(可以根据实际需求调整判断条件)
|
||||
private fun AccessibilityNodeInfo.isExpandable(): Boolean {
|
||||
// 通常可展开的控件具有可检查或可选择属性,且不是叶子节点
|
||||
return (this.isCheckable || this.isClickable) && this.childCount > 0
|
||||
}
|
||||
fun focus(node: AccessibilityNodeInfo) {
|
||||
if( node.isFocusable){
|
||||
node.performAction(AccessibilityNodeInfo.ACTION_FOCUS)
|
||||
@@ -13,7 +56,9 @@ class AccessibilityTool {
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun inputText(editTextNode: AccessibilityNodeInfo, value: String): Boolean {
|
||||
ensureNodeVisible(editTextNode)
|
||||
focus(editTextNode)
|
||||
clickButton(editTextNode)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user