fix hyb1996-guest/AutoJsIssueReport#1341 and replace JavaAdapter to ProxyObject in ui module to avoid compilation to class file
This commit is contained in:
@@ -45,7 +45,7 @@ module.exports = function(__runtime__, scope){
|
||||
function toStrokes(args){
|
||||
var screenMetrics = __runtime__.getScreenMetrics();
|
||||
var len = args.length;
|
||||
var strokes = [];
|
||||
var strokes = java.lang.reflect.Array.newInstance(android.accessibilityservice.GestureDescription.StrokeDescription, len);
|
||||
for(var i = 0; i < len; i++){
|
||||
var gesture = args[i];
|
||||
var pointsIndex = 1;
|
||||
@@ -63,7 +63,7 @@ module.exports = function(__runtime__, scope){
|
||||
for(var j = pointsIndex + 1; j < gestureLen; j++){
|
||||
path.lineTo(screenMetrics.scaleX(gesture[j][0]), screenMetrics.scaleY(gesture[j][1]));
|
||||
}
|
||||
strokes.push(new android.accessibilityservice.GestureDescription.StrokeDescription(path, start, delay));
|
||||
strokes[i] = new android.accessibilityservice.GestureDescription.StrokeDescription(path, start, delay);
|
||||
}
|
||||
return strokes;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
module.exports = function(__runtime__, scope){
|
||||
var ui = Object.create(__runtime__.ui);
|
||||
ui.__id_cache__ = {};
|
||||
var ui = {};
|
||||
ui.__view_cache__ = {};
|
||||
|
||||
ui.layout = function(xml){
|
||||
view = ui.inflate(activity, xml.toString());
|
||||
var view = __runtime__.ui.layoutInflater.inflate(activity, xml.toString());
|
||||
ui.setContentView(view);
|
||||
}
|
||||
|
||||
ui.setContentView = function(view){
|
||||
ui.view = view;
|
||||
ui.__id_cache__ = {};
|
||||
ui.__view_cache__ = {};
|
||||
activity.setContentView(view);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,10 @@ module.exports = function(__runtime__, scope){
|
||||
}
|
||||
|
||||
ui.nonUi = function(action){
|
||||
ui.runOnNonUiThread(action);
|
||||
if(!ui.__executor__){
|
||||
ui.__executor__ = java.util.concurrent.Executors.newSingleThreadExecutor();
|
||||
}
|
||||
ui.__executor__.submit(action);
|
||||
}
|
||||
|
||||
ui.postDelay = function(action, delay){
|
||||
@@ -39,7 +42,7 @@ module.exports = function(__runtime__, scope){
|
||||
if(typeof(color) == 'string'){
|
||||
color = android.graphics.Color.parseColor(color);
|
||||
}
|
||||
if(Build.VERSION.SDK_INT >= 21){
|
||||
if(android.os.Build.VERSION.SDK_INT >= 21){
|
||||
activity.getWindow().setStatusBarColor(color);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +51,10 @@ module.exports = function(__runtime__, scope){
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
ui.findViewByStringId = function(view, id){
|
||||
return com.stardust.autojs.runtime.api.ui.JsViewHelper.findViewByStringId(view, id);
|
||||
}
|
||||
|
||||
function decorate(view){
|
||||
var view = Object.create(view);
|
||||
view._id = function(id){
|
||||
@@ -70,23 +77,25 @@ module.exports = function(__runtime__, scope){
|
||||
return view;
|
||||
}
|
||||
|
||||
return new JavaAdapter(org.mozilla.javascript.NativeObject, {
|
||||
put: function(name, start, value) {
|
||||
ui[name] = value;
|
||||
},
|
||||
get: function(name, start) {
|
||||
if(!ui[name] && ui.view){
|
||||
var cacheView = ui.__id_cache__[name];
|
||||
if(cacheView){
|
||||
return cacheView;
|
||||
}
|
||||
cacheView = ui.id(name);
|
||||
if(cacheView){
|
||||
ui.__id_cache__[name] = cacheView;
|
||||
return cacheView;
|
||||
}
|
||||
}
|
||||
return ui[name];
|
||||
}
|
||||
});
|
||||
var proxy = __runtime__.ui;
|
||||
proxy.__proxy__ = {
|
||||
set: function(name, value){
|
||||
ui[name] = value;
|
||||
},
|
||||
get: function(name) {
|
||||
if(!ui[name] && ui.view){
|
||||
var cacheView = ui.__view_cache__[name];
|
||||
if(cacheView){
|
||||
return cacheView;
|
||||
}
|
||||
cacheView = ui.id(name);
|
||||
if(cacheView){
|
||||
ui.__view_cache__[name] = cacheView;
|
||||
return cacheView;
|
||||
}
|
||||
}
|
||||
return ui[name];
|
||||
}
|
||||
};
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@@ -2,18 +2,14 @@ package com.stardust.autojs.engine;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.autojs.engine.preprocess.MultiLinePreprocessor;
|
||||
import com.stardust.autojs.engine.preprocess.Preprocessor;
|
||||
import com.stardust.autojs.rhino_android.AndroidContextFactory;
|
||||
import com.stardust.autojs.rhino_android.RhinoAndroidHelper;
|
||||
import com.stardust.autojs.rhino.AndroidContextFactory;
|
||||
import com.stardust.autojs.rhino.RhinoAndroidHelper;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.ErrorReporter;
|
||||
import org.mozilla.javascript.EvaluatorException;
|
||||
import org.mozilla.javascript.ImporterTopLevel;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.autojs.rhino_android;
|
||||
package com.stardust.autojs.rhino;
|
||||
|
||||
import com.android.dx.command.dexer.Main;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.stardust.autojs.rhino_android;
|
||||
package com.stardust.autojs.rhino;
|
||||
|
||||
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.tools.shell.ShellContextFactory;
|
||||
import org.mozilla.javascript.xml.XMLLib;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.autojs.rhino_android;
|
||||
package com.stardust.autojs.rhino;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.GeneratedClassLoader;
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.stardust.autojs.rhino;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.NativeFunction;
|
||||
import org.mozilla.javascript.NativeObject;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.UniqueTag;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/17.
|
||||
*/
|
||||
|
||||
public class ProxyObject extends NativeObject {
|
||||
|
||||
private NativeFunction mGetter;
|
||||
private NativeFunction mSetter;
|
||||
|
||||
@Override
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
if (name.equals("__proxy__")) {
|
||||
NativeObject proxy = (NativeObject) value;
|
||||
Object getter = proxy.get("get", start);
|
||||
if (getter instanceof NativeFunction) {
|
||||
mGetter = (NativeFunction) getter;
|
||||
}
|
||||
Object setter = proxy.get("set", start);
|
||||
if (setter instanceof NativeFunction) {
|
||||
mSetter = (NativeFunction) setter;
|
||||
}
|
||||
} else if (mSetter != null) {
|
||||
mSetter.call(Context.getCurrentContext(), start, start, new Object[]{name, value});
|
||||
} else {
|
||||
super.put(name, start, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getWithoutProxy(String name, Scriptable start) {
|
||||
return super.get(name, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String name, Scriptable start) {
|
||||
Object value = super.get(name, start);
|
||||
if (value != null && value != UniqueTag.NOT_FOUND) {
|
||||
return value;
|
||||
}
|
||||
if (mGetter != null) {
|
||||
value = mGetter.call(Context.getCurrentContext(), start, start, new Object[]{name});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue(Class<?> typeHint) {
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.autojs.rhino_android;
|
||||
package com.stardust.autojs.rhino;
|
||||
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.stardust.autojs.runtime;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
import com.stardust.autojs.runtime.api.AppUtils;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.autojs.runtime.api.UiSelector;
|
||||
import com.stardust.autojs.runtime.api.ui.UI;
|
||||
import com.stardust.autojs.runtime.simple_action.SimpleActionAutomator;
|
||||
import com.stardust.autojs.runtime.simpleaction.SimpleActionAutomator;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
import com.stardust.view.accessibility.AccessibilityInfoProvider;
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ import android.os.Looper;
|
||||
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.engine.preprocess.Preprocessor;
|
||||
import com.stardust.autojs.rhino_android.AndroidClassLoader;
|
||||
import com.stardust.autojs.rhino.AndroidClassLoader;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
import com.stardust.autojs.runtime.api.AppUtils;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
|
||||
@@ -1,49 +1,52 @@
|
||||
package com.stardust.autojs.runtime.api.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import com.stardust.autojs.rhino.ProxyObject;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.UniqueTag;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/14.
|
||||
*/
|
||||
|
||||
public class UI {
|
||||
public class UI extends ProxyObject {
|
||||
|
||||
|
||||
private Context mContext;
|
||||
private JsLayoutInflater mJsLayoutInflater;
|
||||
private ExecutorService mExecutorService;
|
||||
private Map<String, Object> mProperties = new ConcurrentHashMap<>();
|
||||
|
||||
public UI(Context context, JsLayoutInflater layoutInflater) {
|
||||
mContext = context;
|
||||
mJsLayoutInflater = layoutInflater;
|
||||
mProperties.put("layoutInflater", layoutInflater);
|
||||
}
|
||||
|
||||
|
||||
public UI(Context context) {
|
||||
this(context, new ConvertLayoutInflater());
|
||||
}
|
||||
|
||||
public JsLayoutInflater getLayoutInflater() {
|
||||
return mJsLayoutInflater;
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return UI.class.getSimpleName();
|
||||
}
|
||||
|
||||
public View inflate(Context context, String xml) {
|
||||
return mJsLayoutInflater.inflate(context, xml);
|
||||
}
|
||||
|
||||
public void runOnNonUiThread(Runnable action) {
|
||||
if (mExecutorService == null) {
|
||||
mExecutorService = Executors.newSingleThreadExecutor();
|
||||
@Override
|
||||
public Object get(String name, Scriptable start) {
|
||||
Object value = super.get(name, start);
|
||||
if (value != null && value != UniqueTag.NOT_FOUND && !value.equals(org.mozilla.javascript.Context.getUndefinedValue())) {
|
||||
return value;
|
||||
}
|
||||
mExecutorService.submit(action);
|
||||
value = mProperties.get(name);
|
||||
if (value != null)
|
||||
return value;
|
||||
return UniqueTag.NOT_FOUND;
|
||||
}
|
||||
|
||||
public View findViewByStringId(View view, String id) {
|
||||
return JsViewHelper.findViewByStringId(view, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,22 @@
|
||||
package com.stardust.autojs.runtime.simple_action;
|
||||
package com.stardust.autojs.runtime.simpleaction;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.accessibilityservice.GestureDescription;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.autojs.runtime.AbstractScriptRuntime;
|
||||
import com.stardust.autojs.runtime.AccessibilityBridge;
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
import com.stardust.autojs.runtime.api.AutomatorConfig;
|
||||
import com.stardust.automator.AccessibilityEventCommandHost;
|
||||
import com.stardust.automator.GlobalActionAutomator;
|
||||
import com.stardust.automator.UiObject;
|
||||
import com.stardust.automator.simple_action.SimpleAction;
|
||||
import com.stardust.automator.simple_action.ActionFactory;
|
||||
import com.stardust.automator.simple_action.ActionTarget;
|
||||
import com.stardust.automator.simple_action.SimpleAction;
|
||||
import com.stardust.util.DeveloperUtils;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
|
||||
@@ -173,21 +167,22 @@ public class SimpleActionAutomator {
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public boolean gestures(GestureDescription.StrokeDescription... strokes) {
|
||||
public boolean gestures(Object strokes) {
|
||||
prepareForGesture();
|
||||
return mGlobalActionAutomator.gestures(strokes);
|
||||
return mGlobalActionAutomator.gestures((GestureDescription.StrokeDescription[]) strokes);
|
||||
}
|
||||
|
||||
//如果这里用GestureDescription.StrokeDescription[]为参数,安卓7.0以下会因为找不到这个类而报错
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public void gesturesAsync(GestureDescription.StrokeDescription... strokes) {
|
||||
public void gesturesAsync(Object strokes) {
|
||||
prepareForGesture();
|
||||
mGlobalActionAutomator.gesturesAsync(strokes);
|
||||
mGlobalActionAutomator.gesturesAsync((GestureDescription.StrokeDescription[]) strokes);
|
||||
}
|
||||
|
||||
private void prepareForGesture() {
|
||||
ensureAccessibilityServiceEnabled();
|
||||
mScriptRuntime.requiresApi(24);
|
||||
mGlobalActionAutomator.setService(mAccessibilityBridge.getService());
|
||||
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
@@ -3,7 +3,6 @@ package com.stardust.autojs.script;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.autojs.rhino_android.RhinoAndroidHelper;
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user