6.7.0 - Alpha13 - 修复 UiObject#isShifted 方法内部逻辑错误; 新增 UiObject#snapshot 方法 (issue #469)

This commit is contained in:
SuperMonster003
2025-12-27 23:18:01 +08:00
parent ebf4489655
commit f8ef030f94
3 changed files with 36 additions and 22 deletions

View File

@@ -20,7 +20,8 @@
"http 模块请求相关方法支持 options.client 选项, 用于配置 OkHttpClient.Builder (如 followRedirects 等) _[`issue #454`](http://issues.autojs6.com/454)_", "http 模块请求相关方法支持 options.client 选项, 用于配置 OkHttpClient.Builder (如 followRedirects 等) _[`issue #454`](http://issues.autojs6.com/454)_",
"runtime.(set/is)JavaPrimitiveWrap 方法, 用于设置或获取 Java 原始类型包装策略 _[`issue #435`](http://issues.autojs6.com/435)_", "runtime.(set/is)JavaPrimitiveWrap 方法, 用于设置或获取 Java 原始类型包装策略 _[`issue #435`](http://issues.autojs6.com/435)_",
"autojs.(restart/exit) 方法, 用于重启或退出 AutoJs6 应用, 并支持应用重启时自动运行其参数指定的脚本 _[`issue #460`](http://issues.autojs6.com/460)_", "autojs.(restart/exit) 方法, 用于重启或退出 AutoJs6 应用, 并支持应用重启时自动运行其参数指定的脚本 _[`issue #460`](http://issues.autojs6.com/460)_",
"UiObject#isShifted 方法, 用于检测控件位置变化", "UiObject#isShifted 方法, 用于检测控件位置变化 _[`issue #469`](http://issues.autojs6.com/469)_",
"UiObject#snapshot 方法, 用于捕获控件当前状态 _[`issue #469`](http://issues.autojs6.com/469)_",
"crash 全局方法, 用于测试崩溃报告页面", "crash 全局方法, 用于测试崩溃报告页面",
"structuredClone 全局方法, 用于深拷贝 JavaScript 对象 (参阅 [MDN](https://developer.mozilla.org/zh-CN/docs/Web/API/Window/structuredClone))", "structuredClone 全局方法, 用于深拷贝 JavaScript 对象 (参阅 [MDN](https://developer.mozilla.org/zh-CN/docs/Web/API/Window/structuredClone))",
"等价系列选择器 (UiSelector#id/text/...) 及包含系列选择器 (UiSelector#xxxContains) 支持正则表达式参数", "等价系列选择器 (UiSelector#id/text/...) 及包含系列选择器 (UiSelector#xxxContains) 支持正则表达式参数",

View File

@@ -559,27 +559,40 @@ open class UiObject(
"${lastChild() ?: ""}" == "${other.lastChild()}" "${lastChild() ?: ""}" == "${other.lastChild()}"
} }
fun isShifted(other: UiObject) = bounds() == other.bounds() // Captures current state; refreshing it won't affect the original.
// zh-CN: 捕获当前状态; 刷新它不会影响原始对象.
fun snapshot(): UiObject {
val raw = unwrap()
val rawCopy = AccessibilityNodeInfo.obtain(raw)
return UiObject(rawCopy, allocator, depth, indexInParent)
}
fun isShifted(other: UiObject, tolerance: Double): Boolean { @JvmOverloads
val a = bounds() fun isShifted(tolerance: Double = 0.0): Boolean {
val b = other.bounds() val probe = snapshot()
return when { try {
tolerance < 0 -> throw WrappedIllegalArgumentException( val a = probe.bounds() /* Before. */
"Argument \"tolerance\" ${tolerance.jsBrief()} for UiObject#isShifted must be greater than or equal to 0", if (!probe.refresh()) return true
) val b = probe.bounds() /* After. */
tolerance < 1 -> (width() to height()).let { (w, h) -> return when {
return@let abs(a.left - b.left) > tolerance * w tolerance < 0 -> throw WrappedIllegalArgumentException(
|| abs(a.top - b.top) > tolerance * h "Argument \"tolerance\" ${tolerance.jsBrief()} for UiObject#isShifted must be greater than or equal to 0",
|| abs(a.right - b.right) > tolerance * w )
|| abs(a.bottom - b.bottom) > tolerance * h tolerance < 1 -> (width() to height()).let { (w, h) ->
} return@let abs(a.left - b.left) > tolerance * w
else -> let { || abs(a.top - b.top) > tolerance * h
return@let abs(a.left - b.left) > tolerance || abs(a.right - b.right) > tolerance * w
|| abs(a.top - b.top) > tolerance || abs(a.bottom - b.bottom) > tolerance * h
|| abs(a.right - b.right) > tolerance }
|| abs(a.bottom - b.bottom) > tolerance else -> let {
return@let abs(a.left - b.left) > tolerance
|| abs(a.top - b.top) > tolerance
|| abs(a.right - b.right) > tolerance
|| abs(a.bottom - b.bottom) > tolerance
}
} }
} finally {
probe.recycle()
} }
} }

View File

@@ -1,5 +1,5 @@
#Sat Dec 27 21:41:16 CST 2025 #Sat Dec 27 22:46:17 CST 2025
BUILD_TIME=1766842876384 BUILD_TIME=1766846777167
COMPILE_SDK_VERSION=36 COMPILE_SDK_VERSION=36
IMAGE_QUANT_CMAKE_VERSION=3.22.1 IMAGE_QUANT_CMAKE_VERSION=3.22.1
IMAGE_QUANT_NDK_VERSION=26.1.10909125 IMAGE_QUANT_NDK_VERSION=26.1.10909125