From ea76e293228fef3b99988506b4657e0bcf4831bc Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Mon, 9 Dec 2024 20:33:55 +0800 Subject: [PATCH] =?UTF-8?q?6.6.1=20-=20Alpha2=20-=20findOnce=20=E5=8F=8A?= =?UTF-8?q?=20find=20=E6=94=AF=E6=8C=81=E8=B4=9F=E6=95=B0=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../autojs/core/accessibility/UiSelector.kt | 54 ++++++++++++++----- version.properties | 6 +-- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/autojs/autojs/core/accessibility/UiSelector.kt b/app/src/main/java/org/autojs/autojs/core/accessibility/UiSelector.kt index 764fa027..012fdfe6 100644 --- a/app/src/main/java/org/autojs/autojs/core/accessibility/UiSelector.kt +++ b/app/src/main/java/org/autojs/autojs/core/accessibility/UiSelector.kt @@ -44,7 +44,6 @@ import org.autojs.autojs.core.automator.search.DFS import org.autojs.autojs.core.automator.search.SearchAlgorithm import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.api.StringReadable -import org.autojs.autojs.runtime.api.augment.util.Inspect import org.autojs.autojs.runtime.exception.ScriptInterruptedException import org.autojs.autojs.util.App import org.autojs.autojs.util.RhinoUtils @@ -653,7 +652,20 @@ open class UiSelector : UiObjectActions, StringReadable { fun findOnce(): UiObject? = findOnce(0) @ScriptInterface - fun findOnce(index: Int): UiObject? = find(index + 1).takeIf { index < it.size() }?.get(index) + fun findOnce(index: Int): UiObject? = when { + index >= 0 -> find(index + 1).let { found -> + when (index) { + in 0 until found.size() -> found[index] + else -> null + } + } + else -> find().let { found -> + when (val reverseIndex = index + found.size()) { + in 0 until found.size() -> found[reverseIndex] + else -> null + } + } + } @ScriptInterface fun exists() = findOnce() != null @@ -661,6 +673,33 @@ open class UiSelector : UiObjectActions, StringReadable { @ScriptInterface fun find(): UiObjectCollection = find(Int.MAX_VALUE) + @ScriptInterface + fun find(max: Int): UiObjectCollection { + mA11yTool.ensureService() + return when { + max >= 0 -> findInternal(max) + else -> findInternal(Int.MAX_VALUE).let { found -> + val foundSize = found.size() + when (val startIndex = foundSize + max) { + in 0 until foundSize -> { + of(found.nodes.slice(startIndex until foundSize)) + } + else -> EMPTY + } + } + } + } + + private fun findInternal(max: Int) = when { + mAccessibilityBridge == null -> findImpl(max) + isMainThread() -> findImpl(max) + mAccessibilityBridge.flags and AccessibilityBridge.FLAG_FIND_ON_UI_THREAD == 0 -> findImpl(max) + else -> VolatileBox().run { + mAccessibilityBridge.post { unblock(findImpl(max)) } + blockedGet() + } + } + @ScriptInterface fun findOne(timeout: Long): UiObject? { if (isMainThread()) { @@ -740,17 +779,6 @@ open class UiSelector : UiObjectActions, StringReadable { return of(result) } - protected fun find(max: Int): UiObjectCollection { - mA11yTool.ensureService() - mAccessibilityBridge ?: return findImpl(max) - if (isMainThread()) return findImpl(max) - if (mAccessibilityBridge.flags and AccessibilityBridge.FLAG_FIND_ON_UI_THREAD == 0) return findImpl(max) - return VolatileBox().run { - mAccessibilityBridge.post { unblock(findImpl(max)) } - blockedGet() - } - } - private fun findOf(root: UiObject, max: Int): UiObjectCollection = of(findAndReturnList(root, max)) private fun addFilter(filter: Filter) = also { selector.add(filter) } diff --git a/version.properties b/version.properties index 2ab8c7cc..a2cfce9a 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Mon Dec 09 11:04:44 CST 2024 -BUILD_TIME=1733713484875 +#Mon Dec 09 20:21:59 CST 2024 +BUILD_TIME=1733746919592 COMPILE_SDK_VERSION=34 JAVA_VERSION=23 JAVA_VERSION_MIN_RADICAL=0 @@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=34 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=2900 +VERSION_BUILD=2902 VERSION_NAME=6.6.1 Alpha2 VSCODE_EXT_REQUIRED_VERSION=1.0.8