mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
api: selector.findOne(timeout), selector.findOnce(index)
This commit is contained in:
parent
cd5def8700
commit
6ea30c6fcc
@ -1,5 +1,6 @@
|
||||
package com.stardust.autojs.core.accessibility;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
@ -111,6 +112,50 @@ public class UiSelector extends UiGlobalSelector {
|
||||
return uiObjectCollection;
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public UiObject findOne(long timeout) {
|
||||
if (timeout == -1) {
|
||||
return untilFindOne();
|
||||
}
|
||||
UiObjectCollection uiObjectCollection = find();
|
||||
long start = SystemClock.uptimeMillis();
|
||||
while (uiObjectCollection.empty()) {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
if (SystemClock.uptimeMillis() - start > timeout) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
uiObjectCollection = find();
|
||||
}
|
||||
|
||||
return uiObjectCollection.get(0);
|
||||
}
|
||||
|
||||
public UiObject findOnce(int index) {
|
||||
UiObjectCollection uiObjectCollection = find();
|
||||
while (uiObjectCollection.empty()) {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
uiObjectCollection = find();
|
||||
}
|
||||
if (index >= uiObjectCollection.size()) {
|
||||
return null;
|
||||
}
|
||||
return uiObjectCollection.get(index);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public UiObject findOne() {
|
||||
return untilFindOne();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user