6.7.0 - Alpha14 - 修复布局分析页面生成代码时对于集合控件可能生成失败的问题 (试修) (issue #328)

This commit is contained in:
SuperMonster003
2026-01-12 17:46:24 +08:00
parent 27a43fbd62
commit 27e06e5fe7
3 changed files with 40 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
{
"$data": {
"v6.7.0": {
"released_date": "2026/01/11",
"released_date": "2026/01/12",
"feature": [
"插件中心功能, 支持插件的安装/卸载/更新等操作 (入口: 主页抽屉按钮)",
"cvt 模块, 用于数据单位转换 (参阅 项目文档 > [单位转换](https://docs.autojs6.com/#/cvt))",
@@ -87,6 +87,7 @@
"客户端模式连接时, 旋转屏幕及切换语言等触发 Activity 重建的操作导致 AutoJs6 总是重建连接的问题",
"服务端模式连接时, 旋转屏幕及切换语言等触发 Activity 重建的操作导致 VSCode 控制台无法输出日志的问题 _[`issue #385`](http://issues.autojs6.com/385)_",
"连接 VSCode 插件时, 多种方式同时连接可能导致日志打印数量成倍增加的问题",
"布局分析页面生成代码时对于集合控件可能生成失败的问题 (试修) _[`issue #328`](http://issues.autojs6.com/328)_",
"构建工具启用 isCleanup[Paddle/Rapid]Ocr 配置选项时无法正常完成 Rebuild Project 任务的问题"
],
"improvement": [

View File

@@ -1,13 +1,14 @@
package org.autojs.autojs.codegeneration;
import androidx.annotation.NonNull;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import org.autojs.autojs.core.accessibility.UiSelector;
import org.autojs.autojs.core.accessibility.NodeInfo;
import org.autojs.autojs.core.accessibility.UiSelector;
import org.autojs.autojs.core.automator.UiObject;
/**
* Created by Stardust on Dec 7, 2017.
* Modified by SuperMonster003 as of Jan 12, 2026.
*/
public class CodeGenerator {
@@ -56,7 +57,14 @@ public class CodeGenerator {
public String generateCode() {
UiObject collection = getCollectionParent(mTarget);
if (collection != null) {
return generateCodeForCollectionChild(collection, mTarget);
// @Hint by SuperMonster003 on Jan 12, 2026.
// ! Collection-based generation may fail in some apps due to unstable accessibility trees.
// ! zh-CN: 基于集合控件的生成在某些应用中可能因无障碍树不稳定而失败.
// # return generateCodeForCollectionChild(collection, mTarget);
String collectionChildCode = generateCodeForCollectionChild(collection, mTarget);
if (collectionChildCode != null) {
return collectionChildCode;
}
}
UiSelectorGenerator generator = new UiSelectorGenerator(mRoot, mTarget);
@@ -65,8 +73,9 @@ public class CodeGenerator {
generator.setUsingId(mUsingId);
generator.setUsingText(mUsingText);
String selector = generateCode(generator, mRoot, mTarget, 2, 2, true);
if (selector == null)
if (selector == null) {
return null;
}
return generateAction(selector);
}
@@ -85,8 +94,9 @@ public class CodeGenerator {
if (maxChildrenLevel > 0) {
for (int i = 0; i < target.childCount(); i++) {
UiObject child = target.child(i);
if (child == null)
if (child == null) {
continue;
}
String childCode = generateCode(root, child, 0, maxChildrenLevel - 1);
if (childCode != null) {
return childCode + ".parent()";
@@ -116,8 +126,9 @@ public class CodeGenerator {
}
private String generateAction(String selector) {
if (selector == null)
if (selector == null) {
return null;
}
if (mSearchMode == WAIT_FOR) {
return selector + ".waitFor()";
}
@@ -145,30 +156,38 @@ public class CodeGenerator {
private String generateCodeForCollectionChild(UiObject collection, UiObject target) {
UiObject parent = target.parent();
if (parent == null)
if (parent == null) {
return null;
}
UiObject collectionItem = null;
for (int i = 0; i < collection.childCount(); i++) {
if (inherits(collection.child(i), target)) {
collectionItem = collection.child(i);
UiObject child = collection.child(i);
if (child == null) {
continue;
}
if (inherits(child, target)) {
collectionItem = child;
break;
}
}
if (collectionItem == null)
if (collectionItem == null) {
return null;
}
String collectionCode = generateCode(mRoot, collection, 2, 0);
if (collectionCode == null)
if (collectionCode == null) {
return null;
}
String itemCode = generateCode(collectionItem, target, 1, 2, false);
if (itemCode == null)
if (itemCode == null) {
return null;
}
return collectionCode + ".children().forEach(child => {\n"
+ "var target = child.findOne(" + itemCode + ");\n"
+ "target." + getAction() + ";\n"
+ "});";
+ "var target = child.findOne(" + itemCode + ");\n"
+ "target." + getAction() + ";\n"
+ "});";
}
private boolean inherits(UiObject root, UiObject target) {
private boolean inherits(@NonNull UiObject root, UiObject target) {
for (int i = 0; i < root.childCount(); i++) {
UiObject child = root.child(i);
if (child != null) {

View File

@@ -1,5 +1,5 @@
#Sun Jan 11 23:41:15 CST 2026
BUILD_TIME=1768146075102
#Mon Jan 12 17:10:46 CST 2026
BUILD_TIME=1768209046850
COMPILE_SDK_VERSION=36
IMAGE_QUANT_CMAKE_VERSION=3.22.1
IMAGE_QUANT_NDK_VERSION=26.1.10909125
@@ -27,6 +27,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=36
TARGET_SDK_VERSION_INRT=29
VERSION_BUILD=3597
VERSION_BUILD=3598
VERSION_NAME=6.7.0 Alpha14
VSCODE_EXT_REQUIRED_VERSION=1.0.13