api: selector.findOne(timeout), selector.findOnce(index)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.stardust.autojs.core.accessibility;
|
package com.stardust.autojs.core.accessibility;
|
||||||
|
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
@@ -111,6 +112,50 @@ public class UiSelector extends UiGlobalSelector {
|
|||||||
return uiObjectCollection;
|
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
|
@ScriptInterface
|
||||||
public UiObject findOne() {
|
public UiObject findOne() {
|
||||||
return untilFindOne();
|
return untilFindOne();
|
||||||
|
|||||||
Reference in New Issue
Block a user