save works
This commit is contained in:
@@ -22,8 +22,8 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
|
|||||||
private int mLastTouchY = -1;
|
private int mLastTouchY = -1;
|
||||||
|
|
||||||
public InputEventToSendEventJsConverter() {
|
public InputEventToSendEventJsConverter() {
|
||||||
mCode.append("var sh = new Shell(true);\n")
|
mCode.append("var ies = new InputEventSender();\n")
|
||||||
.append("sh.SetScreenMetrics(").append(getDeviceScreenWidth()).append(", ")
|
.append("ies.setScreenMetrics(").append(getDeviceScreenWidth()).append(", ")
|
||||||
.append(getDeviceScreenHeight()).append(");\n");
|
.append(getDeviceScreenHeight()).append(");\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
|
|||||||
if (mLastEventTime == 0) {
|
if (mLastEventTime == 0) {
|
||||||
mLastEventTime = event.time;
|
mLastEventTime = event.time;
|
||||||
} else if (event.time - mLastEventTime > 0.03) {
|
} 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;
|
mLastEventTime = event.time;
|
||||||
}
|
}
|
||||||
int device = parseDeviceNumber(event.device);
|
int device = parseDeviceNumber(event.device);
|
||||||
@@ -51,7 +51,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkLastTouch();
|
checkLastTouch();
|
||||||
mCode.append("sh.SendEvent(");
|
mCode.append("ies.sendEvent(");
|
||||||
if (device != mTouchDevice) {
|
if (device != mTouchDevice) {
|
||||||
mCode.append(device).append(", ");
|
mCode.append(device).append(", ");
|
||||||
}
|
}
|
||||||
@@ -62,11 +62,11 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
|
|||||||
|
|
||||||
private void checkLastTouch() {
|
private void checkLastTouch() {
|
||||||
if (mLastTouchX >= 0) {
|
if (mLastTouchX >= 0) {
|
||||||
mCode.append("sh.TouchX(").append(mLastTouchX).append(");\n");
|
mCode.append("ies.touchX(").append(mLastTouchX).append(");\n");
|
||||||
mLastTouchX = -1;
|
mLastTouchX = -1;
|
||||||
}
|
}
|
||||||
if (mLastTouchY >= 0) {
|
if (mLastTouchY >= 0) {
|
||||||
mCode.append("sh.TouchY(").append(mLastTouchY).append(");\n");
|
mCode.append("ies.touchY(").append(mLastTouchY).append(");\n");
|
||||||
mLastTouchY = -1;
|
mLastTouchY = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
|
|||||||
setTouchDevice(device);
|
setTouchDevice(device);
|
||||||
}
|
}
|
||||||
if (mLastTouchX >= 0) {
|
if (mLastTouchX >= 0) {
|
||||||
mCode.append("sh.Touch(")
|
mCode.append("ies.touch(")
|
||||||
.append(mLastTouchX).append(", ")
|
.append(mLastTouchX).append(", ")
|
||||||
.append(value).append(");\n");
|
.append(value).append(");\n");
|
||||||
mLastTouchX = -1;
|
mLastTouchX = -1;
|
||||||
@@ -103,7 +103,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setTouchDevice(int i) {
|
private void setTouchDevice(int i) {
|
||||||
mCode.append("sh.SetTouchDevice(").append(i).append(");\n");
|
mCode.append("ies.setInputDevice(").append(i).append(");\n");
|
||||||
mTouchDevice = i;
|
mTouchDevice = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ public class InputEventToSendEventJsConverter extends InputEventConverter {
|
|||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
super.stop();
|
super.stop();
|
||||||
mCode.append("sh.exitAndWaitFor();");
|
mCode.append("ies.exitAndWaitFor();");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String hex2dec(String hex) {
|
private static String hex2dec(String hex) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.stardust.theme;
|
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.*;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
|
|
||||||
|
|||||||
@@ -36,3 +36,4 @@ require("__general__")(__runtime__, this);
|
|||||||
})(__that__);
|
})(__that__);
|
||||||
|
|
||||||
__importClass__(com.stardust.autojs.runtime.api.Shell);
|
__importClass__(com.stardust.autojs.runtime.api.Shell);
|
||||||
|
__importClass__(com.stardust.autojs.runtime.api.InputEventSender);
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -190,4 +190,12 @@ public abstract class AbstractShell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void exitAndWaitFor();
|
public abstract void exitAndWaitFor();
|
||||||
|
|
||||||
|
public void sleep(long i) {
|
||||||
|
exec("sleep " + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void usleep(long l) {
|
||||||
|
exec("usleep " + l);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user