add dialogs, fix code completion
This commit is contained in:
@@ -17,28 +17,30 @@ var toast = function(text){
|
||||
__runtime__.toast(text);
|
||||
}
|
||||
|
||||
var app = __runtime__.app;
|
||||
|
||||
var launchPackage = function(package){
|
||||
__runtime__.app.launchPackage(package);
|
||||
app.launchPackage(package);
|
||||
}
|
||||
|
||||
var launch = function(a, b){
|
||||
if(arguments.length == 2){
|
||||
__runtime__.app.launch(a, b);
|
||||
app.launch(a, b);
|
||||
}else{
|
||||
__runtime__.app.launchPackage(a);
|
||||
app.launchPackage(a);
|
||||
}
|
||||
}
|
||||
|
||||
var launchApp = function(appName){
|
||||
__runtime__.app.launchApp(appName);
|
||||
app.launchApp(appName);
|
||||
}
|
||||
|
||||
var getPackageName = function(appName){
|
||||
return __runtime__.app.getPackageName(appName);
|
||||
return app.getPackageName(appName);
|
||||
}
|
||||
|
||||
var openAppSetting = function(packageName){
|
||||
return __runtime__.app.openAppSetting(packageName);
|
||||
return app.openAppSetting(packageName);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +184,11 @@ var setClip = function(text){
|
||||
}
|
||||
|
||||
|
||||
var SetScreenMetrics = function(w, h){
|
||||
__runtime__.SetScreenMetrics(w, h);
|
||||
}
|
||||
|
||||
|
||||
var Tap = function(x, y){
|
||||
__runtime__.shellExecAsync("input tap " + x + " " + y);
|
||||
}
|
||||
|
||||
@@ -43,9 +43,19 @@ public class ScriptEngineService {
|
||||
EVENT_BUS.post(new ScriptExecutionEvent(ScriptExecutionEvent.ON_START, execution.getSource().toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(ScriptExecution execution, Object result) {
|
||||
onFinish(execution);
|
||||
}
|
||||
|
||||
private void onFinish(ScriptExecution execution) {
|
||||
execution.getRuntime().onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(ScriptExecution execution, Exception e) {
|
||||
e.printStackTrace();
|
||||
onFinish(execution);
|
||||
if (!causedByInterrupted(e)) {
|
||||
execution.getRuntime().console.error(e.getMessage());
|
||||
EVENT_BUS.post(new ScriptExecutionEvent(ScriptExecutionEvent.ON_EXCEPTION, e.getMessage()));
|
||||
@@ -54,7 +64,7 @@ public class ScriptEngineService {
|
||||
};
|
||||
|
||||
|
||||
private final Supplier<ScriptRuntime> mRuntimeSupplier;
|
||||
private final Supplier<? extends ScriptRuntime> mRuntimeSupplier;
|
||||
private final Context mContext;
|
||||
private UiHandler mUiHandler;
|
||||
private final Console mGlobalConsole;
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.stardust.util.UiHandler;
|
||||
|
||||
public class ScriptEngineServiceBuilder {
|
||||
|
||||
Supplier<ScriptRuntime> mRuntimeSupplier;
|
||||
Supplier<? extends ScriptRuntime> mRuntimeSupplier;
|
||||
ScriptEngineManager mScriptEngineManager;
|
||||
Console mGlobalConsole;
|
||||
UiHandler mUiHandler;
|
||||
@@ -22,7 +22,7 @@ public class ScriptEngineServiceBuilder {
|
||||
|
||||
}
|
||||
|
||||
public ScriptEngineServiceBuilder runtime(Supplier<ScriptRuntime> runtimeSupplier) {
|
||||
public ScriptEngineServiceBuilder runtime(Supplier<? extends ScriptRuntime> runtimeSupplier) {
|
||||
mRuntimeSupplier = runtimeSupplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ public class RhinoJavaScriptEngineManager extends AbstractScriptEngineManager {
|
||||
ScriptEngine engine = createEngine();
|
||||
ScriptSource source = new StringScriptSource("this", "this");
|
||||
engine.setTag("script", source);
|
||||
engine.init();
|
||||
Scriptable scriptable = (Scriptable) engine.execute(source);
|
||||
Object[] ids = scriptable.getIds();
|
||||
String[] functions = new String[ids.length];
|
||||
|
||||
@@ -25,15 +25,19 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mScriptEngine = mScriptEngineService.createScriptEngine();
|
||||
mScriptRuntime = mScriptEngineService.createScriptRuntime();
|
||||
execute(mScriptRuntime, mScriptEngine);
|
||||
execute();
|
||||
}
|
||||
|
||||
private void execute(ScriptRuntime runtime, ScriptEngine engine) {
|
||||
public Object execute() {
|
||||
mScriptEngine = mScriptEngineService.createScriptEngine();
|
||||
mScriptRuntime = mScriptEngineService.createScriptRuntime();
|
||||
return execute(mScriptRuntime, mScriptEngine);
|
||||
}
|
||||
|
||||
private Object execute(ScriptRuntime runtime, ScriptEngine engine) {
|
||||
try {
|
||||
prepare(runtime, engine);
|
||||
doExecution(engine);
|
||||
return doExecution(engine);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
getListener().onException(this, e);
|
||||
@@ -41,6 +45,7 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
Log.d(TAG, "Engine destroy");
|
||||
engine.destroy();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void prepare(ScriptRuntime runtime, ScriptEngine engine) {
|
||||
@@ -51,10 +56,12 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
engine.init();
|
||||
}
|
||||
|
||||
private void doExecution(ScriptEngine engine) {
|
||||
private Object doExecution(ScriptEngine engine) {
|
||||
engine.setTag("script", getSource());
|
||||
getListener().onStart(this);
|
||||
getListener().onSuccess(this, engine.execute(getSource()));
|
||||
Object result = engine.execute(getSource());
|
||||
getListener().onSuccess(this, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,17 +14,17 @@ import com.stardust.view.accessibility.AccessibilityInfoProvider;
|
||||
|
||||
public abstract class AbstractScriptRuntime {
|
||||
|
||||
@JavascriptField
|
||||
public AppUtils app;
|
||||
@ScriptVariable
|
||||
public AppUtils app;
|
||||
|
||||
@JavascriptField
|
||||
public Console console;
|
||||
@ScriptVariable
|
||||
public Console console;
|
||||
|
||||
@JavascriptField
|
||||
public SimpleActionAutomator automator;
|
||||
@ScriptVariable
|
||||
public SimpleActionAutomator automator;
|
||||
|
||||
@JavascriptField
|
||||
public AccessibilityInfoProvider info;
|
||||
@ScriptVariable
|
||||
public AccessibilityInfoProvider info;
|
||||
|
||||
public AbstractScriptRuntime(AppUtils app, Console console, AccessibilityBridge bridge) {
|
||||
this.app = app;
|
||||
@@ -36,35 +36,40 @@ public abstract class AbstractScriptRuntime {
|
||||
public AbstractScriptRuntime() {
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract void toast(final String text);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract void sleep(long millis);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract void setClip(final String text);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract void shellExecAsync(String cmd);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract AbstractShell.Result shell(String cmd, int root);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract UiSelector selector(ScriptEngine engine);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract boolean isStopped();
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract void requiresApi(int i);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract void loadJar(String path);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public abstract void stop();
|
||||
|
||||
@ScriptInterface
|
||||
public abstract void SetScreenMetrics(int width, int height);
|
||||
|
||||
public abstract void ensureAccessibilityServiceEnabled();
|
||||
|
||||
public abstract void onStop();
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ import java.lang.annotation.Target;
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface JavascriptClass {
|
||||
public @interface ScriptClass {
|
||||
}
|
||||
@@ -10,5 +10,5 @@ import java.lang.annotation.Target;
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface JavascriptInterface {
|
||||
public @interface ScriptInterface {
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.util.ClipboardUtil;
|
||||
import com.stardust.autojs.runtime.api.ProcessShell;
|
||||
import com.stardust.util.SdkVersionUtil;
|
||||
import com.stardust.util.Supplier;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
@@ -29,15 +30,69 @@ public class ScriptRuntime extends AbstractScriptRuntime {
|
||||
|
||||
private static final String TAG = "ScriptRuntime";
|
||||
|
||||
public static class Builder {
|
||||
private AppUtils mAppUtils;
|
||||
private UiHandler mUiHandler;
|
||||
private Console mConsole;
|
||||
private AccessibilityBridge mAccessibilityBridge;
|
||||
private Supplier<AbstractShell> mShellSupplier;
|
||||
|
||||
|
||||
public Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder setAppUtils(AppUtils appUtils) {
|
||||
mAppUtils = appUtils;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUiHandler(UiHandler uiHandler) {
|
||||
mUiHandler = uiHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setConsole(Console console) {
|
||||
mConsole = console;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAccessibilityBridge(AccessibilityBridge accessibilityBridge) {
|
||||
mAccessibilityBridge = accessibilityBridge;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setShellSupplier(Supplier<AbstractShell> shellSupplier) {
|
||||
mShellSupplier = shellSupplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScriptRuntime build() {
|
||||
return new ScriptRuntime(mAppUtils, mUiHandler, mConsole, mAccessibilityBridge, mShellSupplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private UiHandler mUiHandler;
|
||||
private AccessibilityBridge mAccessibilityBridge;
|
||||
|
||||
private AbstractShell mRootShell;
|
||||
private Supplier<AbstractShell> mShellSupplier;
|
||||
|
||||
public ScriptRuntime(UiHandler uiHandler, Console console, AccessibilityBridge accessibilityBridge) {
|
||||
super(new AppUtils(uiHandler.getContext()), console, accessibilityBridge);
|
||||
|
||||
protected ScriptRuntime(AppUtils appUtils, UiHandler uiHandler, Console console, AccessibilityBridge accessibilityBridge, Supplier<AbstractShell> shellSupplier) {
|
||||
super(appUtils, console, accessibilityBridge);
|
||||
mAccessibilityBridge = accessibilityBridge;
|
||||
mUiHandler = uiHandler;
|
||||
mShellSupplier = shellSupplier;
|
||||
}
|
||||
|
||||
public UiHandler getUiHandler() {
|
||||
return mUiHandler;
|
||||
}
|
||||
|
||||
public AccessibilityBridge getAccessibilityBridge() {
|
||||
return mAccessibilityBridge;
|
||||
}
|
||||
|
||||
public void toast(final String text) {
|
||||
@@ -62,12 +117,20 @@ public class ScriptRuntime extends AbstractScriptRuntime {
|
||||
}
|
||||
|
||||
public void shellExecAsync(String cmd) {
|
||||
if (mRootShell == null) {
|
||||
mRootShell = new ProcessShell(true);
|
||||
}
|
||||
ensureRootShell();
|
||||
mRootShell.exec(cmd);
|
||||
}
|
||||
|
||||
private void ensureRootShell() {
|
||||
if (mRootShell == null) {
|
||||
if (mShellSupplier == null) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
mRootShell = mShellSupplier.get();
|
||||
mShellSupplier = null;
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractShell.Result shell(String cmd, int root) {
|
||||
return ProcessShell.execCommand(cmd, root != 0);
|
||||
}
|
||||
@@ -98,7 +161,22 @@ public class ScriptRuntime extends AbstractScriptRuntime {
|
||||
Thread.interrupted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetScreenMetrics(int width, int height) {
|
||||
ensureRootShell();
|
||||
mRootShell.SetScreenMetrics(width, height);
|
||||
}
|
||||
|
||||
public void ensureAccessibilityServiceEnabled() {
|
||||
mAccessibilityBridge.ensureServiceEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mRootShell != null) {
|
||||
mRootShell.exit();
|
||||
mRootShell = null;
|
||||
}
|
||||
mShellSupplier = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.stardust.autojs.runtime;
|
||||
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
import com.stardust.autojs.runtime.api.AppUtils;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.util.Supplier;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
public class ScriptRuntimeBuilder {
|
||||
|
||||
}
|
||||
@@ -11,5 +11,5 @@ import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target({ElementType.FIELD})
|
||||
public @interface JavascriptField {
|
||||
public @interface ScriptVariable {
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public abstract class AbstractShell {
|
||||
exec(TextUtils.join("", new Object[]{"sendevent /dev/input/event", device, " ", type, " ", code, " ", value}));
|
||||
}
|
||||
|
||||
public void SetScreenScale(int width, int height){
|
||||
public void SetScreenMetrics(int width, int height){
|
||||
mScreenWidth = width;
|
||||
mScreenHeight = height;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.stardust.autojs.runtime.api;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.stardust.autojs.runtime.JavascriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
import com.stardust.util.IntentUtil;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,13 +20,13 @@ import java.util.List;
|
||||
public class AppUtils {
|
||||
|
||||
private Context mContext;
|
||||
private Activity mCurrentActivity;
|
||||
|
||||
public AppUtils(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean launchPackage(String packageName) {
|
||||
try {
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
@@ -34,12 +38,12 @@ public class AppUtils {
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean launchApp(String appName) {
|
||||
return launchPackage(getPackageName(appName));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public String getPackageName(String appName) {
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
|
||||
@@ -51,10 +55,23 @@ public class AppUtils {
|
||||
return "";
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean openAppSetting(String packageName) {
|
||||
return IntentUtil.goToAppDetailSettings(mContext, packageName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Activity getCurrentActivity() {
|
||||
return mCurrentActivity;
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public void uninstall(String packageName) {
|
||||
mContext.startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + packageName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
public void setCurrentActivity(Activity currentActivity) {
|
||||
mCurrentActivity = currentActivity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.stardust.autojs.runtime.api;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.stardust.autojs.runtime.JavascriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
@@ -10,31 +10,31 @@ import com.stardust.autojs.runtime.JavascriptInterface;
|
||||
|
||||
public interface Console {
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void verbose(@Nullable Object data, Object... options);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void log(@Nullable Object data, Object... options);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void info(@Nullable Object data, Object... options);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void warn(@Nullable Object data, Object... options);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void error(@Nullable Object data, Object... options);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void assertTrue(boolean value, @Nullable Object data, Object... options);
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void clear();
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void show();
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
void hide();
|
||||
|
||||
void println(int level, CharSequence charSequence);
|
||||
|
||||
@@ -4,15 +4,15 @@ import android.content.Context;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.stardust.autojs.runtime.JavascriptClass;
|
||||
import com.stardust.autojs.runtime.JavascriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptClass;
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/1.
|
||||
*/
|
||||
@JavascriptClass
|
||||
@ScriptClass
|
||||
public class InjectableWebView extends WebView {
|
||||
|
||||
private InjectableWebClient mInjectableWebClient;
|
||||
@@ -27,12 +27,12 @@ public class InjectableWebView extends WebView {
|
||||
setWebViewClient(mInjectableWebClient);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public void inject(String script, ValueCallback<String> callback) {
|
||||
mInjectableWebClient.inject(script, callback);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public void inject(String script) {
|
||||
mInjectableWebClient.inject(script);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.autojs.runtime.AccessibilityBridge;
|
||||
import com.stardust.autojs.runtime.JavascriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.automator.AccessibilityEventCommandHost;
|
||||
import com.stardust.automator.ActionArgument;
|
||||
@@ -85,7 +85,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
mAllocator = allocator;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public UiObjectCollection find() {
|
||||
ensureAccessibilityServiceEnabled();
|
||||
if (AutomatorConfig.isUnintendedGuardEnabled() && isRunningPackageSelf()) {
|
||||
@@ -111,7 +111,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
}
|
||||
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
@NonNull
|
||||
public UiObjectCollection untilFind() {
|
||||
UiObjectCollection uiObjectCollection;
|
||||
@@ -125,7 +125,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
return uiObjectCollection;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public UiObject findOne() {
|
||||
return untilFindOne();
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
return new UiObject(collection.get(0).getInfo());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public UiSelector id(final String id) {
|
||||
if (!id.contains(":")) {
|
||||
addFilter(new DfsFilter() {
|
||||
@@ -157,131 +157,131 @@ public class UiSelector extends UiGlobalSelector {
|
||||
return untilFind().performAction(action, arguments);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean click() {
|
||||
return performAction(ACTION_CLICK);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean longClick() {
|
||||
return performAction(ACTION_LONG_CLICK);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean accessibilityFocus() {
|
||||
return performAction(ACTION_ACCESSIBILITY_FOCUS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean clearAccessibilityFocus() {
|
||||
return performAction(ACTION_CLEAR_ACCESSIBILITY_FOCUS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean focus() {
|
||||
return performAction(ACTION_FOCUS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean clearFocus() {
|
||||
return performAction(ACTION_CLEAR_FOCUS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean copy() {
|
||||
return performAction(ACTION_COPY);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean paste() {
|
||||
return performAction(ACTION_PASTE);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean select() {
|
||||
return performAction(ACTION_SELECT);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean cut() {
|
||||
return performAction(ACTION_CUT);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean collapse() {
|
||||
return performAction(ACTION_COLLAPSE);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean expand() {
|
||||
return performAction(ACTION_EXPAND);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean dismiss() {
|
||||
return performAction(ACTION_DISMISS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean show() {
|
||||
return performAction(ACTION_SHOW_ON_SCREEN.getId());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollForward() {
|
||||
return performAction(ACTION_SCROLL_FORWARD);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollBackward() {
|
||||
return performAction(ACTION_SCROLL_BACKWARD);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollUp() {
|
||||
return performAction(ACTION_SCROLL_UP.getId());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollDown() {
|
||||
return performAction(ACTION_SCROLL_DOWN.getId());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollLeft() {
|
||||
return performAction(ACTION_SCROLL_LEFT.getId());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollRight() {
|
||||
return performAction(ACTION_SCROLL_RIGHT.getId());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean contextClick() {
|
||||
return performAction(ACTION_CONTEXT_CLICK.getId());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean setSelection(int s, int e) {
|
||||
return performAction(ACTION_SET_SELECTION,
|
||||
new ActionArgument.IntActionArgument(ACTION_ARGUMENT_SELECTION_START_INT, s),
|
||||
new ActionArgument.IntActionArgument(ACTION_ARGUMENT_SELECTION_END_INT, e));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean setText(String text) {
|
||||
return performAction(ACTION_SET_TEXT,
|
||||
new ActionArgument.CharSequenceActionArgument(ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean setProgress(float value) {
|
||||
return performAction(ACTION_SET_PROGRESS.getId(),
|
||||
new ActionArgument.FloatActionArgument(ACTION_ARGUMENT_PROGRESS_VALUE, value));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollTo(int row, int column) {
|
||||
return performAction(ACTION_SCROLL_TO_POSITION.getId(),
|
||||
new ActionArgument.IntActionArgument(ACTION_ARGUMENT_ROW_INT, row),
|
||||
|
||||
@@ -10,8 +10,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.autojs.runtime.AbstractScriptRuntime;
|
||||
import com.stardust.autojs.runtime.AccessibilityBridge;
|
||||
import com.stardust.autojs.runtime.JavascriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
import com.stardust.autojs.runtime.api.AutomatorConfig;
|
||||
import com.stardust.automator.AccessibilityEventCommandHost;
|
||||
import com.stardust.automator.UiObject;
|
||||
@@ -53,74 +52,74 @@ public class SimpleActionAutomator {
|
||||
mScriptRuntime = scriptRuntime;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public ActionTarget text(String text, int i) {
|
||||
return new ActionTarget.TextActionTarget(text, i);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public ActionTarget bounds(int left, int top, int right, int bottom) {
|
||||
return new ActionTarget.BoundsActionTarget(new Rect(left, top, right, bottom));
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public ActionTarget editable(int i) {
|
||||
mScriptRuntime.requiresApi(Build.VERSION_CODES.LOLLIPOP);
|
||||
return new ActionTarget.EditableActionTarget(i);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public ActionTarget id(String id) {
|
||||
return new ActionTarget.IdActionTarget(id);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean click(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_CLICK));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean longClick(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_LONG_CLICK));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollUp(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollDown(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollBackward(int i) {
|
||||
return performAction(ActionFactory.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, i));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollForward(int i) {
|
||||
return performAction(ActionFactory.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, i));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollMaxBackward() {
|
||||
return performAction(ActionFactory.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean scrollMaxForward() {
|
||||
return performAction(ActionFactory.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean focus(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_FOCUS));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean select(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SELECT));
|
||||
}
|
||||
@@ -131,39 +130,39 @@ public class SimpleActionAutomator {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SET_TEXT, text));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean back() {
|
||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean home() {
|
||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean powerDialog() {
|
||||
mScriptRuntime.requiresApi(Build.VERSION_CODES.LOLLIPOP);
|
||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean notifications() {
|
||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean quickSettings() {
|
||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean recents() {
|
||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public boolean splitScreen() {
|
||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
|
||||
@@ -177,7 +176,7 @@ public class SimpleActionAutomator {
|
||||
return service.performGlobalAction(action);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
@ScriptInterface
|
||||
public boolean paste(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_PASTE));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user