mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-29 21:03:01 +08:00
commit
d9b3a4ac27
@ -15,7 +15,7 @@ import com.stardust.autojs.engine.LoopBasedJavaScriptEngine;
|
||||
import com.stardust.autojs.engine.RootAutomatorEngine;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.engine.ScriptEngineManager;
|
||||
import com.stardust.autojs.core.bridge.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.accessibility.AccessibilityBridge;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.core.console.GlobalStardustConsole;
|
||||
import com.stardust.autojs.runtime.exception.ScriptException;
|
||||
|
||||
@ -14,13 +14,32 @@ var loadJar = function(path){
|
||||
__runtime__.loadJar(path);
|
||||
}
|
||||
|
||||
__runtime__.bridges.setFunctionCaller(function(func, target, args){
|
||||
var arr = [];
|
||||
var len = args.length;
|
||||
for(var i = 0; i < len; i++){
|
||||
arr.push(args[i]);
|
||||
}
|
||||
return func.apply(target, arr);
|
||||
__runtime__.bridges.setBridges({
|
||||
call: function(func, target, args){
|
||||
var arr = [];
|
||||
var len = args.length;
|
||||
for(var i = 0; i < len; i++){
|
||||
arr.push(args[i]);
|
||||
}
|
||||
return func.apply(target, arr);
|
||||
},
|
||||
toArray: function(o){
|
||||
var arr = [];
|
||||
for(var i = 0; i < o.size(); i++){
|
||||
arr.push(o.get(i));
|
||||
}
|
||||
for(var key in o){
|
||||
if(arr[key])
|
||||
continue;
|
||||
var v = o[key];
|
||||
if(typeof(v) == 'function'){
|
||||
arr[key] = v.bind(o);
|
||||
}else{
|
||||
arr[key] = v;
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
});
|
||||
|
||||
var __that__ = this;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.stardust.autojs.core.bridge;
|
||||
package com.stardust.autojs.core.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
@ -1,36 +0,0 @@
|
||||
package com.stardust.autojs.core.accessibility;
|
||||
|
||||
import com.stardust.autojs.core.bridge.ScriptBridges;
|
||||
import com.stardust.automator.UiObject;
|
||||
import com.stardust.automator.UiObjectCollection;
|
||||
import com.stardust.view.accessibility.AccessibilityNodeInfoAllocator;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/31.
|
||||
*/
|
||||
|
||||
public class ScriptUiObject extends UiObject {
|
||||
|
||||
private ScriptBridges mScriptBridges;
|
||||
|
||||
public ScriptUiObject(Object info, ScriptBridges scriptBridges) {
|
||||
super(info);
|
||||
mScriptBridges = scriptBridges;
|
||||
}
|
||||
|
||||
public ScriptUiObject(Object info, AccessibilityNodeInfoAllocator allocator, boolean isRootNode, ScriptBridges scriptBridges) {
|
||||
super(info, allocator, isRootNode);
|
||||
mScriptBridges = scriptBridges;
|
||||
}
|
||||
|
||||
public ScriptUiObject(Object info, AccessibilityNodeInfoAllocator allocator, ScriptBridges scriptBridges) {
|
||||
super(info, allocator);
|
||||
mScriptBridges = scriptBridges;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object children() {
|
||||
return super.children();
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,6 @@ import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.autojs.annotation.ScriptInterface;
|
||||
import com.stardust.autojs.core.bridge.AccessibilityBridge;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.accessibility.AutomatorConfig;
|
||||
import com.stardust.automator.GlobalActionAutomator;
|
||||
@ -21,6 +20,9 @@ import com.stardust.automator.simple_action.SimpleAction;
|
||||
import com.stardust.util.DeveloperUtils;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.NativeJavaObject;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
*/
|
||||
|
||||
@ -0,0 +1,196 @@
|
||||
package com.stardust.autojs.core.accessibility;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.automator.ActionArgument;
|
||||
import com.stardust.automator.UiGlobalSelector;
|
||||
import com.stardust.automator.UiObject;
|
||||
import com.stardust.automator.UiObjectCollection;
|
||||
import com.stardust.util.ArrayUtils;
|
||||
import com.stardust.util.Consumer;
|
||||
import com.stardust.util.Func1;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
import org.mozilla.javascript.NativeJavaObject;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.ast.Scope;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/31.
|
||||
*/
|
||||
|
||||
public class UiCollection extends NativeJavaObject {
|
||||
|
||||
private UiObjectCollection mUiObjectCollection;
|
||||
|
||||
public UiCollection(UiObjectCollection c, Scriptable scope) {
|
||||
super(scope, c, UiObjectCollection.class);
|
||||
mUiObjectCollection = c;
|
||||
}
|
||||
|
||||
public boolean performAction(int action) {
|
||||
return mUiObjectCollection.performAction(action);
|
||||
}
|
||||
|
||||
public boolean performAction(int action, ActionArgument... arguments) {
|
||||
return mUiObjectCollection.performAction(action, arguments);
|
||||
}
|
||||
|
||||
public boolean click() {
|
||||
return mUiObjectCollection.click();
|
||||
}
|
||||
|
||||
public boolean longClick() {
|
||||
return mUiObjectCollection.longClick();
|
||||
}
|
||||
|
||||
public boolean accessibilityFocus() {
|
||||
return mUiObjectCollection.accessibilityFocus();
|
||||
}
|
||||
|
||||
public boolean clearAccessibilityFocus() {
|
||||
return mUiObjectCollection.clearAccessibilityFocus();
|
||||
}
|
||||
|
||||
public boolean focus() {
|
||||
return mUiObjectCollection.focus();
|
||||
}
|
||||
|
||||
public boolean clearFocus() {
|
||||
return mUiObjectCollection.clearFocus();
|
||||
}
|
||||
|
||||
public boolean copy() {
|
||||
return mUiObjectCollection.copy();
|
||||
}
|
||||
|
||||
public boolean paste() {
|
||||
return mUiObjectCollection.paste();
|
||||
}
|
||||
|
||||
public boolean select() {
|
||||
return mUiObjectCollection.select();
|
||||
}
|
||||
|
||||
public boolean cut() {
|
||||
return mUiObjectCollection.cut();
|
||||
}
|
||||
|
||||
public boolean collapse() {
|
||||
return mUiObjectCollection.collapse();
|
||||
}
|
||||
|
||||
|
||||
public boolean expand() {
|
||||
return mUiObjectCollection.expand();
|
||||
}
|
||||
|
||||
public boolean dismiss() {
|
||||
return mUiObjectCollection.dismiss();
|
||||
}
|
||||
|
||||
public boolean show() {
|
||||
return mUiObjectCollection.show();
|
||||
}
|
||||
|
||||
public boolean scrollForward() {
|
||||
return mUiObjectCollection.scrollForward();
|
||||
}
|
||||
|
||||
public boolean scrollBackward() {
|
||||
return mUiObjectCollection.scrollBackward();
|
||||
}
|
||||
|
||||
public boolean scrollUp() {
|
||||
return mUiObjectCollection.scrollUp();
|
||||
}
|
||||
|
||||
public boolean scrollDown() {
|
||||
return mUiObjectCollection.scrollDown();
|
||||
}
|
||||
|
||||
public boolean scrollLeft() {
|
||||
return mUiObjectCollection.scrollLeft();
|
||||
}
|
||||
|
||||
public boolean scrollRight() {
|
||||
return mUiObjectCollection.scrollRight();
|
||||
}
|
||||
|
||||
public boolean contextClick() {
|
||||
return mUiObjectCollection.contextClick();
|
||||
}
|
||||
|
||||
public boolean setSelection(int s, int e) {
|
||||
return mUiObjectCollection.setSelection(s, e);
|
||||
}
|
||||
|
||||
public boolean setText(CharSequence text) {
|
||||
return mUiObjectCollection.setText(text);
|
||||
}
|
||||
|
||||
public boolean setProgress(float value) {
|
||||
return mUiObjectCollection.setProgress(value);
|
||||
}
|
||||
|
||||
public boolean scrollTo(int row, int column) {
|
||||
return mUiObjectCollection.scrollTo(row, column);
|
||||
}
|
||||
|
||||
public UiCollection each(Consumer<UiObject> consumer) {
|
||||
mUiObjectCollection.each(consumer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public UiCollection find(UiGlobalSelector selector) {
|
||||
return new UiCollection(mUiObjectCollection.find(selector), getParentScope());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public UiObject findOne(UiGlobalSelector selector) {
|
||||
return mUiObjectCollection.findOne(selector);
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
return mUiObjectCollection.empty();
|
||||
}
|
||||
|
||||
public boolean nonEmpty() {
|
||||
return mUiObjectCollection.nonEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean has(int index, Scriptable start) {
|
||||
return index > 0 && index < mUiObjectCollection.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index, Scriptable start) {
|
||||
return mUiObjectCollection.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String name, Scriptable start) {
|
||||
if ("length".equals(name)) {
|
||||
return mUiObjectCollection.size();
|
||||
}
|
||||
return super.get(name, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String name, Scriptable start) {
|
||||
if ("length".equals(name)) {
|
||||
return true;
|
||||
}
|
||||
return super.has(name, start);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
package com.stardust.autojs.core.accessibility;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.autojs.annotation.ScriptInterface;
|
||||
import com.stardust.autojs.core.bridge.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.bridge.ScriptBridges;
|
||||
import com.stardust.autojs.runtime.accessibility.AutomatorConfig;
|
||||
import com.stardust.autojs.runtime.api.UI;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.automator.ActionArgument;
|
||||
import com.stardust.automator.UiGlobalSelector;
|
||||
@ -59,33 +55,22 @@ public class UiSelector extends UiGlobalSelector {
|
||||
|
||||
|
||||
private static final String TAG = "UiSelector";
|
||||
private static Object sEmptyUiCollection;
|
||||
|
||||
private AccessibilityBridge mAccessibilityBridge;
|
||||
private AccessibilityNodeInfoAllocator mAllocator = null;
|
||||
private ScriptBridges mScriptBridges;
|
||||
|
||||
public UiSelector(ScriptBridges bridges) {
|
||||
this(bridges, null);
|
||||
public UiSelector(AccessibilityBridge accessibilityBridge) {
|
||||
mAccessibilityBridge = accessibilityBridge;
|
||||
}
|
||||
|
||||
public UiSelector(ScriptBridges bridges, AccessibilityNodeInfoAllocator allocator) {
|
||||
mAccessibilityBridge = bridges.getAccessibilityBrige();
|
||||
mScriptBridges = bridges;
|
||||
public UiSelector(AccessibilityBridge accessibilityBridge, AccessibilityNodeInfoAllocator allocator) {
|
||||
mAccessibilityBridge = accessibilityBridge;
|
||||
mAllocator = allocator;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ScriptInterface
|
||||
public Object find() {
|
||||
UiObjectCollection c = findInner();
|
||||
if(c == UiObjectCollection.EMPTY){
|
||||
return emptyUiCollection();
|
||||
}
|
||||
return mScriptBridges.wrapAsArray(c);
|
||||
}
|
||||
|
||||
protected UiObjectCollection findInner(){
|
||||
public UiObjectCollection find() {
|
||||
ensureAccessibilityServiceEnabled();
|
||||
if (AutomatorConfig.isUnintendedGuardEnabled() && isRunningPackageSelf()) {
|
||||
Log.d(TAG, "isSelfPackage return null");
|
||||
@ -95,22 +80,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
if (root == null) {
|
||||
return UiObjectCollection.EMPTY;
|
||||
}
|
||||
return super.findOf(UiObject.createRoot(root, mAllocator));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object findOf(UiObject node) {
|
||||
return mScriptBridges.wrapAsArray((Iterable<?>) super.findOf(node));
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
private Object emptyUiCollection() {
|
||||
if(sEmptyUiCollection == null){
|
||||
sEmptyUiCollection = mScriptBridges.wrapAsArray(UiObjectCollection.EMPTY);
|
||||
}
|
||||
return sEmptyUiCollection;
|
||||
return findOf(UiObject.createRoot(root, mAllocator));
|
||||
}
|
||||
|
||||
|
||||
@ -125,15 +95,8 @@ public class UiSelector extends UiGlobalSelector {
|
||||
|
||||
@ScriptInterface
|
||||
@NonNull
|
||||
public Object untilFind() {
|
||||
return mScriptBridges.wrapAsArray(untilFindInner());
|
||||
}
|
||||
|
||||
|
||||
@ScriptInterface
|
||||
@NonNull
|
||||
protected UiObjectCollection untilFindInner() {
|
||||
UiObjectCollection uiObjectCollection = findInner();
|
||||
public UiObjectCollection untilFind() {
|
||||
UiObjectCollection uiObjectCollection = find();
|
||||
while (uiObjectCollection.empty()) {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new ScriptInterruptedException();
|
||||
@ -143,7 +106,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
} catch (InterruptedException e) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
uiObjectCollection = findInner();
|
||||
uiObjectCollection = find();
|
||||
}
|
||||
return uiObjectCollection;
|
||||
}
|
||||
@ -155,13 +118,13 @@ public class UiSelector extends UiGlobalSelector {
|
||||
|
||||
@ScriptInterface
|
||||
public boolean exists() {
|
||||
UiObjectCollection collection = findInner();
|
||||
UiObjectCollection collection = find();
|
||||
return collection.nonEmpty();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public UiObject untilFindOne() {
|
||||
UiObjectCollection collection = untilFindInner();
|
||||
UiObjectCollection collection = untilFind();
|
||||
return new UiObject(collection.get(0).getInfo());
|
||||
}
|
||||
|
||||
@ -188,7 +151,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
|
||||
|
||||
private boolean performAction(int action, ActionArgument... arguments) {
|
||||
return untilFindInner().performAction(action, arguments);
|
||||
return untilFind().performAction(action, arguments);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
package com.stardust.autojs.core.bridge;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/31.
|
||||
*/
|
||||
|
||||
public abstract class ScriptBridges {
|
||||
|
||||
|
||||
public abstract Object toArray(Object[] nativeArray);
|
||||
|
||||
public abstract Object toString(String nativeString);
|
||||
|
||||
public abstract Object callFunction(Object function, Object target, Object[] args);
|
||||
|
||||
public abstract Object wrapAsArray(Iterable<?> iterable);
|
||||
|
||||
public abstract AccessibilityBridge getAccessibilityBrige();
|
||||
|
||||
}
|
||||
@ -3,19 +3,25 @@ package com.stardust.autojs.engine;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.autojs.BuildConfig;
|
||||
import com.stardust.autojs.core.accessibility.UiCollection;
|
||||
import com.stardust.autojs.rhino.AndroidContextFactory;
|
||||
import com.stardust.autojs.rhino.RhinoAndroidHelper;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.autojs.script.JavaScriptSource;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.automator.UiObjectCollection;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.ImporterTopLevel;
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
import org.mozilla.javascript.ScriptRuntime;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.TopLevel;
|
||||
import org.mozilla.javascript.WrapFactory;
|
||||
import org.mozilla.javascript.commonjs.module.RequireBuilder;
|
||||
import org.mozilla.javascript.commonjs.module.provider.SoftCachingModuleScriptProvider;
|
||||
import org.mozilla.javascript.tools.debugger.Dim;
|
||||
@ -23,9 +29,12 @@ import org.mozilla.javascript.tools.debugger.Dim;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
@ -33,7 +42,13 @@ import java.util.List;
|
||||
|
||||
public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
|
||||
public interface TypeWrapper {
|
||||
|
||||
Object wrap(Context cx, Scriptable scope, Object obj, Class<?> staticType);
|
||||
}
|
||||
|
||||
private static final String LOG_TAG = "RhinoJavaScriptEngine";
|
||||
private static Constructor<?> nativeStringConstructor;
|
||||
|
||||
private static int contextCount = 0;
|
||||
private static StringScriptSource sInitScript;
|
||||
@ -124,6 +139,7 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
.setSandboxed(true)
|
||||
.createRequire(context, scope)
|
||||
.install(scope);
|
||||
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
@ -148,9 +164,36 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
contextCount++;
|
||||
context.setOptimizationLevel(-1);
|
||||
context.setLanguageVersion(Context.VERSION_ES6);
|
||||
context.setLocale(Locale.getDefault());
|
||||
context.setWrapFactory(new WrapFactory());
|
||||
return context;
|
||||
}
|
||||
|
||||
private Object createNativeString(Object obj) {
|
||||
if (nativeStringConstructor == null)
|
||||
return obj;
|
||||
try {
|
||||
return nativeStringConstructor.newInstance(obj.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
private class WrapFactory extends org.mozilla.javascript.WrapFactory {
|
||||
@Override
|
||||
public Object wrap(Context cx, Scriptable scope, Object obj, Class<?> staticType) {
|
||||
if (staticType == String.class) {
|
||||
return createNativeString(obj);
|
||||
}
|
||||
if (staticType == UiObjectCollection.class ) {
|
||||
return getRuntime().bridges.toArray(obj);
|
||||
|
||||
}
|
||||
return super.wrap(cx, scope, obj, staticType);
|
||||
}
|
||||
}
|
||||
|
||||
private static class InterruptibleAndroidContextFactory extends AndroidContextFactory {
|
||||
|
||||
public InterruptibleAndroidContextFactory(File cacheDirectory) {
|
||||
@ -172,4 +215,14 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
Class c = Class.forName("org.mozilla.javascript.NativeString");
|
||||
nativeStringConstructor = c.getDeclaredConstructor(CharSequence.class);
|
||||
nativeStringConstructor.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,29 +1,41 @@
|
||||
package com.stardust.autojs.runtime;
|
||||
|
||||
import com.stardust.autojs.core.accessibility.UiCollection;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/21.
|
||||
*/
|
||||
|
||||
public class ScriptBridges {
|
||||
|
||||
public interface FunctionCaller {
|
||||
public interface Bridges {
|
||||
|
||||
Object[] NO_ARGUMENTS = new Object[0];
|
||||
|
||||
Object call(Object func, Object target, Object[] arg);
|
||||
|
||||
Object toArray(Object o);
|
||||
}
|
||||
|
||||
private FunctionCaller mFunctionCaller;
|
||||
private Bridges mBridges;
|
||||
|
||||
public void setFunctionCaller(FunctionCaller functionCaller) {
|
||||
mFunctionCaller = functionCaller;
|
||||
public void setBridges(Bridges bridges) {
|
||||
mBridges = bridges;
|
||||
}
|
||||
|
||||
public Object callFunction(Object func, Object target, Object[] args) {
|
||||
if (mFunctionCaller == null)
|
||||
throw new IllegalStateException("no function caller");
|
||||
return mFunctionCaller.call(func, target, args);
|
||||
checkBridges();
|
||||
return mBridges.call(func, target, args);
|
||||
}
|
||||
|
||||
private void checkBridges() {
|
||||
if (mBridges == null)
|
||||
throw new IllegalStateException("no bridges set");
|
||||
}
|
||||
|
||||
|
||||
public Object toArray(Object c) {
|
||||
checkBridges();
|
||||
return mBridges.toArray(c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import android.os.Looper;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.ScriptEngineService;
|
||||
import com.stardust.autojs.annotation.ScriptVariable;
|
||||
import com.stardust.autojs.core.bridge.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.accessibility.AccessibilityBridge;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.rhino.AndroidClassLoader;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
@ -25,6 +25,7 @@ import com.stardust.autojs.runtime.exception.ScriptEnvironmentException;
|
||||
import com.stardust.autojs.runtime.exception.ScriptException;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.autojs.core.accessibility.SimpleActionAutomator;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.autojs.runtime.api.UI;
|
||||
import com.stardust.concurrent.VolatileDispose;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
|
||||
@ -47,7 +47,10 @@ public class AppUtils {
|
||||
|
||||
@ScriptInterface
|
||||
public boolean launchApp(String appName) {
|
||||
return launchPackage(getPackageName(appName));
|
||||
String pkg = getPackageName(appName);
|
||||
if(pkg == null)
|
||||
return false;
|
||||
return launchPackage(pkg);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
|
||||
@ -6,9 +6,10 @@ import android.graphics.Point;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.bridge.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.accessibility.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.eventloop.EventEmitter;
|
||||
import com.stardust.notification.Notification;
|
||||
import com.stardust.notification.NotificationListenerService;
|
||||
|
||||
@ -351,19 +351,13 @@ public class UiGlobalSelector {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Note: The method use a dirty template to make its child class can
|
||||
* change the type of return value.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T findOf(UiObject node) {
|
||||
public UiObjectCollection findOf(UiObject node) {
|
||||
List<UiObject> list = new ArrayList<>();
|
||||
list.add(node);
|
||||
for (ListFilter filter : mFilters) {
|
||||
list = filter.filter(list);
|
||||
}
|
||||
return (T) UiObjectCollection.of(list);
|
||||
return UiObjectCollection.of(list);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@ -97,7 +97,7 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T find(UiGlobalSelector selector) {
|
||||
public UiObjectCollection find(UiGlobalSelector selector) {
|
||||
return selector.findOf(this);
|
||||
}
|
||||
|
||||
@ -105,13 +105,12 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
return selector.findOneOf(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T children() {
|
||||
public UiObjectCollection children() {
|
||||
ArrayList<AccessibilityNodeInfoCompat> list = new ArrayList<>(getChildCount());
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
list.add(getChild(i));
|
||||
}
|
||||
return (T) UiObjectCollection.ofCompat(list);
|
||||
return UiObjectCollection.ofCompat(list);
|
||||
}
|
||||
|
||||
public int childCount() {
|
||||
|
||||
@ -2,7 +2,6 @@ package com.stardust.automator;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
@ -11,11 +10,8 @@ import com.stardust.util.Consumer;
|
||||
import com.stardust.util.Func1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import static android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.*;
|
||||
import static android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CONTEXT_CLICK;
|
||||
@ -31,7 +27,7 @@ import static android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.
|
||||
* Created by Stardust on 2017/3/9.
|
||||
*/
|
||||
|
||||
public class UiObjectCollection implements List<UiObject> {
|
||||
public class UiObjectCollection {
|
||||
|
||||
public static final UiObjectCollection EMPTY = UiObjectCollection.of(Collections.<UiObject>emptyList());
|
||||
|
||||
@ -53,10 +49,14 @@ public class UiObjectCollection implements List<UiObject> {
|
||||
|
||||
private List<UiObject> mNodes;
|
||||
|
||||
protected UiObjectCollection(List<UiObject> list) {
|
||||
private UiObjectCollection(List<UiObject> list) {
|
||||
mNodes = list;
|
||||
}
|
||||
|
||||
public UiObject[] toArray(){
|
||||
return mNodes.toArray(new UiObject[mNodes.size()]);
|
||||
}
|
||||
|
||||
public boolean performAction(int action) {
|
||||
boolean fail = false;
|
||||
for (UiObject node : mNodes) {
|
||||
@ -193,126 +193,14 @@ public class UiObjectCollection implements List<UiObject> {
|
||||
new ActionArgument.IntActionArgument(ACTION_ARGUMENT_COLUMN_INT, column));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UiObject get(int i) {
|
||||
return mNodes.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UiObject set(int index, UiObject element) {
|
||||
return mNodes.set(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, UiObject element) {
|
||||
mNodes.add(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UiObject remove(int index) {
|
||||
return mNodes.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
return mNodes.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
return mNodes.lastIndexOf(o);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ListIterator<UiObject> listIterator() {
|
||||
return mNodes.listIterator();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ListIterator<UiObject> listIterator(int index) {
|
||||
return mNodes.listIterator(index);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public UiObjectCollection subList(int fromIndex, int toIndex) {
|
||||
return UiObjectCollection.of(mNodes.subList(fromIndex, toIndex));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mNodes.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return mNodes.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return mNodes.contains(o);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Iterator<UiObject> iterator() {
|
||||
return mNodes.iterator();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return mNodes.toArray();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T> T[] toArray(@NonNull T[] a) {
|
||||
return mNodes.toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(UiObject uiObject) {
|
||||
return mNodes.add(uiObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return mNodes.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(@NonNull Collection<?> c) {
|
||||
return mNodes.containsAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(@NonNull Collection<? extends UiObject> c) {
|
||||
return mNodes.addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, @NonNull Collection<? extends UiObject> c) {
|
||||
return mNodes.addAll(index, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(@NonNull Collection<?> c) {
|
||||
return mNodes.retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(@NonNull Collection<?> c) {
|
||||
return mNodes.retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
mNodes.clear();
|
||||
}
|
||||
|
||||
public UiObjectCollection each(Consumer<UiObject> consumer) {
|
||||
for (UiObject uiObject : mNodes) {
|
||||
consumer.accept(uiObject);
|
||||
@ -320,19 +208,10 @@ public class UiObjectCollection implements List<UiObject> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public UiObjectCollection filter(Func1<UiObject, Boolean> func1) {
|
||||
List<UiObject> list = new ArrayList<>();
|
||||
for (UiObject uiObject : mNodes) {
|
||||
if (func1.call(uiObject))
|
||||
list.add(uiObject);
|
||||
}
|
||||
return of(list);
|
||||
}
|
||||
|
||||
public UiObjectCollection find(UiGlobalSelector selector) {
|
||||
List<UiObject> list = new ArrayList<>();
|
||||
for (UiObject object : mNodes) {
|
||||
list.addAll(((UiObjectCollection) selector.findOf(object)).mNodes);
|
||||
list.addAll(selector.findOf(object).mNodes);
|
||||
}
|
||||
return of(list);
|
||||
}
|
||||
@ -348,11 +227,11 @@ public class UiObjectCollection implements List<UiObject> {
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
return isEmpty();
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
public boolean nonEmpty() {
|
||||
return !isEmpty();
|
||||
return size() != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.stardust.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -34,4 +35,12 @@ public class ArrayUtils {
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T[] merge(T[] a1, T[] a2) {
|
||||
T[] a = (T[]) Array.newInstance(a1.getClass().getComponentType(), a1.length + a2.length);
|
||||
System.arraycopy(a1, 0, a, 0, a1.length);
|
||||
System.arraycopy(a2, 0, a, a1.length, a2.length);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import com.stardust.auojs.inrt.App;
|
||||
import com.stardust.auojs.inrt.R;
|
||||
import com.stardust.autojs.ScriptEngineService;
|
||||
import com.stardust.autojs.ScriptEngineServiceBuilder;
|
||||
import com.stardust.autojs.core.bridge.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.accessibility.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.console.GlobalStardustConsole;
|
||||
import com.stardust.autojs.core.inputevent.InputEventObserver;
|
||||
import com.stardust.autojs.core.record.accessibility.AccessibilityActionRecorder;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user