add script running repleatedly support, change min sdk version to 17
This commit is contained in:
@@ -5,7 +5,7 @@ android {
|
||||
buildToolsVersion "25.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -9,6 +9,9 @@ public class ExecutionConfig implements Serializable {
|
||||
|
||||
private String[] mRequirePath = new String[0];
|
||||
private static final ExecutionConfig DEFAULT = new ExecutionConfig();
|
||||
public long delay = 0;
|
||||
public long interval = 0;
|
||||
public int loopTimes = 1;
|
||||
|
||||
public static ExecutionConfig getDefault() {
|
||||
return DEFAULT;
|
||||
@@ -29,4 +32,11 @@ public class ExecutionConfig implements Serializable {
|
||||
public String[] getRequirePath() {
|
||||
return mRequirePath;
|
||||
}
|
||||
|
||||
public ExecutionConfig loop(long delay, int loopTimes, long interval) {
|
||||
this.delay = delay;
|
||||
this.loopTimes = loopTimes;
|
||||
this.interval = interval;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.util.Log;
|
||||
import com.stardust.autojs.ScriptEngineService;
|
||||
import com.stardust.autojs.engine.RhinoJavaScriptEngine;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
|
||||
@@ -61,11 +62,34 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
private Object doExecution(ScriptEngine engine) {
|
||||
engine.setTag("script", getSource());
|
||||
getListener().onStart(this);
|
||||
Object result = engine.execute(getSource());
|
||||
Object result = null;
|
||||
long delay = getConfig().delay;
|
||||
int times = getConfig().loopTimes;
|
||||
if (times == 0) {
|
||||
times = Integer.MAX_VALUE;
|
||||
}
|
||||
long interval = getConfig().interval;
|
||||
sleep(delay);
|
||||
ScriptSource source = getSource();
|
||||
for (int i = 0; i < times; i++) {
|
||||
result = engine.execute(source);
|
||||
sleep(interval);
|
||||
}
|
||||
getListener().onSuccess(this, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sleep(long i) {
|
||||
if (i <= 0) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(i);
|
||||
} catch (InterruptedException e) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptEngine getEngine() {
|
||||
return mScriptEngine;
|
||||
|
||||
Reference in New Issue
Block a user