Skip to content

Commit

Permalink
Merge pull request #16 from Jinnrry/feature-v2.3
Browse files Browse the repository at this point in the history
v2.3 thanks for chongkaechin
  • Loading branch information
Jinnrry authored Sep 6, 2020
2 parents afbec81 + 6ee595c commit f5669b3
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea/*
.gradle


.DS_Store
sendevent/.DS_Store
sendevent/bin/.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public void start() {
Robot.tap(point);


/***************************** 双指缩放操作 ************************************/


// Robot.pinchOpen(100); // 目前仅在xposed模式中实现了该方法,distance值为0到100
// Robot.pinchClose(100); // 目前仅在xposed模式中实现了该方法,


/***** 提示 *****/
Toast.show("运行结束!");
//声音提示
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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方式中实现了该方法");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
public interface Input {




/**
* 点击操作
*
Expand Down Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,6 +106,223 @@ 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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或者无障碍权限!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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方式中实现了该方法");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
9 changes: 9 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## V2.3版本新功能

1.加入双指缩放功能

感谢chongkaechin实现。

https://github.com/Jinnrry/RobotHelper/issues/13


## V2.2版本新功能

1.加入了Root权限实现点击操作,目前仅在oneplus 7pro上测试通过,不保证所有手机兼容。遇到无法使用的问题欢迎提bug
Expand Down

0 comments on commit f5669b3

Please sign in to comment.