api: threads, files
This commit is contained in:
1
app/src/main/assets/sample/多线程/原子变量.js
Normal file
1
app/src/main/assets/sample/多线程/原子变量.js
Normal file
@@ -0,0 +1 @@
|
||||
var i = threads.atomic();
|
||||
11
app/src/main/assets/sample/多线程/变量可见性实验.js
Normal file
11
app/src/main/assets/sample/多线程/变量可见性实验.js
Normal file
@@ -0,0 +1,11 @@
|
||||
var running = true;
|
||||
|
||||
threads.start(function(){
|
||||
while(running){
|
||||
log("running = true");
|
||||
}
|
||||
});
|
||||
|
||||
sleep(2000);
|
||||
running = false;
|
||||
console.info("running = false");
|
||||
26
app/src/main/assets/sample/多线程/多线程简单示例.js
Normal file
26
app/src/main/assets/sample/多线程/多线程简单示例.js
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
//启动一个线程
|
||||
threads.start(function(){
|
||||
//在线程中每隔1秒打印"线程1"
|
||||
while(true){
|
||||
log("线程1");
|
||||
sleep(1000);
|
||||
}
|
||||
});
|
||||
|
||||
//启动另一个线程
|
||||
threads.start(function(){
|
||||
//在线程中每隔2秒打印"线程1"
|
||||
while(true){
|
||||
log("线程2");
|
||||
sleep(2000);
|
||||
}
|
||||
});
|
||||
|
||||
//在主线程中每隔3秒打印"主线程"
|
||||
for(var i = 0; i < 10; i++){
|
||||
log("主线程");
|
||||
sleep(3000);
|
||||
}
|
||||
//打印100次后退出所有线程
|
||||
threads.shutDownAll();
|
||||
14
app/src/main/assets/sample/多线程/线程启动与关闭.js
Normal file
14
app/src/main/assets/sample/多线程/线程启动与关闭.js
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
//启动一个无限循环的线程
|
||||
var thread = threads.start(function(){
|
||||
while(true){
|
||||
log("子线程运行中...");
|
||||
sleep(1000);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//5秒后关闭线程
|
||||
sleep(5000);
|
||||
thread.interrupt();
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.accessibility.AccessibilityService;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.autojs.record.GlobalActionRecorder;
|
||||
import com.stardust.scriptdroid.model.script.Scripts;
|
||||
import com.stardust.scriptdroid.storage.file.StorageFileProvider;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.ui.common.NotAskAgainDialog;
|
||||
@@ -132,6 +133,7 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
|
||||
.positiveText(R.string.cancel)
|
||||
.build();
|
||||
listView.setOnItemOperatedListener(file -> dialog.dismiss());
|
||||
listView.setOnScriptFileClickListener((view, file) -> Scripts.run(file));
|
||||
DialogUtils.showDialog(dialog);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.androidannotations.annotations.ViewById;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
@EActivity(R.layout.activity_main)
|
||||
|
||||
Reference in New Issue
Block a user