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 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.github.hyb1996:EnhancedFloaty:0.15'
|
||||
compile 'com.github.hyb1996:EnhancedFloaty:0.16'
|
||||
compile 'com.flurry.android:analytics:7.0.0@aar'
|
||||
compile 'com.pushtorefresh.storio:sqlite:1.12.3'
|
||||
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.settings.AboutActivity"/>
|
||||
<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.help.LocalWebViewActivity"/>
|
||||
<activity android:name=".external.tasker.TaskerScriptEditActivity"/>
|
||||
|
||||
@@ -45,10 +45,6 @@ var rawInput = function(title, prefill){
|
||||
return dialogs.rawInput(title, prefill);
|
||||
}
|
||||
|
||||
var input = function(title, prefill){
|
||||
return dialogs.input(title, prefill);
|
||||
}
|
||||
|
||||
var alert = function(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.support.annotation.Keep;
|
||||
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.stardust.app.SimpleActivityLifecycleCallbacks;
|
||||
import com.stardust.app.VolumeChangeObserver;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.stardust.scriptdroid.autojs.api;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -24,12 +25,23 @@ public class BlockedMaterialDialog extends MaterialDialog {
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
if (!(getContext() instanceof Activity)) {
|
||||
if (!isActivityContext(getContext())) {
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
}
|
||||
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 {
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.stardust.lang.ThreadCompat;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.tool.UpdateChecker;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -30,13 +31,39 @@ import jackpal.androidterm.util.TermSettings;
|
||||
public class Shell extends AbstractShell implements AutoCloseable {
|
||||
|
||||
public interface Callback {
|
||||
void onNewLine(String str);
|
||||
|
||||
void onOutput(String str);
|
||||
|
||||
void onNewLine(String line);
|
||||
|
||||
void onInitialized();
|
||||
|
||||
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 TermSession mTermSession;
|
||||
@@ -191,20 +218,19 @@ public class Shell extends AbstractShell implements AutoCloseable {
|
||||
|
||||
private void onNewLine(String line) {
|
||||
Log.d(TAG, line);
|
||||
if (mInitialized) {
|
||||
if (mCallback != null) {
|
||||
mCallback.onNewLine(line);
|
||||
}
|
||||
} else {
|
||||
if (!mInitialized) {
|
||||
if (isRoot() && line.endsWith(" $ su")) {
|
||||
notifyInitialized();
|
||||
return;
|
||||
}
|
||||
if (!isRoot() && line.endsWith(" $ ")) {
|
||||
if (!isRoot() && line.endsWith(" $ sh")) {
|
||||
notifyInitialized();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mCallback != null) {
|
||||
mCallback.onNewLine(line);
|
||||
}
|
||||
if (mWaitingExit && line.endsWith(" exit")) {
|
||||
notifyExit();
|
||||
}
|
||||
@@ -214,7 +240,11 @@ public class Shell extends AbstractShell implements AutoCloseable {
|
||||
@Override
|
||||
protected void processInput(byte[] data, int offset, int count) {
|
||||
try {
|
||||
if (mCallback != null) {
|
||||
mCallback.onOutput(new String(data, offset, count));
|
||||
}
|
||||
mOutputStream.write(data, offset, count);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,11 @@ import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/10.
|
||||
*
|
||||
*/
|
||||
|
||||
// TODO: 2017/5/8
|
||||
|
||||
public class LayoutInspector {
|
||||
|
||||
private volatile NodeInfo mCapture;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class InputEventRecorder extends Recorder.AbstractRecorder {
|
||||
|
||||
public void listen() {
|
||||
mShell = new Shell(true);
|
||||
mShell.setCallback(new Shell.Callback() {
|
||||
mShell.setCallback(new Shell.SimpleCallback() {
|
||||
@Override
|
||||
public void onNewLine(String str) {
|
||||
if (mShell.isInitialized()) {
|
||||
|
||||
@@ -55,9 +55,8 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
|
||||
public View inflateExpandedView(FloatyService service, ResizableExpandableFloatyWindow window) {
|
||||
ensureContextWrapper(service);
|
||||
View view = View.inflate(mContextWrapper, R.layout.floating_console_expand, null);
|
||||
((ConsoleView) view.findViewById(R.id.console)).setConsole(mConsole);
|
||||
setListeners(view, window);
|
||||
initConsoleTitle(view);
|
||||
setUpConsole(view, window);
|
||||
setInitialMeasure(view);
|
||||
return view;
|
||||
}
|
||||
@@ -79,6 +78,17 @@ public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableEx
|
||||
}
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.stardust.scriptdroid.ui.console;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.AppCompatTextView;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
@@ -13,26 +11,22 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.util.MapEntries;
|
||||
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.
|
||||
*/
|
||||
|
||||
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>()
|
||||
.entry(Log.VERBOSE, 0xdfc0c0c0)
|
||||
@@ -46,6 +40,9 @@ public class ConsoleView extends LinearLayout implements StardustConsole.LogList
|
||||
private StardustConsole mConsole;
|
||||
private TextView mTextView;
|
||||
private EditText mEditText;
|
||||
private ResizableExpandableFloatyWindow mWindow;
|
||||
private LinearLayout mInputContainer;
|
||||
private ScrollView mContentContainer;
|
||||
|
||||
public ConsoleView(Context context) {
|
||||
super(context);
|
||||
@@ -64,26 +61,43 @@ public class ConsoleView extends LinearLayout implements StardustConsole.LogList
|
||||
|
||||
private void init() {
|
||||
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() {
|
||||
//mEditText = (EditText) findViewById(R.id.ediText);
|
||||
mEditText.setFocusableInTouchMode(true);
|
||||
mTextView.setMovementMethod(new ScrollingMovementMethod());
|
||||
setOnClickListener(new OnClickListener() {
|
||||
private void initSubmitButton() {
|
||||
final Button submit = (Button) findViewById(R.id.submit);
|
||||
submit.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mEditText.requestFocus();
|
||||
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||
CharSequence input = mEditText.getText();
|
||||
submitInput(input);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
mConsole = console;
|
||||
mConsole.setLogListener(this);
|
||||
mConsole.setConsoleView(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,20 +113,12 @@ public class ConsoleView extends LinearLayout implements StardustConsole.LogList
|
||||
@Override
|
||||
public void run() {
|
||||
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) {
|
||||
Spannable spannable = new SpannableString(log);
|
||||
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
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.stardust.scriptdroid.R;
|
||||
* Created by Stardust on 2017/2/12.
|
||||
*/
|
||||
|
||||
public class ConsoleActivity extends BaseActivity {
|
||||
public class LogActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -2,18 +2,24 @@ package com.stardust.scriptdroid.ui.console;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
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.Console;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.autojs.api.VolatileBox;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/2.
|
||||
@@ -44,6 +50,10 @@ public class StardustConsole extends AbstractConsole {
|
||||
private ConsoleFloaty mConsoleFloaty;
|
||||
private LogListener mLogListener;
|
||||
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) {
|
||||
mUiHandler = uiHandler;
|
||||
@@ -51,6 +61,14 @@ public class StardustConsole extends AbstractConsole {
|
||||
mFloatyWindow = new ResizableExpandableFloatyWindow(mConsoleFloaty);
|
||||
}
|
||||
|
||||
public void setConsoleView(ConsoleView consoleView) {
|
||||
mConsoleView = consoleView;
|
||||
setLogListener(consoleView);
|
||||
synchronized (this) {
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLogListener(LogListener logListener) {
|
||||
mLogListener = logListener;
|
||||
}
|
||||
@@ -92,6 +110,7 @@ public class StardustConsole extends AbstractConsole {
|
||||
}
|
||||
}
|
||||
});
|
||||
mShown = true;
|
||||
}
|
||||
|
||||
private void startFloatyService() {
|
||||
@@ -106,6 +125,43 @@ public class StardustConsole extends AbstractConsole {
|
||||
} 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
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
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.Editor920Utils;
|
||||
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.view.ViewBinding;
|
||||
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.view.ViewBinder;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class EditSideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Click(R.id.console)
|
||||
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)
|
||||
|
||||
@@ -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.service.AccessibilityWatchDogService;
|
||||
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.util.UnderuseExecutors;
|
||||
import com.stardust.view.ViewBinder;
|
||||
@@ -99,7 +99,7 @@ public class SlideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Click(R.id.console)
|
||||
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)
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<view
|
||||
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_height="match_parent"/>
|
||||
|
||||
|
||||
@@ -1,16 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
<ScrollView
|
||||
android:id="@+id/content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:paddingLeft="3dp"
|
||||
android:textIsSelectable="true"
|
||||
android:textSize="14sp"/>
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
</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.Console" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorButtonNormal">#cc181818</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user