chore
This commit is contained in:
@@ -8,8 +8,8 @@ android {
|
|||||||
applicationId "com.stardust.scriptdroid"
|
applicationId "com.stardust.scriptdroid"
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 249
|
versionCode 250
|
||||||
versionName "3.0.0 Beta3"
|
versionName "3.0.0 Alpha50"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":246},"path":"release-3.0.0 Beta.apk","properties":{"packageId":"com.stardust.scriptdroid","split":"","minSdkVersion":"17"}}]
|
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":34},"path":"inrt-release.apk","properties":{"packageId":"com.stardust.auojs.inrt","split":"","minSdkVersion":"17"}}]
|
||||||
Binary file not shown.
@@ -24,12 +24,18 @@ module.exports = function(__runtime__, scope){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i.action) {
|
if (i.action) {
|
||||||
|
if(i.action.indexOf(".") == -1){
|
||||||
|
i.action = "android.intent.action." + i.action;
|
||||||
|
}
|
||||||
intent.setAction(i.action);
|
intent.setAction(i.action);
|
||||||
}
|
}
|
||||||
if (i.type) {
|
if (i.type) {
|
||||||
intent.setType(i.type);
|
if(i.data){
|
||||||
}
|
intent.setDataAndType(android.net.Uri.parse(i.data), i.type);
|
||||||
if (i.data) {
|
}else{
|
||||||
|
intent.setType(i.type);
|
||||||
|
}
|
||||||
|
}else if (i.data) {
|
||||||
intent.setData(android.net.Uri.parse(i.data));
|
intent.setData(android.net.Uri.parse(i.data));
|
||||||
}
|
}
|
||||||
return intent;
|
return intent;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import com.stardust.autojs.runtime.api.Timers;
|
|||||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||||
import com.stardust.lang.ThreadCompat;
|
import com.stardust.lang.ThreadCompat;
|
||||||
|
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/7/29.
|
* Created by Stardust on 2017/7/29.
|
||||||
*/
|
*/
|
||||||
@@ -24,6 +26,7 @@ public class Loopers implements MessageQueue.IdleHandler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private volatile ThreadLocal<Boolean> waitWhenIdle = new ThreadLocal<>();
|
private volatile ThreadLocal<Boolean> waitWhenIdle = new ThreadLocal<>();
|
||||||
|
private volatile ThreadLocal<CopyOnWriteArrayList<LooperQuitHandler>> looperQuitHanders = new ThreadLocal<>();
|
||||||
private volatile Looper mServantLooper;
|
private volatile Looper mServantLooper;
|
||||||
private Timers mTimers;
|
private Timers mTimers;
|
||||||
private ScriptRuntime mScriptRuntime;
|
private ScriptRuntime mScriptRuntime;
|
||||||
@@ -48,6 +51,20 @@ public class Loopers implements MessageQueue.IdleHandler {
|
|||||||
return mMainLooper;
|
return mMainLooper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addLooperQuiteHandler(LooperQuitHandler handler) {
|
||||||
|
CopyOnWriteArrayList<LooperQuitHandler> handlers = looperQuitHanders.get();
|
||||||
|
if (handlers == null) {
|
||||||
|
handlers = new CopyOnWriteArrayList<>();
|
||||||
|
looperQuitHanders.set(handlers);
|
||||||
|
}
|
||||||
|
handlers.add(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeLooperQuiteHandler(LooperQuitHandler handler) {
|
||||||
|
CopyOnWriteArrayList<LooperQuitHandler> handlers = looperQuitHanders.get();
|
||||||
|
return handlers != null && handlers.remove(handler);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldQuitLooper() {
|
private boolean shouldQuitLooper() {
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
if (Thread.currentThread().isInterrupted()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -55,7 +72,19 @@ public class Loopers implements MessageQueue.IdleHandler {
|
|||||||
if (mTimers.hasPendingCallbacks()) {
|
if (mTimers.hasPendingCallbacks()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !waitWhenIdle.get();
|
if (waitWhenIdle.get()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CopyOnWriteArrayList<LooperQuitHandler> handlers = looperQuitHanders.get();
|
||||||
|
if (handlers == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (LooperQuitHandler handler : handlers) {
|
||||||
|
if (!handler.shouldQuit()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ public class ScriptRuntime {
|
|||||||
public final Files files;
|
public final Files files;
|
||||||
|
|
||||||
@ScriptVariable
|
@ScriptVariable
|
||||||
public final Sensors sensors;
|
public Sensors sensors;
|
||||||
|
|
||||||
|
|
||||||
private Images images;
|
private Images images;
|
||||||
@@ -205,7 +205,6 @@ public class ScriptRuntime {
|
|||||||
device = new Device(context);
|
device = new Device(context);
|
||||||
floaty = new Floaty(uiHandler, ui, this);
|
floaty = new Floaty(uiHandler, ui, this);
|
||||||
files = new Files(this);
|
files = new Files(this);
|
||||||
sensors = new Sensors(context, bridges);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -216,6 +215,7 @@ public class ScriptRuntime {
|
|||||||
loopers = new Loopers(this);
|
loopers = new Loopers(this);
|
||||||
events = new Events(uiHandler.getContext(), accessibilityBridge, this);
|
events = new Events(uiHandler.getContext(), accessibilityBridge, this);
|
||||||
mThread = Thread.currentThread();
|
mThread = Thread.currentThread();
|
||||||
|
sensors = new Sensors(uiHandler.getContext(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setApplicationContext(Context context) {
|
public static void setApplicationContext(Context context) {
|
||||||
|
|||||||
@@ -1,19 +1,12 @@
|
|||||||
package com.stardust.autojs.runtime.api;
|
package com.stardust.autojs.runtime.api;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.AssetManager;
|
|
||||||
|
|
||||||
import com.stardust.autojs.engine.ScriptEngine;
|
import com.stardust.autojs.engine.ScriptEngine;
|
||||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||||
import com.stardust.autojs.script.JavaScriptSource;
|
|
||||||
import com.stardust.pio.PFileInterface;
|
import com.stardust.pio.PFileInterface;
|
||||||
import com.stardust.pio.PFiles;
|
import com.stardust.pio.PFiles;
|
||||||
import com.stardust.util.Func1;
|
import com.stardust.util.Func1;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2018/1/23.
|
* Created by Stardust on 2018/1/23.
|
||||||
@@ -93,6 +86,10 @@ public class Files {
|
|||||||
return PFiles.read(path(path));
|
return PFiles.read(path(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] readBytes(String path){
|
||||||
|
return PFiles.readBytes(path(path));
|
||||||
|
}
|
||||||
|
|
||||||
public void write(String path, String text) {
|
public void write(String path, String text) {
|
||||||
PFiles.write(path(path), text);
|
PFiles.write(path(path), text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import android.hardware.SensorManager;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.stardust.autojs.core.eventloop.EventEmitter;
|
import com.stardust.autojs.core.eventloop.EventEmitter;
|
||||||
|
import com.stardust.autojs.core.looper.Loopers;
|
||||||
import com.stardust.autojs.runtime.ScriptBridges;
|
import com.stardust.autojs.runtime.ScriptBridges;
|
||||||
|
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||||
import com.stardust.util.MapEntries;
|
import com.stardust.util.MapEntries;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -20,7 +23,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
* Created by Stardust on 2018/2/5.
|
* Created by Stardust on 2018/2/5.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Sensors extends EventEmitter {
|
public class Sensors extends EventEmitter implements Loopers.LooperQuitHandler {
|
||||||
|
|
||||||
|
|
||||||
public class SensorEventEmitter extends EventEmitter implements SensorEventListener {
|
public class SensorEventEmitter extends EventEmitter implements SensorEventListener {
|
||||||
|
|
||||||
@@ -79,13 +83,16 @@ public class Sensors extends EventEmitter {
|
|||||||
private final SensorManager mSensorManager;
|
private final SensorManager mSensorManager;
|
||||||
private final ScriptBridges mScriptBridges;
|
private final ScriptBridges mScriptBridges;
|
||||||
private final SensorEventEmitter mNoOpSensorEventEmitter;
|
private final SensorEventEmitter mNoOpSensorEventEmitter;
|
||||||
|
private final ScriptRuntime mScriptRuntime;
|
||||||
|
|
||||||
|
|
||||||
public Sensors(Context context, ScriptBridges bridges) {
|
public Sensors(Context context, ScriptRuntime runtime) {
|
||||||
super(bridges);
|
super(runtime.bridges);
|
||||||
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||||
mScriptBridges = bridges;
|
mScriptBridges = runtime.bridges;
|
||||||
mNoOpSensorEventEmitter = new SensorEventEmitter(bridges);
|
mNoOpSensorEventEmitter = new SensorEventEmitter(runtime.bridges);
|
||||||
|
mScriptRuntime = runtime;
|
||||||
|
runtime.loopers.addLooperQuiteHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SensorEventEmitter register(String sensorName) {
|
public SensorEventEmitter register(String sensorName) {
|
||||||
@@ -107,23 +114,6 @@ public class Sensors extends EventEmitter {
|
|||||||
return register(sensor, delay);
|
return register(sensor, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SensorEventEmitter registerByType(int sensorType, int delay) {
|
|
||||||
Sensor sensor = mSensorManager.getDefaultSensor(sensorType);
|
|
||||||
if (sensor == null) {
|
|
||||||
if (ignoresUnsupportedSensor) {
|
|
||||||
emit("unsupported_sensor", null, sensorType);
|
|
||||||
return mNoOpSensorEventEmitter;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return register(sensor, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SensorEventEmitter registerByType(int sensorType) {
|
|
||||||
return registerByType(sensorType, delay.normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SensorEventEmitter register(@NonNull Sensor sensor, int delay) {
|
private SensorEventEmitter register(@NonNull Sensor sensor, int delay) {
|
||||||
SensorEventEmitter emitter = new SensorEventEmitter(mScriptBridges);
|
SensorEventEmitter emitter = new SensorEventEmitter(mScriptBridges);
|
||||||
mSensorManager.registerListener(emitter, sensor, delay);
|
mSensorManager.registerListener(emitter, sensor, delay);
|
||||||
@@ -134,13 +124,33 @@ public class Sensors extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Sensor getSensor(String sensorName) {
|
@Override
|
||||||
|
public boolean shouldQuit() {
|
||||||
|
if (mSensorEventEmitters.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sensor getSensor(String sensorName) {
|
||||||
Integer type = SENSORS.get(sensorName.toUpperCase());
|
Integer type = SENSORS.get(sensorName.toUpperCase());
|
||||||
|
if (type == null)
|
||||||
|
type = getSensorTypeByReflect(sensorName);
|
||||||
if (type == null)
|
if (type == null)
|
||||||
return null;
|
return null;
|
||||||
return mSensorManager.getDefaultSensor(type);
|
return mSensorManager.getDefaultSensor(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer getSensorTypeByReflect(String sensorName) {
|
||||||
|
sensorName = sensorName.toUpperCase();
|
||||||
|
try {
|
||||||
|
Field field = Sensor.class.getField("TYPE_" + sensorName);
|
||||||
|
return (Integer) field.get(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void unregister(SensorEventEmitter emitter) {
|
public void unregister(SensorEventEmitter emitter) {
|
||||||
if (emitter == null)
|
if (emitter == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -460,4 +460,11 @@ public class PFiles {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] readBytes(String path) {
|
||||||
|
try {
|
||||||
|
return readBytes(new FileInputStream(path));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user