modularize init script
This commit is contained in:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 23
|
||||
versionCode 122
|
||||
versionName "2.0.9c Alpha"
|
||||
versionCode 123
|
||||
versionName "2.0.9d Alpha"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
|
||||
@@ -1,344 +0,0 @@
|
||||
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,6 +1,6 @@
|
||||
var num1 = input("请输入第一个数字");
|
||||
var num1 = dialogs.input("请输入第一个数字");
|
||||
var op = dialogs.singleChoice("请选择运算", 0, "加", "减", "乘", "除", "幂");
|
||||
var num2 = input("请输入第二个数字");
|
||||
var num2 = dialogs.input("请输入第二个数字");
|
||||
var result = 0;
|
||||
switch(op){
|
||||
case 0:
|
||||
|
||||
10
app/src/main/assets/sample/应用/卸载应用.js
Normal file
10
app/src/main/assets/sample/应用/卸载应用.js
Normal file
@@ -0,0 +1,10 @@
|
||||
//输入应用名称
|
||||
var appName = rawInput('请输入要卸载的应用名称');
|
||||
//获取应用包名
|
||||
var packageName = getPackageName(appName);
|
||||
if(!packageName){
|
||||
toast("应用不存在!");
|
||||
}else{
|
||||
//卸载应用
|
||||
app.uninstall(packageName);
|
||||
}
|
||||
10
app/src/main/assets/sample/应用/发送意图-QQ文本消息分享.js
Normal file
10
app/src/main/assets/sample/应用/发送意图-QQ文本消息分享.js
Normal file
@@ -0,0 +1,10 @@
|
||||
var content = rawInput('请输入要分享的文本');
|
||||
app.startActivity({
|
||||
action: "android.intent.action.SEND",
|
||||
type: "text/*",
|
||||
extras: {
|
||||
"android.intent.extra.TEXT": content
|
||||
},
|
||||
packageName: "com.tencent.mobileqq",
|
||||
className: "com.tencent.mobileqq.activity.JumpActivity"
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
//以UTF-8编码打开SD卡上的1.txt文件
|
||||
var in = open("/sdcard/1.txt", "r", "utf-8");
|
||||
var f = open("/sdcard/1.txt", "r", "utf-8");
|
||||
//读取文件所有内容
|
||||
var text = in.read();
|
||||
var text = f.read();
|
||||
//关闭文件
|
||||
in.close();
|
||||
f.close();
|
||||
//以gbk编码打开SD卡上的2.txt文件
|
||||
var out = open("/sdcard/2.txt", "w", "gbk");
|
||||
//写入内容
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"auto";
|
||||
launch("com.tencent.mm");
|
||||
sleep(500);
|
||||
while(!click("发现"));
|
||||
while(!click("扫一扫"));
|
||||
@@ -1,3 +1,4 @@
|
||||
"auto";
|
||||
launchApp("支付宝");
|
||||
sleep(800);
|
||||
while(!click("扫一扫"));
|
||||
@@ -8,6 +8,9 @@ import com.stardust.autojs.runtime.api.AutomatorConfig;
|
||||
import com.stardust.automator.AccessibilityEventCommandHost;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
|
||||
import org.mozilla.javascript.tools.debugger.Dim;
|
||||
import org.mozilla.javascript.tools.debugger.GuiCallback;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/31.
|
||||
*/
|
||||
@@ -78,7 +81,7 @@ public class Pref {
|
||||
return def().getString(getString(R.string.key_stop_record_trigger), null);
|
||||
}
|
||||
|
||||
public static boolean hasRecordTrigger(){
|
||||
public static boolean hasRecordTrigger() {
|
||||
String startTrigger = getStartRecordTrigger();
|
||||
String stopTrigger = getStartRecordTrigger();
|
||||
return startTrigger != null && !startTrigger.equals("NONE")
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.stardust.scriptdroid.external.floating_window;
|
||||
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/9.
|
||||
*/
|
||||
|
||||
public class OverlayPermissionChecker {
|
||||
|
||||
|
||||
public static void addFloaty() {
|
||||
FloatyService.addWindow(new FloatyWindow() {
|
||||
@Override
|
||||
public void onCreate(FloatyService floatyService, WindowManager windowManager) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDestroy(FloatyService floatyService) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class OnePixelWindow implements FloatyWindow {
|
||||
|
||||
@Override
|
||||
public void onCreate(FloatyService floatyService, WindowManager windowManager) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDestroy(FloatyService floatyService) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,12 +27,10 @@ public class ExampleUnitTest {
|
||||
// TODO: 2017/3/24 编辑界面文档和自动补全
|
||||
// TODO: 2017/3/24 驻留模式
|
||||
//// TODO: 2017/3/26 NODEJS
|
||||
// TODO: 2017/3/26 加密
|
||||
// TODO: 2017/3/31 自定义快捷方式图标
|
||||
|
||||
|
||||
// FIXME: 2017/3/23 死机重启问题
|
||||
// FIXME: 2017/3/23 卡顿问题
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user