save works

This commit is contained in:
hyb1996 2017-07-16 21:47:34 +08:00
parent 73773faedc
commit 248338016b
6 changed files with 140 additions and 9 deletions

View File

@ -22,8 +22,8 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
private int mLastTouchY = -1;
public InputEventToSendEventJsConverter() {
mCode.append("var sh = new Shell(true);\n")
.append("sh.SetScreenMetrics(").append(getDeviceScreenWidth()).append(", ")
mCode.append("var ies = new InputEventSender();\n")
.append("ies.setScreenMetrics(").append(getDeviceScreenWidth()).append(", ")
.append(getDeviceScreenHeight()).append(");\n");
}
@ -33,7 +33,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
if (mLastEventTime == 0) {
mLastEventTime = event.time;
} else if (event.time - mLastEventTime > 0.03) {
mCode.append("sleep(").append((long) (1000 * (event.time - mLastEventTime))).append(");\n");
mCode.append("sleep(").append((long) (1000L * (event.time - mLastEventTime))).append(");\n");
mLastEventTime = event.time;
}
int device = parseDeviceNumber(event.device);
@ -51,7 +51,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
}
}
checkLastTouch();
mCode.append("sh.SendEvent(");
mCode.append("ies.sendEvent(");
if (device != mTouchDevice) {
mCode.append(device).append(", ");
}
@ -62,11 +62,11 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
private void checkLastTouch() {
if (mLastTouchX >= 0) {
mCode.append("sh.TouchX(").append(mLastTouchX).append(");\n");
mCode.append("ies.touchX(").append(mLastTouchX).append(");\n");
mLastTouchX = -1;
}
if (mLastTouchY >= 0) {
mCode.append("sh.TouchY(").append(mLastTouchY).append(");\n");
mCode.append("ies.touchY(").append(mLastTouchY).append(");\n");
mLastTouchY = -1;
}
}
@ -93,7 +93,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
setTouchDevice(device);
}
if (mLastTouchX >= 0) {
mCode.append("sh.Touch(")
mCode.append("ies.touch(")
.append(mLastTouchX).append(", ")
.append(value).append(");\n");
mLastTouchX = -1;
@ -103,7 +103,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
}
private void setTouchDevice(int i) {
mCode.append("sh.SetTouchDevice(").append(i).append(");\n");
mCode.append("ies.setInputDevice(").append(i).append(");\n");
mTouchDevice = i;
}
@ -119,7 +119,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
@Override
public void stop() {
super.stop();
mCode.append("sh.exitAndWaitFor();");
mCode.append("ies.exitAndWaitFor();");
}
private static String hex2dec(String hex) {

View File

@ -1,5 +1,7 @@
package com.stardust.theme;
import com.jecelyin.editor.v2.core.widget.JecEditText;
import com.jecelyin.editor.v2.ui.EditorDelegate;
import com.stardust.scriptdroid.*;
import com.stardust.scriptdroid.R;

View File

@ -36,3 +36,4 @@ require("__general__")(__runtime__, this);
})(__that__);
__importClass__(com.stardust.autojs.runtime.api.Shell);
__importClass__(com.stardust.autojs.runtime.api.InputEventSender);

View File

@ -0,0 +1,34 @@
package com.stardust.autojs.execution;
import com.stardust.autojs.ScriptEngineService;
import com.stardust.autojs.engine.ScriptEngine;
import com.stardust.autojs.runtime.ScriptRuntime;
import com.stardust.autojs.runtime.api.AbstractShell;
import com.stardust.autojs.runtime.api.ProcessShell;
import com.stardust.util.IntentExtras;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Stardust on 2017/7/16.
*/
public class RootedScriptExecution extends RunnableScriptExecution {
private static int count = 0;
private static Map<String, ScriptExecutionTask> arguments = new HashMap<>();
public RootedScriptExecution(ScriptEngineService service, ScriptExecutionTask task) {
super(service, task);
}
@Override
public void run() {
}
public static void main(String[] args) {
}
}

View File

@ -190,4 +190,12 @@ public abstract class AbstractShell {
}
public abstract void exitAndWaitFor();
public void sleep(long i) {
exec("sleep " + i);
}
public void usleep(long l) {
exec("usleep " + l);
}
}

View File

@ -0,0 +1,86 @@
package com.stardust.autojs.runtime.api;
import com.stardust.util.ScreenMetrics;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Created by Stardust on 2017/7/16.
*/
public class InputEventSender {
private DataOutputStream mDeviceFile;
private ScreenMetrics mScreenMetrics;
public InputEventSender(String devicePath) throws FileNotFoundException {
mDeviceFile = new DataOutputStream(new FileOutputStream(devicePath));
}
public InputEventSender(int i) throws FileNotFoundException {
this("/dev/input/event" + i);
}
public InputEventSender() {
}
public void sendEvent(int type, int code, int value) throws IOException {
for (int i = 0; i < 16; i++)
mDeviceFile.writeByte(0);
mDeviceFile.writeShort(type);
mDeviceFile.writeShort(code);
mDeviceFile.writeInt(value);
mDeviceFile.flush();
}
public void setInputDevice(int i) throws IOException {
if (mDeviceFile != null) {
mDeviceFile.close();
}
mDeviceFile = new DataOutputStream(new FileOutputStream("/dev/input/event" + i));
}
public void Touch(int x, int y) throws IOException {
TouchX(x);
TouchY(y);
}
public void setScreenMetrics(int width, int height) {
if (mScreenMetrics == null) {
mScreenMetrics = new ScreenMetrics();
}
mScreenMetrics.setScreenMetrics(width, height);
}
public void TouchX(int x) throws IOException {
sendEvent(3, 53, scaleX(x));
}
private int scaleX(int x) {
return mScreenMetrics.scaleX(x);
}
public void TouchY(int y) throws IOException {
sendEvent(3, 54, scaleY(y));
}
private int scaleY(int y) {
return mScreenMetrics.scaleY(y);
}
public void close() throws IOException {
mDeviceFile.close();
}
}