6.6.1 - Alpha2 - findOnce 及 find 支持负数参数
This commit is contained in:
@@ -44,7 +44,6 @@ import org.autojs.autojs.core.automator.search.DFS
|
|||||||
import org.autojs.autojs.core.automator.search.SearchAlgorithm
|
import org.autojs.autojs.core.automator.search.SearchAlgorithm
|
||||||
import org.autojs.autojs.runtime.ScriptRuntime
|
import org.autojs.autojs.runtime.ScriptRuntime
|
||||||
import org.autojs.autojs.runtime.api.StringReadable
|
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.runtime.exception.ScriptInterruptedException
|
||||||
import org.autojs.autojs.util.App
|
import org.autojs.autojs.util.App
|
||||||
import org.autojs.autojs.util.RhinoUtils
|
import org.autojs.autojs.util.RhinoUtils
|
||||||
@@ -653,7 +652,20 @@ open class UiSelector : UiObjectActions, StringReadable {
|
|||||||
fun findOnce(): UiObject? = findOnce(0)
|
fun findOnce(): UiObject? = findOnce(0)
|
||||||
|
|
||||||
@ScriptInterface
|
@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
|
@ScriptInterface
|
||||||
fun exists() = findOnce() != null
|
fun exists() = findOnce() != null
|
||||||
@@ -661,6 +673,33 @@ open class UiSelector : UiObjectActions, StringReadable {
|
|||||||
@ScriptInterface
|
@ScriptInterface
|
||||||
fun find(): UiObjectCollection = find(Int.MAX_VALUE)
|
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<UiObjectCollection>().run {
|
||||||
|
mAccessibilityBridge.post { unblock(findImpl(max)) }
|
||||||
|
blockedGet()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ScriptInterface
|
@ScriptInterface
|
||||||
fun findOne(timeout: Long): UiObject? {
|
fun findOne(timeout: Long): UiObject? {
|
||||||
if (isMainThread()) {
|
if (isMainThread()) {
|
||||||
@@ -740,17 +779,6 @@ open class UiSelector : UiObjectActions, StringReadable {
|
|||||||
return of(result)
|
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<UiObjectCollection>().run {
|
|
||||||
mAccessibilityBridge.post { unblock(findImpl(max)) }
|
|
||||||
blockedGet()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findOf(root: UiObject, max: Int): UiObjectCollection = of(findAndReturnList(root, max))
|
private fun findOf(root: UiObject, max: Int): UiObjectCollection = of(findAndReturnList(root, max))
|
||||||
|
|
||||||
private fun addFilter(filter: Filter) = also { selector.add(filter) }
|
private fun addFilter(filter: Filter) = also { selector.add(filter) }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Mon Dec 09 11:04:44 CST 2024
|
#Mon Dec 09 20:21:59 CST 2024
|
||||||
BUILD_TIME=1733713484875
|
BUILD_TIME=1733746919592
|
||||||
COMPILE_SDK_VERSION=34
|
COMPILE_SDK_VERSION=34
|
||||||
JAVA_VERSION=23
|
JAVA_VERSION=23
|
||||||
JAVA_VERSION_MIN_RADICAL=0
|
JAVA_VERSION_MIN_RADICAL=0
|
||||||
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
|
|||||||
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
|
||||||
TARGET_SDK_VERSION=34
|
TARGET_SDK_VERSION=34
|
||||||
TARGET_SDK_VERSION_INRT=29
|
TARGET_SDK_VERSION_INRT=29
|
||||||
VERSION_BUILD=2900
|
VERSION_BUILD=2902
|
||||||
VERSION_NAME=6.6.1 Alpha2
|
VERSION_NAME=6.6.1 Alpha2
|
||||||
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
VSCODE_EXT_REQUIRED_VERSION=1.0.8
|
||||||
|
|||||||
Reference in New Issue
Block a user