add console.rawInput, app.intent
This commit is contained in:
@@ -107,7 +107,7 @@ dependencies {
|
|||||||
compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
|
compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
|
||||||
compile group: 'com.twofortyfouram', name: 'android-plugin-client-sdk-for-locale', version: '[4.0.2, 5.0['
|
compile group: 'com.twofortyfouram', name: 'android-plugin-client-sdk-for-locale', version: '[4.0.2, 5.0['
|
||||||
compile 'com.android.volley:volley:1.0.0'
|
compile 'com.android.volley:volley:1.0.0'
|
||||||
compile 'com.github.hyb1996:EnhancedFloaty:0.15'
|
compile 'com.github.hyb1996:EnhancedFloaty:0.16'
|
||||||
compile 'com.flurry.android:analytics:7.0.0@aar'
|
compile 'com.flurry.android:analytics:7.0.0@aar'
|
||||||
compile 'com.pushtorefresh.storio:sqlite:1.12.3'
|
compile 'com.pushtorefresh.storio:sqlite:1.12.3'
|
||||||
compile 'com.android.support:multidex:1.0.1'
|
compile 'com.android.support:multidex:1.0.1'
|
||||||
|
|||||||
344
app/src/androidTest/java/com/stardust/NodeTest.java
Normal file
344
app/src/androidTest/java/com/stardust/NodeTest.java
Normal file
@@ -0,0 +1,344 @@
|
|||||||
|
package com.stardust;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Stardust on 2017/5/8.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Copyright (c) 2014 Tom Zhou<iwebpp@gmail.com>
|
||||||
|
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.iwebpp.node.EventEmitter.Listener;
|
||||||
|
import com.iwebpp.node.NodeContext;
|
||||||
|
import com.iwebpp.node.NodeContext.TimeoutListener;
|
||||||
|
import com.iwebpp.node.http.ClientRequest;
|
||||||
|
import com.iwebpp.node.http.ClientRequest.upgradeListener;
|
||||||
|
import com.iwebpp.node.http.HttpServer;
|
||||||
|
import com.iwebpp.node.http.HttpServer.clientErrorListener;
|
||||||
|
import com.iwebpp.node.http.http;
|
||||||
|
import com.iwebpp.node.http.IncomingMessage;
|
||||||
|
import com.iwebpp.node.http.ReqOptions;
|
||||||
|
import com.iwebpp.node.http.ServerResponse;
|
||||||
|
import com.iwebpp.node.net.AbstractSocket;
|
||||||
|
import com.iwebpp.node.stream.Writable.WriteCB;
|
||||||
|
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
|
public final class NodeTest {
|
||||||
|
private static final String TAG = "HttpTest";
|
||||||
|
private NodeContext ctx;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListening() throws Exception {
|
||||||
|
HttpServer srv;
|
||||||
|
final int port = 6188;
|
||||||
|
srv = new HttpServer(ctx);
|
||||||
|
|
||||||
|
srv.listen(port, "127.0.0.1", 4000, new HttpServer.ListeningCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListening() throws Exception {
|
||||||
|
Log.d(TAG, "http server listening on " + port);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Thread.sleep(8000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void testConnection() throws Exception {
|
||||||
|
final int port = 6288;
|
||||||
|
final HttpServer srv = new HttpServer(ctx, new HttpServer.requestListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequest(IncomingMessage req, ServerResponse res)
|
||||||
|
throws Exception {
|
||||||
|
Log.d(TAG, "got reqeust, headers: " + req.headers());
|
||||||
|
|
||||||
|
Map<String, List<String>> headers = new Hashtable<String, List<String>>();
|
||||||
|
headers.put("content-type", new ArrayList<String>());
|
||||||
|
headers.get("content-type").add("text/plain");
|
||||||
|
///headers.put("te", new LinkedList<String>());
|
||||||
|
///headers.get("te").add("chunk");
|
||||||
|
|
||||||
|
res.writeHead(200, headers);
|
||||||
|
///for (int i = 0; i < 10; i ++)
|
||||||
|
res.write("Hello Tom", "utf-8", new WriteCB() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeDone(String error) throws Exception {
|
||||||
|
Log.d(TAG, "http res.write done");
|
||||||
|
fail("http res.write done");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
res.end(null, null, null);
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
srv.onClientError(new clientErrorListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClientError(String exception, AbstractSocket socket) throws Exception {
|
||||||
|
Log.e(TAG, "client error: " + exception + "@" + socket);
|
||||||
|
fail("client error: " + exception + "@" + socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
srv.listen(port, "0.0.0.0", 10, new HttpServer.ListeningCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListening() throws Exception {
|
||||||
|
Log.d(TAG, "http server listening on " + port);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void testUpgrade() throws Exception {
|
||||||
|
final String host = "192.188.1.100";
|
||||||
|
final int port = 6668;
|
||||||
|
|
||||||
|
// client
|
||||||
|
ReqOptions ropt = new ReqOptions();
|
||||||
|
ropt.hostname = host;
|
||||||
|
ropt.port = port;
|
||||||
|
ropt.method = "GET";
|
||||||
|
ropt.path = "/";
|
||||||
|
|
||||||
|
ropt.headers.put("Connection", new ArrayList<String>());
|
||||||
|
ropt.headers.get("Connection").add("Upgrade");
|
||||||
|
|
||||||
|
ropt.headers.put("Upgrade", new ArrayList<String>());
|
||||||
|
ropt.headers.get("Upgrade").add("websocket");
|
||||||
|
|
||||||
|
ropt.headers.put("Host", new ArrayList<String>());
|
||||||
|
ropt.headers.get("Host").add("192.188.1.100:6668");
|
||||||
|
|
||||||
|
ropt.headers.put("Origin", new ArrayList<String>());
|
||||||
|
ropt.headers.get("Origin").add("http://192.188.1.100:6668");
|
||||||
|
|
||||||
|
ropt.headers.put("Sec-WebSocket-Version", new ArrayList<String>());
|
||||||
|
ropt.headers.get("Sec-WebSocket-Version").add("13");
|
||||||
|
|
||||||
|
ropt.headers.put("Sec-WebSocket-Key", new ArrayList<String>());
|
||||||
|
ropt.headers.get("Sec-WebSocket-Key").add("MTMtVHVlIE9jdCAwNyAxMzozNzoyMiBHTVQrMDg6MDAgMjAxNA==");
|
||||||
|
|
||||||
|
ClientRequest req = http.request(ctx, ropt, new ClientRequest.responseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(IncomingMessage res) throws Exception {
|
||||||
|
Log.d(TAG, "STATUS: " + res.statusCode());
|
||||||
|
Log.d(TAG, "HEADERS: " + res.getHeaders());
|
||||||
|
|
||||||
|
res.setEncoding("utf-8");
|
||||||
|
res.on("data", new Listener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Object chunk) throws Exception {
|
||||||
|
Log.d(TAG, "BODY: " + chunk);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
req.onceUpgrade(new upgradeListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(IncomingMessage res,
|
||||||
|
AbstractSocket socket, ByteBuffer head)
|
||||||
|
throws Exception {
|
||||||
|
Log.d(TAG, "got upgrade: " + res.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on("error", new Listener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Object e) throws Exception {
|
||||||
|
Log.d(TAG, "problem with request: " + e);
|
||||||
|
fail("problem with request: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
req.end(null, null, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void testConnect() throws Exception {
|
||||||
|
final String host = "192.188.1.100";
|
||||||
|
final int port = 51680;
|
||||||
|
|
||||||
|
// client
|
||||||
|
ReqOptions ropt = new ReqOptions();
|
||||||
|
ropt.hostname = host;
|
||||||
|
ropt.port = port;
|
||||||
|
ropt.method = "PUT";
|
||||||
|
ropt.path = "/";
|
||||||
|
///ropt.keepAlive = true;
|
||||||
|
///ropt.keepAliveMsecs = 10000;
|
||||||
|
|
||||||
|
ClientRequest req = http.request(ctx, ropt, new ClientRequest.responseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(IncomingMessage res) throws Exception {
|
||||||
|
Log.d(TAG, "STATUS: " + res.statusCode());
|
||||||
|
Log.d(TAG, "HEADERS: " + res.getHeaders());
|
||||||
|
|
||||||
|
res.setEncoding("utf-8");
|
||||||
|
res.on("data", new Listener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Object chunk) throws Exception {
|
||||||
|
Log.d(TAG, "BODY: " + chunk);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on("error", new Listener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Object e) throws Exception {
|
||||||
|
Log.d(TAG, "problem with request: " + e);
|
||||||
|
fail("problem with request: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// write data to request body
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
req.write("data" + i + "\n", "utf-8", null);
|
||||||
|
|
||||||
|
req.end(null, null, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void testConnectPair() throws Exception {
|
||||||
|
final int port = 6688;
|
||||||
|
|
||||||
|
final HttpServer srv = http.createServer(ctx, new HttpServer.requestListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequest(IncomingMessage req, ServerResponse res)
|
||||||
|
throws Exception {
|
||||||
|
Log.d(TAG, "got reqeust, headers: " + req.headers());
|
||||||
|
|
||||||
|
Map<String, List<String>> headers = new Hashtable<String, List<String>>();
|
||||||
|
headers.put("content-type", new ArrayList<String>());
|
||||||
|
headers.get("content-type").add("text/plain");
|
||||||
|
///headers.put("te", new ArrayList<String>());
|
||||||
|
///headers.get("te").add("chunk");
|
||||||
|
|
||||||
|
res.writeHead(200, headers);
|
||||||
|
res.write("Hello Tom", "utf-8", new WriteCB() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeDone(String error) throws Exception {
|
||||||
|
Log.d(TAG, "http res.write done");
|
||||||
|
fail("http res.write done");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
res.end(null, null, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
srv.listen(port, "0.0.0.0", 1, new HttpServer.ListeningCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListening() throws Exception {
|
||||||
|
Log.d(TAG, "http server listening on " + port);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// client
|
||||||
|
final ReqOptions ropt = new ReqOptions();
|
||||||
|
ropt.hostname = "localhost"; // IP address instead localhost
|
||||||
|
ropt.port = port;
|
||||||
|
ropt.method = "GET";
|
||||||
|
ropt.path = "/";
|
||||||
|
|
||||||
|
// defer 2s to connect
|
||||||
|
ctx.setTimeout(new TimeoutListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeout() throws Exception {
|
||||||
|
|
||||||
|
ClientRequest req = http.request(ctx, ropt, new ClientRequest.responseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(IncomingMessage res) throws Exception {
|
||||||
|
Log.d(TAG, "STATUS: " + res.statusCode());
|
||||||
|
Log.d(TAG, "HEADERS: " + res.getHeaders());
|
||||||
|
|
||||||
|
res.setEncoding("utf-8");
|
||||||
|
|
||||||
|
res.on("data", new Listener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Object chunk) throws Exception {
|
||||||
|
Log.d(TAG, "BODY: " + chunk);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on("error", new Listener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Object e) throws Exception {
|
||||||
|
Log.d(TAG, "problem with request: " + e);
|
||||||
|
fail("problem with request: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// write data to request body
|
||||||
|
///req.write("data\n", "utf-8", null);
|
||||||
|
///req.write("data\n", "utf-8", null);
|
||||||
|
req.end(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
this.ctx = new NodeContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.stardust;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Stardust on 2017/3/8.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
<activity android:name=".ui.help.HelpCatalogueActivity"/>
|
<activity android:name=".ui.help.HelpCatalogueActivity"/>
|
||||||
<activity android:name=".ui.settings.AboutActivity"/>
|
<activity android:name=".ui.settings.AboutActivity"/>
|
||||||
<activity android:name=".ui.settings.SettingsActivity"/>
|
<activity android:name=".ui.settings.SettingsActivity"/>
|
||||||
<activity android:name=".ui.console.ConsoleActivity"/>
|
<activity android:name=".ui.console.LogActivity"/>
|
||||||
<activity android:name=".ui.error.ErrorReportActivity"/>
|
<activity android:name=".ui.error.ErrorReportActivity"/>
|
||||||
<activity android:name=".ui.help.LocalWebViewActivity"/>
|
<activity android:name=".ui.help.LocalWebViewActivity"/>
|
||||||
<activity android:name=".external.tasker.TaskerScriptEditActivity"/>
|
<activity android:name=".external.tasker.TaskerScriptEditActivity"/>
|
||||||
|
|||||||
@@ -45,10 +45,6 @@ var rawInput = function(title, prefill){
|
|||||||
return dialogs.rawInput(title, prefill);
|
return dialogs.rawInput(title, prefill);
|
||||||
}
|
}
|
||||||
|
|
||||||
var input = function(title, prefill){
|
|
||||||
return dialogs.input(title, prefill);
|
|
||||||
}
|
|
||||||
|
|
||||||
var alert = function(title, prefill){
|
var alert = function(title, prefill){
|
||||||
dialogs.alert(title, prefill);
|
dialogs.alert(title, prefill);
|
||||||
}
|
}
|
||||||
|
|||||||
8
app/src/main/assets/sample/控制台/控制台示例.js
Normal file
8
app/src/main/assets/sample/控制台/控制台示例.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
//显示控制台
|
||||||
|
console.show();
|
||||||
|
|
||||||
|
console.verbose("这是灰色");
|
||||||
|
console.log("这是黑色");
|
||||||
|
console.info("这是红色");
|
||||||
|
console.warn("这是蓝色");
|
||||||
|
console.error("这是绿色=_=");
|
||||||
13
app/src/main/assets/sample/控制台/终端模拟器.js
Normal file
13
app/src/main/assets/sample/控制台/终端模拟器.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
var sh = new Shell();
|
||||||
|
sh.setCallback({
|
||||||
|
onNewLine: function(str){
|
||||||
|
console.log(str);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.show();
|
||||||
|
console.info("请输入要运行命令:");
|
||||||
|
do {
|
||||||
|
var cmd = console.rawInput();
|
||||||
|
sh.exec(cmd);
|
||||||
|
}while(cmd != "exit");
|
||||||
|
sh.exit();
|
||||||
@@ -6,7 +6,12 @@ import android.content.IntentFilter;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Keep;
|
import android.support.annotation.Keep;
|
||||||
import android.support.multidex.MultiDexApplication;
|
import android.support.multidex.MultiDexApplication;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.iwebpp.node.NodeContext;
|
||||||
|
import com.iwebpp.node.http.ClientRequest;
|
||||||
|
import com.iwebpp.node.http.IncomingMessage;
|
||||||
|
import com.iwebpp.node.http.http;
|
||||||
import com.squareup.leakcanary.LeakCanary;
|
import com.squareup.leakcanary.LeakCanary;
|
||||||
import com.stardust.app.SimpleActivityLifecycleCallbacks;
|
import com.stardust.app.SimpleActivityLifecycleCallbacks;
|
||||||
import com.stardust.app.VolumeChangeObserver;
|
import com.stardust.app.VolumeChangeObserver;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.stardust.scriptdroid.autojs.api;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.ContextWrapper;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@@ -24,12 +25,23 @@ public class BlockedMaterialDialog extends MaterialDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
if (!(getContext() instanceof Activity)) {
|
if (!isActivityContext(getContext())) {
|
||||||
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||||
}
|
}
|
||||||
super.show();
|
super.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isActivityContext(Context context) {
|
||||||
|
if (context == null)
|
||||||
|
return false;
|
||||||
|
if (context instanceof Activity)
|
||||||
|
return true;
|
||||||
|
if (context instanceof ContextWrapper) {
|
||||||
|
return isActivityContext(((ContextWrapper) context).getBaseContext());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Builder extends MaterialDialog.Builder {
|
public static class Builder extends MaterialDialog.Builder {
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.stardust.lang.ThreadCompat;
|
|||||||
import com.stardust.pio.UncheckedIOException;
|
import com.stardust.pio.UncheckedIOException;
|
||||||
import com.stardust.scriptdroid.App;
|
import com.stardust.scriptdroid.App;
|
||||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||||
|
import com.stardust.scriptdroid.tool.UpdateChecker;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -30,13 +31,39 @@ import jackpal.androidterm.util.TermSettings;
|
|||||||
public class Shell extends AbstractShell implements AutoCloseable {
|
public class Shell extends AbstractShell implements AutoCloseable {
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onNewLine(String str);
|
|
||||||
|
void onOutput(String str);
|
||||||
|
|
||||||
|
void onNewLine(String line);
|
||||||
|
|
||||||
void onInitialized();
|
void onInitialized();
|
||||||
|
|
||||||
void onInterrupted(InterruptedException e);
|
void onInterrupted(InterruptedException e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SimpleCallback implements Callback {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOutput(String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNewLine(String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialized() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInterrupted(InterruptedException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final String TAG = "Shell";
|
private static final String TAG = "Shell";
|
||||||
|
|
||||||
private TermSession mTermSession;
|
private TermSession mTermSession;
|
||||||
@@ -191,20 +218,19 @@ public class Shell extends AbstractShell implements AutoCloseable {
|
|||||||
|
|
||||||
private void onNewLine(String line) {
|
private void onNewLine(String line) {
|
||||||
Log.d(TAG, line);
|
Log.d(TAG, line);
|
||||||
if (mInitialized) {
|
if (!mInitialized) {
|
||||||
if (mCallback != null) {
|
|
||||||
mCallback.onNewLine(line);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isRoot() && line.endsWith(" $ su")) {
|
if (isRoot() && line.endsWith(" $ su")) {
|
||||||
notifyInitialized();
|
notifyInitialized();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isRoot() && line.endsWith(" $ ")) {
|
if (!isRoot() && line.endsWith(" $ sh")) {
|
||||||
notifyInitialized();
|
notifyInitialized();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.onNewLine(line);
|
||||||
|
}
|
||||||
if (mWaitingExit && line.endsWith(" exit")) {
|
if (mWaitingExit && line.endsWith(" exit")) {
|
||||||
notifyExit();
|
notifyExit();
|
||||||
}
|
}
|
||||||
@@ -214,7 +240,11 @@ public class Shell extends AbstractShell implements AutoCloseable {
|
|||||||
@Override
|
@Override
|
||||||
protected void processInput(byte[] data, int offset, int count) {
|
protected void processInput(byte[] data, int offset, int count) {
|
||||||
try {
|
try {
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.onOutput(new String(data, offset, count));
|
||||||
|
}
|
||||||
mOutputStream.write(data, offset, count);
|
mOutputStream.write(data, offset, count);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,11 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/3/10.
|
* Created by Stardust on 2017/3/10.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO: 2017/5/8
|
||||||
|
|
||||||
public class LayoutInspector {
|
public class LayoutInspector {
|
||||||
|
|
||||||
private volatile NodeInfo mCapture;
|
private volatile NodeInfo mCapture;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class InputEventRecorder extends Recorder.AbstractRecorder {
|
|||||||
|
|
||||||
public void listen() {
|
public void listen() {
|
||||||
mShell = new Shell(true);
|
mShell = new Shell(true);
|
||||||
mShell.setCallback(new Shell.Callback() {
|
mShell.setCallback(new Shell.SimpleCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onNewLine(String str) {
|
public void onNewLine(String str) {
|
||||||
if (mShell.isInitialized()) {
|
if (mShell.isInitialized()) {
|
||||||
|
|||||||
@@ -55,9 +55,8 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
|
|||||||
public View inflateExpandedView(FloatyService service, ResizableExpandableFloatyWindow window) {
|
public View inflateExpandedView(FloatyService service, ResizableExpandableFloatyWindow window) {
|
||||||
ensureContextWrapper(service);
|
ensureContextWrapper(service);
|
||||||
View view = View.inflate(mContextWrapper, R.layout.floating_console_expand, null);
|
View view = View.inflate(mContextWrapper, R.layout.floating_console_expand, null);
|
||||||
((ConsoleView) view.findViewById(R.id.console)).setConsole(mConsole);
|
|
||||||
setListeners(view, window);
|
setListeners(view, window);
|
||||||
initConsoleTitle(view);
|
setUpConsole(view, window);
|
||||||
setInitialMeasure(view);
|
setInitialMeasure(view);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@@ -79,6 +78,17 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setListeners(final View view, final ResizableExpandableFloatyWindow window) {
|
private void setListeners(final View view, final ResizableExpandableFloatyWindow window) {
|
||||||
|
setWindowOperationIconListeners(view, window);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpConsole(View view, ResizableExpandableFloatyWindow window) {
|
||||||
|
ConsoleView consoleView = (ConsoleView) view.findViewById(R.id.console);
|
||||||
|
consoleView.setConsole(mConsole);
|
||||||
|
consoleView.setWindow(window);
|
||||||
|
initConsoleTitle(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setWindowOperationIconListeners(View view, final ResizableExpandableFloatyWindow window) {
|
||||||
view.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
|
view.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package com.stardust.scriptdroid.ui.console;
|
package com.stardust.scriptdroid.ui.console;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.IntDef;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.AppCompatTextView;
|
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
@@ -13,26 +11,22 @@ import android.util.AttributeSet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.widget.Button;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
import com.stardust.util.MapEntries;
|
|
||||||
import com.stardust.util.SparseArrayEntries;
|
import com.stardust.util.SparseArrayEntries;
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/5/2.
|
* Created by Stardust on 2017/5/2.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ConsoleView extends LinearLayout implements StardustConsole.LogListener {
|
public class ConsoleView extends FrameLayout implements StardustConsole.LogListener {
|
||||||
|
|
||||||
private static final SparseArray<Integer> COLORS = new SparseArrayEntries<Integer>()
|
private static final SparseArray<Integer> COLORS = new SparseArrayEntries<Integer>()
|
||||||
.entry(Log.VERBOSE, 0xdfc0c0c0)
|
.entry(Log.VERBOSE, 0xdfc0c0c0)
|
||||||
@@ -46,6 +40,9 @@ public class ConsoleView extends LinearLayout implements StardustConsole.LogList
|
|||||||
private StardustConsole mConsole;
|
private StardustConsole mConsole;
|
||||||
private TextView mTextView;
|
private TextView mTextView;
|
||||||
private EditText mEditText;
|
private EditText mEditText;
|
||||||
|
private ResizableExpandableFloatyWindow mWindow;
|
||||||
|
private LinearLayout mInputContainer;
|
||||||
|
private ScrollView mContentContainer;
|
||||||
|
|
||||||
public ConsoleView(Context context) {
|
public ConsoleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -64,26 +61,43 @@ public class ConsoleView extends LinearLayout implements StardustConsole.LogList
|
|||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
inflate(getContext(), R.layout.console_view, this);
|
inflate(getContext(), R.layout.console_view, this);
|
||||||
mTextView = (TextView) findViewById(R.id.textView);
|
mTextView = (TextView) findViewById(R.id.content);
|
||||||
|
mTextView.setMovementMethod(new ScrollingMovementMethod());
|
||||||
|
mContentContainer = (ScrollView) findViewById(R.id.content_container);
|
||||||
|
initEditText();
|
||||||
|
initSubmitButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initEditText() {
|
private void initSubmitButton() {
|
||||||
//mEditText = (EditText) findViewById(R.id.ediText);
|
final Button submit = (Button) findViewById(R.id.submit);
|
||||||
mEditText.setFocusableInTouchMode(true);
|
submit.setOnClickListener(new OnClickListener() {
|
||||||
mTextView.setMovementMethod(new ScrollingMovementMethod());
|
|
||||||
setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mEditText.requestFocus();
|
CharSequence input = mEditText.getText();
|
||||||
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
submitInput(input);
|
||||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void submitInput(CharSequence input) {
|
||||||
|
if (android.text.TextUtils.isEmpty(input)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mConsole.submitInput(input)) {
|
||||||
|
mEditText.setText("");
|
||||||
|
mEditText.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initEditText() {
|
||||||
|
mEditText = (EditText) findViewById(R.id.input);
|
||||||
|
mEditText.setFocusableInTouchMode(true);
|
||||||
|
mInputContainer = (LinearLayout) findViewById(R.id.input_container);
|
||||||
|
}
|
||||||
|
|
||||||
public void setConsole(StardustConsole console) {
|
public void setConsole(StardustConsole console) {
|
||||||
mConsole = console;
|
mConsole = console;
|
||||||
mConsole.setLogListener(this);
|
mConsole.setConsoleView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,20 +113,12 @@ public class ConsoleView extends LinearLayout implements StardustConsole.LogList
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mTextView.append(spannable);
|
mTextView.append(spannable);
|
||||||
|
mContentContainer.fullScroll(View.FOCUS_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToBottom() {
|
|
||||||
mTextView.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mTextView.scrollTo(0, mTextView.getLayout().getLineTop(mTextView.getLineCount()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Spannable buildColorSpannable(CharSequence log, int color) {
|
private Spannable buildColorSpannable(CharSequence log, int color) {
|
||||||
Spannable spannable = new SpannableString(log);
|
Spannable spannable = new SpannableString(log);
|
||||||
spannable.setSpan(new ForegroundColorSpan(color), 0, log.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
spannable.setSpan(new ForegroundColorSpan(color), 0, log.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
@@ -144,4 +150,19 @@ public class ConsoleView extends LinearLayout implements StardustConsole.LogList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWindow(ResizableExpandableFloatyWindow window) {
|
||||||
|
mWindow = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showEditText() {
|
||||||
|
post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mWindow.requestWindowFocus();
|
||||||
|
mInputContainer.setVisibility(VISIBLE);
|
||||||
|
mEditText.requestFocus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class JraskaConsole extends AbstractConsole {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
App.getApp().startActivity(new Intent(App.getApp(), ConsoleActivity.class)
|
App.getApp().startActivity(new Intent(App.getApp(), LogActivity.class)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import com.stardust.scriptdroid.R;
|
|||||||
* Created by Stardust on 2017/2/12.
|
* Created by Stardust on 2017/2/12.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ConsoleActivity extends BaseActivity {
|
public class LogActivity extends BaseActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@@ -2,18 +2,24 @@ package com.stardust.scriptdroid.ui.console;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import com.stardust.autojs.runtime.ScriptInterface;
|
||||||
|
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||||
import com.stardust.autojs.runtime.api.AbstractConsole;
|
import com.stardust.autojs.runtime.api.AbstractConsole;
|
||||||
import com.stardust.autojs.runtime.api.Console;
|
import com.stardust.autojs.runtime.api.Console;
|
||||||
import com.stardust.enhancedfloaty.FloatyService;
|
import com.stardust.enhancedfloaty.FloatyService;
|
||||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||||
|
import com.stardust.scriptdroid.autojs.api.VolatileBox;
|
||||||
import com.stardust.util.UiHandler;
|
import com.stardust.util.UiHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/5/2.
|
* Created by Stardust on 2017/5/2.
|
||||||
@@ -44,6 +50,10 @@ public class StardustConsole extends AbstractConsole {
|
|||||||
private ConsoleFloaty mConsoleFloaty;
|
private ConsoleFloaty mConsoleFloaty;
|
||||||
private LogListener mLogListener;
|
private LogListener mLogListener;
|
||||||
private UiHandler mUiHandler;
|
private UiHandler mUiHandler;
|
||||||
|
//private volatile VolatileBox<String> mInput = new VolatileBox<>("");
|
||||||
|
private BlockingQueue<String> mInput = new ArrayBlockingQueue<>(1);
|
||||||
|
private ConsoleView mConsoleView;
|
||||||
|
private volatile boolean mShown = false;
|
||||||
|
|
||||||
public StardustConsole(UiHandler uiHandler) {
|
public StardustConsole(UiHandler uiHandler) {
|
||||||
mUiHandler = uiHandler;
|
mUiHandler = uiHandler;
|
||||||
@@ -51,6 +61,14 @@ public class StardustConsole extends AbstractConsole {
|
|||||||
mFloatyWindow = new ResizableExpandableFloatyWindow(mConsoleFloaty);
|
mFloatyWindow = new ResizableExpandableFloatyWindow(mConsoleFloaty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConsoleView(ConsoleView consoleView) {
|
||||||
|
mConsoleView = consoleView;
|
||||||
|
setLogListener(consoleView);
|
||||||
|
synchronized (this) {
|
||||||
|
this.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setLogListener(LogListener logListener) {
|
public void setLogListener(LogListener logListener) {
|
||||||
mLogListener = logListener;
|
mLogListener = logListener;
|
||||||
}
|
}
|
||||||
@@ -92,6 +110,7 @@ public class StardustConsole extends AbstractConsole {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mShown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startFloatyService() {
|
private void startFloatyService() {
|
||||||
@@ -106,6 +125,43 @@ public class StardustConsole extends AbstractConsole {
|
|||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
mShown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public String rawInput() {
|
||||||
|
if (mConsoleView == null) {
|
||||||
|
if (!mShown) {
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
waitConsoleView();
|
||||||
|
}
|
||||||
|
mConsoleView.showEditText();
|
||||||
|
try {
|
||||||
|
return mInput.take();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new ScriptInterruptedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waitConsoleView() {
|
||||||
|
synchronized (this) {
|
||||||
|
try {
|
||||||
|
this.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new ScriptInterruptedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public String rawInput(Object data, Object... param) {
|
||||||
|
log(data, param);
|
||||||
|
return rawInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean submitInput(@NonNull CharSequence input) {
|
||||||
|
return mInput.offer(input.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import com.stardust.scriptdroid.autojs.AutoJs;
|
|||||||
import com.stardust.scriptdroid.script.Scripts;
|
import com.stardust.scriptdroid.script.Scripts;
|
||||||
import com.stardust.scriptdroid.script.sample.Sample;
|
import com.stardust.scriptdroid.script.sample.Sample;
|
||||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||||
import com.stardust.scriptdroid.ui.console.ConsoleActivity;
|
|
||||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Activity;
|
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Activity;
|
||||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Utils;
|
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Utils;
|
||||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
|||||||
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||||
import com.stardust.view.ViewBinding;
|
import com.stardust.view.ViewBinding;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
import com.stardust.scriptdroid.ui.console.ConsoleActivity;
|
import com.stardust.scriptdroid.ui.console.LogActivity;
|
||||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||||
import com.stardust.view.ViewBinder;
|
import com.stardust.view.ViewBinder;
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class EditSideMenuFragment extends Fragment {
|
|||||||
|
|
||||||
@ViewBinding.Click(R.id.console)
|
@ViewBinding.Click(R.id.console)
|
||||||
private void startConsoleActivity() {
|
private void startConsoleActivity() {
|
||||||
startActivity(new Intent(getContext(), ConsoleActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
startActivity(new Intent(getContext(), LogActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBinding.Check(R.id.sw_floating_window)
|
@ViewBinding.Check(R.id.sw_floating_window)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
|||||||
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||||
import com.stardust.scriptdroid.ui.console.ConsoleActivity;
|
import com.stardust.scriptdroid.ui.console.LogActivity;
|
||||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||||
import com.stardust.util.UnderuseExecutors;
|
import com.stardust.util.UnderuseExecutors;
|
||||||
import com.stardust.view.ViewBinder;
|
import com.stardust.view.ViewBinder;
|
||||||
@@ -99,7 +99,7 @@ public class SlideMenuFragment extends Fragment {
|
|||||||
|
|
||||||
@ViewBinding.Click(R.id.console)
|
@ViewBinding.Click(R.id.console)
|
||||||
private void startConsoleActivity() {
|
private void startConsoleActivity() {
|
||||||
startActivity(new Intent(getContext(), ConsoleActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
startActivity(new Intent(getContext(), LogActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBinding.Click(R.id.syntax_and_api)
|
@ViewBinding.Click(R.id.syntax_and_api)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
<view
|
<view
|
||||||
android:id="@+id/console"
|
android:id="@+id/console"
|
||||||
class="com.stardust.scriptdroid.ui.console.ConsoleActivity$ConsoleView"
|
class="com.stardust.scriptdroid.ui.console.LogActivity$ConsoleView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,52 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical">
|
android:layout_height="match_parent"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<ScrollView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/content_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1">
|
||||||
android:paddingLeft="3dp"
|
|
||||||
android:textIsSelectable="true"
|
|
||||||
android:textSize="14sp"/>
|
|
||||||
|
|
||||||
</merge>
|
<TextView
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="3dp"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:textSize="14sp"
|
||||||
|
tools:text="12345\n678\n9\n0"/>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/input_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/input"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:lines="1"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/submit"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="@string/ok"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:theme="@style/AppTheme.Console"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -45,5 +45,9 @@
|
|||||||
|
|
||||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||||
|
|
||||||
|
<style name="AppTheme.Console" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
<item name="colorButtonNormal">#cc181818</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -17,19 +17,13 @@ var toast = function(text){
|
|||||||
__runtime__.toast(text);
|
__runtime__.toast(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
var app = __runtime__.app;
|
var app = require("app")(__runtime__);
|
||||||
|
|
||||||
var launchPackage = function(package){
|
var launchPackage = function(package){
|
||||||
app.launchPackage(package);
|
app.launchPackage(package);
|
||||||
}
|
}
|
||||||
|
|
||||||
var launch = function(a, b){
|
var launch = app.launch.bind(app);
|
||||||
if(arguments.length == 2){
|
|
||||||
app.launch(a, b);
|
|
||||||
}else{
|
|
||||||
app.launchPackage(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var launchApp = function(appName){
|
var launchApp = function(appName){
|
||||||
app.launchApp(appName);
|
app.launchApp(appName);
|
||||||
@@ -44,6 +38,7 @@ var openAppSetting = function(packageName){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var sleep = function(millis){
|
var sleep = function(millis){
|
||||||
__runtime__.sleep(millis);
|
__runtime__.sleep(millis);
|
||||||
}
|
}
|
||||||
@@ -81,9 +76,6 @@ var clearConsole = function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
var shell = function(cmd, root){
|
var shell = function(cmd, root){
|
||||||
if(arguments.length == 1){
|
|
||||||
return new com.stardust.scriptdroid.tool.Shell(context, arguments[0] ? 1 : 0);
|
|
||||||
}
|
|
||||||
root = root ? 1 : 0;
|
root = root ? 1 : 0;
|
||||||
return __runtime__.shell(cmd, root);
|
return __runtime__.shell(cmd, root);
|
||||||
}
|
}
|
||||||
@@ -96,6 +88,8 @@ var currentActivity = function(){
|
|||||||
return __runtime__.info.getLatestActivity();
|
return __runtime__.info.getLatestActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var __this__ = this;
|
var __this__ = this;
|
||||||
|
|
||||||
var back = function(){
|
var back = function(){
|
||||||
@@ -126,7 +120,6 @@ var splitScreen = function(){
|
|||||||
return __runtime__.automator.splitScreen();
|
return __runtime__.automator.splitScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function performAction(action, args){
|
function performAction(action, args){
|
||||||
if(args.length == 4){
|
if(args.length == 4){
|
||||||
return action(__runtime__.automator.bounds(args[0], args[1], args[2], args[3]));
|
return action(__runtime__.automator.bounds(args[0], args[1], args[2], args[3]));
|
||||||
|
|||||||
43
autojs/src/main/assets/modules/app.js
Normal file
43
autojs/src/main/assets/modules/app.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
module.exports = function(__runtime__){
|
||||||
|
var app = new Object(__runtime__.app);
|
||||||
|
|
||||||
|
app.intent = function(i) {
|
||||||
|
var intent = new android.content.Intent();
|
||||||
|
if (i.className && i.packageName) {
|
||||||
|
intent.setClassName(i.packageName, i.className);
|
||||||
|
}
|
||||||
|
if (i.extras) {
|
||||||
|
for (var key in i.extras) {
|
||||||
|
intent.putExtra(key, i.extras[key].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i.category) {
|
||||||
|
for (var key in i.category) {
|
||||||
|
intent.addCategory(key, i.category[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i.action) {
|
||||||
|
intent.setAction(i.action);
|
||||||
|
}
|
||||||
|
if (i.type) {
|
||||||
|
intent.setType(i.type);
|
||||||
|
}
|
||||||
|
if (i.data) {
|
||||||
|
intent.setData(android.net.Uri.parse(i.data));
|
||||||
|
}
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.startActivity = function(i){
|
||||||
|
context.startActivity(app.intent(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
app.sendBroadcast = function(i){
|
||||||
|
context.sendBroadcast(app.intent(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
app.launch = app.launchPackage;
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
@@ -81,6 +81,7 @@ public class ScriptEngineService {
|
|||||||
mScriptEngineManager.setEngineLifecycleCallback(mEngineLifecycleObserver);
|
mScriptEngineManager.setEngineLifecycleCallback(mEngineLifecycleObserver);
|
||||||
mScriptExecutionObserver.registerScriptExecutionListener(GLOBAL_LISTENER);
|
mScriptExecutionObserver.registerScriptExecutionListener(GLOBAL_LISTENER);
|
||||||
EVENT_BUS.register(this);
|
EVENT_BUS.register(this);
|
||||||
|
mScriptEngineManager.putGlobal("context", mUiHandler.getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Console getGlobalConsole() {
|
public Console getGlobalConsole() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.stardust.autojs.runtime;
|
package com.stardust.autojs.runtime;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import com.stardust.autojs.R;
|
import com.stardust.autojs.R;
|
||||||
@@ -136,6 +137,7 @@ public class ScriptRuntime extends AbstractScriptRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UiSelector selector(ScriptEngine engine) {
|
public UiSelector selector(ScriptEngine engine) {
|
||||||
|
Intent intent;
|
||||||
return new UiSelector(mAccessibilityBridge);
|
return new UiSelector(mAccessibilityBridge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.stardust.autojs.runtime.api;
|
package com.stardust.autojs.runtime.api;
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityService;
|
import android.accessibilityservice.AccessibilityService;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
@@ -149,6 +151,7 @@ public class UiSelector extends UiGlobalSelector {
|
|||||||
} else {
|
} else {
|
||||||
super.id(id);
|
super.id(id);
|
||||||
}
|
}
|
||||||
|
Intent intent;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.stardust.automator;
|
package com.stardust.automator;
|
||||||
|
|
||||||
import android.app.UiAutomation;
|
import android.app.UiAutomation;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@@ -152,7 +153,7 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
|||||||
@Override
|
@Override
|
||||||
public boolean performAction(int action, Bundle bundle) {
|
public boolean performAction(int action, Bundle bundle) {
|
||||||
try {
|
try {
|
||||||
return super.performAction(action);
|
return super.performAction(action, bundle);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
// FIXME: 2017/5/5
|
// FIXME: 2017/5/5
|
||||||
return false;
|
return false;
|
||||||
@@ -167,6 +168,8 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
|||||||
// FIXME: 2017/5/5
|
// FIXME: 2017/5/5
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.stardust.automator;
|
package com.stardust.automator;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
|
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user