From 3fbef289ae7df85b0189e233ead28af58102c53e Mon Sep 17 00:00:00 2001 From: jiangwei Date: Sun, 6 Sep 2020 13:49:40 +0800 Subject: [PATCH 1/2] v2.3 thanks for chongkaechin --- .gitignore | 7 + .../RobotHelper/GamePackage/Main.java | 7 + .../Tools/InputImp/AccessibilityInput.java | 14 ++ .../RobotHelper/Tools/InputImp/Input.java | 19 +- .../Tools/InputImp/InstrumentationInput.java | 217 ++++++++++++++++++ .../RobotHelper/Tools/InputImp/NullInput.java | 13 ++ .../RobotHelper/Tools/InputImp/RootInput.java | 14 ++ .../cn/xjiangwei/RobotHelper/Tools/Robot.java | 20 ++ UPDATE.md | 9 + 9 files changed, 318 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dedf1bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.idea/* +.gradle + + +.DS_Store +sendevent/.DS_Store +sendevent/bin/.DS_Store \ No newline at end of file diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/GamePackage/Main.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/GamePackage/Main.java index 76b6d2f..567d6c1 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/GamePackage/Main.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/GamePackage/Main.java @@ -72,6 +72,13 @@ public void start() { Robot.tap(point); + /***************************** 双指缩放操作 ************************************/ + + +// Robot.pinchOpen(100); // 目前仅在xposed模式中实现了该方法,distance值为0到100 +// Robot.pinchClose(100); // 目前仅在xposed模式中实现了该方法, + + /***** 提示 *****/ Toast.show("运行结束!"); //声音提示 diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/AccessibilityInput.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/AccessibilityInput.java index fad1473..9257bc5 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/AccessibilityInput.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/AccessibilityInput.java @@ -6,7 +6,9 @@ import android.support.annotation.RequiresApi; import cn.xjiangwei.RobotHelper.Service.Accessibility; +import cn.xjiangwei.RobotHelper.Tools.MLog; import cn.xjiangwei.RobotHelper.Tools.Point; +import cn.xjiangwei.RobotHelper.Tools.Toast; @RequiresApi(api = Build.VERSION_CODES.N) public class AccessibilityInput implements Input { @@ -101,4 +103,16 @@ public void swipe(float x1, float y1, float x2, float y2, float duration) { public void input(String str) { } + + @Override + public void pinchOpen(int distance) { + Toast.show("目前仅在xposed方式中实现了该方法"); + MLog.error("目前仅在xposed方式中实现了该方法"); + } + + @Override + public void pinchClose(int distance) { + Toast.show("目前仅在xposed方式中实现了该方法"); + MLog.error("目前仅在xposed方式中实现了该方法"); + } } diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java index 95010c0..c8ec1b1 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java @@ -6,8 +6,6 @@ public interface Input { - - /** * 点击操作 * @@ -52,4 +50,21 @@ public interface Input { * @param str */ void input(String str); + + + /** + * 放大屏幕(捏开) + * + * @param distance // 距离 // 缩放距离,0到100 + */ + void pinchOpen(int distance); + + + /** + * 缩小屏幕(捏合) + * + * @param distance // 距离 // 缩放距离,0到100 + */ + void pinchClose(int distance); + } diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java index 536a836..542d829 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java @@ -4,6 +4,7 @@ import android.os.SystemClock; import android.view.MotionEvent; +import cn.xjiangwei.RobotHelper.MainApplication; import cn.xjiangwei.RobotHelper.Tools.Point; import static android.os.SystemClock.sleep; @@ -105,6 +106,222 @@ public void input(String str) { } + /** + * https://github.com/Jinnrry/RobotHelper/issues/13 + * + * @param distance // 距离 // 缩放距离,0到100 + */ + @Override + public void pinchOpen(int distance) { + + if (distance > 100) { + distance = 100; + } + + if (distance < 0) { + distance = 0; + } + + + final int center_X = MainApplication.sceenWidth / 2; + final int center_Y = MainApplication.sceenHeight / 2; + + int point_x1 = 100; + int point_x2 = 700; + + + MotionEvent.PointerCoords pOneStart = new MotionEvent.PointerCoords(); + pOneStart.pressure = 1; + pOneStart.x = (point_x2 + point_x1) / 2; + pOneStart.y = center_Y; + pOneStart.size = 1; + + MotionEvent.PointerCoords pTwoStart = new MotionEvent.PointerCoords(); + pTwoStart.pressure = 1; + pTwoStart.x = (point_x2 + point_x1) / 2; + pTwoStart.y = center_Y; + pTwoStart.size = 1; + + + MotionEvent.PointerProperties pProp1 = new MotionEvent.PointerProperties(); + pProp1.id = 0; + pProp1.toolType = MotionEvent.TOOL_TYPE_FINGER; + + MotionEvent.PointerProperties pProp2 = new MotionEvent.PointerProperties(); + pProp2.id = 1; + pProp2.toolType = MotionEvent.TOOL_TYPE_FINGER; + + + MotionEvent.PointerCoords[] pCordStart = new MotionEvent.PointerCoords[]{pOneStart, pTwoStart}; + MotionEvent.PointerProperties[] pProp = new MotionEvent.PointerProperties[]{pProp1, pProp2}; + + + MotionEvent event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_DOWN, 1, pProp, pCordStart, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_POINTER_2_DOWN, 2, pProp, pCordStart, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + + for (int i = 0; i < distance; i++) { + MotionEvent.PointerCoords pOneTemp = new MotionEvent.PointerCoords(); + pOneTemp.pressure = 1; + pOneTemp.x = (point_x2 + point_x1) / 2 + (i * ((float) point_x2 - point_x1) / 200); + + pOneTemp.y = center_Y; + pOneTemp.size = 1; + MotionEvent.PointerCoords pTwoTemp = new MotionEvent.PointerCoords(); + pTwoTemp.pressure = 1; + pTwoTemp.x = (point_x2 + point_x1) / 2 - (i * ((float) point_x2 - point_x1) / 200); + + pTwoTemp.y = center_Y; + pTwoTemp.size = 1; + MotionEvent.PointerCoords[] pCordTemp = new MotionEvent.PointerCoords[]{pOneTemp, pTwoTemp}; + + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), + MotionEvent.ACTION_MOVE, 2, pProp, pCordTemp, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + sleep(25); + } + + + MotionEvent.PointerCoords pOneEnd = new MotionEvent.PointerCoords(); + pOneEnd.pressure = 1; + pOneEnd.x = point_x2; + pOneEnd.y = center_Y; + pOneEnd.size = 1; + + MotionEvent.PointerCoords pTwoEnd = new MotionEvent.PointerCoords(); + pTwoEnd.pressure = 1; + pTwoEnd.x = point_x1; + pTwoEnd.y = center_Y; + pTwoEnd.size = 1; + MotionEvent.PointerCoords[] pCordEnd = new MotionEvent.PointerCoords[]{pOneEnd, pTwoEnd}; + + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_POINTER_2_UP, 2, pProp, pCordEnd, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_UP, 1, pProp, pCordEnd, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + + } + + /** + * https://github.com/Jinnrry/RobotHelper/issues/13 + * + * @param distance // 距离 // 缩放距离,0到100 + */ + @Override + public void pinchClose(int distance) { + + if (distance > 100) { + distance = 100; + } + + if (distance < 0) { + distance = 0; + } + + + final int center_X = MainApplication.sceenWidth / 2; + final int center_Y = MainApplication.sceenHeight / 2; + + int point_x1 = 100; + int point_x2 = 700; + + + MotionEvent.PointerCoords pOneStart = new MotionEvent.PointerCoords(); + pOneStart.pressure = 1; + pOneStart.x = point_x1; + pOneStart.y = center_Y; + pOneStart.size = 1; + + MotionEvent.PointerCoords pTwoStart = new MotionEvent.PointerCoords(); + pTwoStart.pressure = 1; + pTwoStart.x = point_x2; + pTwoStart.y = center_Y; + pTwoStart.size = 1; + + + MotionEvent.PointerProperties pProp1 = new MotionEvent.PointerProperties(); + pProp1.id = 0; + pProp1.toolType = MotionEvent.TOOL_TYPE_FINGER; + + MotionEvent.PointerProperties pProp2 = new MotionEvent.PointerProperties(); + pProp2.id = 1; + pProp2.toolType = MotionEvent.TOOL_TYPE_FINGER; + + + MotionEvent.PointerCoords[] pCordStart = new MotionEvent.PointerCoords[]{pOneStart, pTwoStart}; + MotionEvent.PointerProperties[] pProp = new MotionEvent.PointerProperties[]{pProp1, pProp2}; + + + MotionEvent event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_DOWN, 1, pProp, pCordStart, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_POINTER_2_DOWN, 2, pProp, pCordStart, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + + for (int i = 0; i < distance; i++) { + MotionEvent.PointerCoords pOneTemp = new MotionEvent.PointerCoords(); + pOneTemp.pressure = 1; + pOneTemp.x = point_x1 + (i * ((float) point_x2 - point_x1) / 200); + + pOneTemp.y = center_Y; + pOneTemp.size = 1; + MotionEvent.PointerCoords pTwoTemp = new MotionEvent.PointerCoords(); + pTwoTemp.pressure = 1; + pTwoTemp.x = point_x2 - (i * ((float) point_x2 - point_x1) / 200); + + pTwoTemp.y = center_Y; + pTwoTemp.size = 1; + MotionEvent.PointerCoords[] pCordTemp = new MotionEvent.PointerCoords[]{pOneTemp, pTwoTemp}; + + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), + MotionEvent.ACTION_MOVE, 2, pProp, pCordTemp, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + sleep(25); + } + + + MotionEvent.PointerCoords pOneEnd = new MotionEvent.PointerCoords(); + pOneEnd.pressure = 1; + pOneEnd.x = (point_x2 + point_x1) / 2; + pOneEnd.y = center_Y; + pOneEnd.size = 1; + + MotionEvent.PointerCoords pTwoEnd = new MotionEvent.PointerCoords(); + pTwoEnd.pressure = 1; + pTwoEnd.x = (point_x2 + point_x1) / 2; + pTwoEnd.y = center_Y; + pTwoEnd.size = 1; + MotionEvent.PointerCoords[] pCordEnd = new MotionEvent.PointerCoords[]{pOneEnd, pTwoEnd}; + + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_POINTER_2_UP, 2, pProp, pCordEnd, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + + event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 25, + MotionEvent.ACTION_UP, 1, pProp, pCordEnd, 0, 0, 1, 1, 0, 0, 0, 0); + mInst.sendPointerSync(event); + + + } + private void down(float x, float y) { mInst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, x, y, 0)); diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/NullInput.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/NullInput.java index 30196c8..70dfe71 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/NullInput.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/NullInput.java @@ -61,4 +61,17 @@ public void input(String str) { MLog.error("没有权限执行操作!请检查xposed或者无障碍权限!"); Toast.show("没有权限执行操作!请检查xposed或者无障碍权限!"); } + + + @Override + public void pinchOpen(int distance) { + MLog.error("没有权限执行操作!请检查xposed或者无障碍权限!"); + Toast.show("没有权限执行操作!请检查xposed或者无障碍权限!"); + } + + @Override + public void pinchClose(int distance) { + MLog.error("没有权限执行操作!请检查xposed或者无障碍权限!"); + Toast.show("没有权限执行操作!请检查xposed或者无障碍权限!"); + } } diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/RootInput.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/RootInput.java index a80ce99..bc07be3 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/RootInput.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/RootInput.java @@ -13,8 +13,10 @@ import cn.xjiangwei.RobotHelper.MainApplication; import cn.xjiangwei.RobotHelper.Tools.FileUtils; +import cn.xjiangwei.RobotHelper.Tools.MLog; import cn.xjiangwei.RobotHelper.Tools.Point; import cn.xjiangwei.RobotHelper.Tools.ShellUtils; +import cn.xjiangwei.RobotHelper.Tools.Toast; import static android.os.SystemClock.sleep; @@ -1072,4 +1074,16 @@ private void up() { exec(EV_KEY, BTN_TOUCH, UP); exec(EV_SYN, SYN_REPORT, 0x00000000); } + + @Override + public void pinchOpen(int distance) { + Toast.show("目前仅在xposed方式中实现了该方法"); + MLog.error("目前仅在xposed方式中实现了该方法"); + } + + @Override + public void pinchClose(int distance) { + Toast.show("目前仅在xposed方式中实现了该方法"); + MLog.error("目前仅在xposed方式中实现了该方法"); + } } diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/Robot.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/Robot.java index 1e0e130..ff36cfe 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/Robot.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/Robot.java @@ -134,4 +134,24 @@ public static void input(String str) { getInput().input(str); } + + /** + * 放大屏幕(捏开) + * + * @param distance // 缩放距离,0到100 + */ + public static void pinchOpen(int distance) { + getInput().pinchOpen(distance); + } + + + /** + * 缩小屏幕(捏合) + * + * @param distance // 缩放距离,0到100 + */ + public static void pinchClose(int distance) { + getInput().pinchClose(distance); + } + } diff --git a/UPDATE.md b/UPDATE.md index a2c8510..a425d6a 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -1,3 +1,12 @@ +## V2.3版本新功能 + +1.加入双指缩放功能 + +感谢chongkaechin实现。 + +https://github.com/Jinnrry/RobotHelper/issues/13 + + ## V2.2版本新功能 1.加入了Root权限实现点击操作,目前仅在oneplus 7pro上测试通过,不保证所有手机兼容。遇到无法使用的问题欢迎提bug From 6ee595cca82db760b086e9343ad45f803ab4d4a7 Mon Sep 17 00:00:00 2001 From: jiangwei Date: Sun, 6 Sep 2020 13:56:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java | 4 ++-- .../RobotHelper/Tools/InputImp/InstrumentationInput.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java index c8ec1b1..a1b2795 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/Input.java @@ -53,7 +53,7 @@ public interface Input { /** - * 放大屏幕(捏开) + * 放大屏幕(双指捏开) * * @param distance // 距离 // 缩放距离,0到100 */ @@ -61,7 +61,7 @@ public interface Input { /** - * 缩小屏幕(捏合) + * 缩小屏幕(双指捏合) * * @param distance // 距离 // 缩放距离,0到100 */ diff --git a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java index 542d829..2da3311 100644 --- a/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java +++ b/Android/app/src/main/java/cn/xjiangwei/RobotHelper/Tools/InputImp/InstrumentationInput.java @@ -126,8 +126,8 @@ public void pinchOpen(int distance) { final int center_X = MainApplication.sceenWidth / 2; final int center_Y = MainApplication.sceenHeight / 2; - int point_x1 = 100; - int point_x2 = 700; + int point_x1 = 100; // 这里最好不要硬编码,小屏幕会出问题 + int point_x2 = 700; // 这里最好不要硬编码,小屏幕会出问题 MotionEvent.PointerCoords pOneStart = new MotionEvent.PointerCoords(); @@ -165,6 +165,7 @@ public void pinchOpen(int distance) { mInst.sendPointerSync(event); + // 一共一百步 for (int i = 0; i < distance; i++) { MotionEvent.PointerCoords pOneTemp = new MotionEvent.PointerCoords(); pOneTemp.pressure = 1; @@ -234,8 +235,8 @@ public void pinchClose(int distance) { final int center_X = MainApplication.sceenWidth / 2; final int center_Y = MainApplication.sceenHeight / 2; - int point_x1 = 100; - int point_x2 = 700; + int point_x1 = 100; // 这里最好不要硬编码,小屏幕会出问题 + int point_x2 = 700; // 这里最好不要硬编码,小屏幕会出问题 MotionEvent.PointerCoords pOneStart = new MotionEvent.PointerCoords();