api: threads, events
This commit is contained in:
23
app/src/main/assets/sample/多线程/多线程按键监听.js
Normal file
23
app/src/main/assets/sample/多线程/多线程按键监听.js
Normal file
@@ -0,0 +1,23 @@
|
||||
auto();
|
||||
|
||||
threads.start(function(){
|
||||
//在子线程中调用observeKey()从而使按键事件处理在子线程执行
|
||||
events.observeKey();
|
||||
events.on("key_down", function(keyCode, events){
|
||||
//音量键关闭脚本
|
||||
if(keyCode == keys.volume_up){
|
||||
exit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
toast("音量上键关闭脚本");
|
||||
|
||||
events.on("exit", function(){
|
||||
toast("脚本已结束");
|
||||
});
|
||||
|
||||
while(true){
|
||||
log("脚本运行中...");
|
||||
sleep(2000);
|
||||
}
|
||||
@@ -88,6 +88,13 @@ public class EditActivity extends BaseActivity implements OnActivityResultDelega
|
||||
super.onActionModeStarted(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (!mEditor.onBackPressed()) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
if (mEditor.isTextChanged()) {
|
||||
|
||||
@@ -91,7 +91,7 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
||||
FunctionsKeyboardView mFunctionsKeyboard;
|
||||
|
||||
@ViewById(R.id.docs)
|
||||
EWebView mEWebView;
|
||||
EWebView mDocsWebView;
|
||||
|
||||
@ViewById(R.id.drawer_layout)
|
||||
DrawerLayout mDrawerLayout;
|
||||
@@ -201,8 +201,8 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
||||
setUpInputMethodEnhancedBar();
|
||||
setUpFunctionsKeyboard();
|
||||
setMenuItemStatus(R.id.save, false);
|
||||
mEWebView.getWebView().getSettings().setDisplayZoomControls(true);
|
||||
mEWebView.getWebView().loadUrl(Pref.getDocumentationUrl() + "index.html");
|
||||
mDocsWebView.getWebView().getSettings().setDisplayZoomControls(true);
|
||||
mDocsWebView.getWebView().loadUrl(Pref.getDocumentationUrl() + "index.html");
|
||||
|
||||
}
|
||||
|
||||
@@ -257,6 +257,18 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
||||
mShowFunctionsButton.setColorFilter(textColor);
|
||||
}
|
||||
|
||||
public boolean onBackPressed() {
|
||||
if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
|
||||
if (mDocsWebView.getWebView().canGoBack()) {
|
||||
mDocsWebView.getWebView().goBack();
|
||||
} else {
|
||||
mDrawerLayout.closeDrawer(Gravity.START);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Click(R.id.run)
|
||||
public void runAndSaveFileIfNeeded() {
|
||||
@@ -414,7 +426,7 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
||||
.title(title)
|
||||
.url(absUrl)
|
||||
.pinToLeft(v -> {
|
||||
mEWebView.getWebView().loadUrl(absUrl);
|
||||
mDocsWebView.getWebView().loadUrl(absUrl);
|
||||
mDrawerLayout.openDrawer(Gravity.START);
|
||||
})
|
||||
.show();
|
||||
|
||||
Reference in New Issue
Block a user