Change adb-shell-input utility to use duration for swipe

Change-Id: Id48fade60a07220c0672697f5771b75f984ee5bd
This commit is contained in:
Chet Haase
2012-10-02 19:27:40 -07:00
parent 369a7f493e
commit 4ec7ea72d2

View File

@@ -72,7 +72,7 @@ public class Input {
} else if (command.equals("swipe")) {
if (args.length == 5) {
sendSwipe(InputDevice.SOURCE_TOUCHSCREEN, Float.parseFloat(args[1]), Float.parseFloat(args[2]),
Float.parseFloat(args[3]), Float.parseFloat(args[4]));
Float.parseFloat(args[3]), Float.parseFloat(args[4]), -1);
return;
}
} else if (command.equals("touchscreen") || command.equals("touchpad")) {
@@ -94,7 +94,12 @@ public class Input {
if (args.length == 6) {
sendSwipe(inputSource, Float.parseFloat(args[2]),
Float.parseFloat(args[3]), Float.parseFloat(args[4]),
Float.parseFloat(args[5]));
Float.parseFloat(args[5]), -1);
return;
} else if (args.length == 7) {
sendSwipe(inputSource, Float.parseFloat(args[2]),
Float.parseFloat(args[3]), Float.parseFloat(args[4]),
Float.parseFloat(args[5]), Integer.parseInt(args[6]));
return;
}
}
@@ -172,14 +177,20 @@ public class Input {
injectMotionEvent(inputSource, MotionEvent.ACTION_UP, now, x, y, 0.0f);
}
private void sendSwipe(int inputSource, float x1, float y1, float x2, float y2) {
final int NUM_STEPS = 11;
private void sendSwipe(int inputSource, float x1, float y1, float x2, float y2, int duration) {
if (duration < 0) {
duration = 300;
}
long now = SystemClock.uptimeMillis();
injectMotionEvent(inputSource, MotionEvent.ACTION_DOWN, now, x1, y1, 1.0f);
for (int i = 1; i < NUM_STEPS; i++) {
float alpha = (float) i / NUM_STEPS;
long startTime = now;
long endTime = startTime + duration;
while (now < endTime) {
long elapsedTime = now - startTime;
float alpha = (float) elapsedTime / duration;
injectMotionEvent(inputSource, MotionEvent.ACTION_MOVE, now, lerp(x1, x2, alpha),
lerp(y1, y2, alpha), 1.0f);
now = SystemClock.uptimeMillis();
}
injectMotionEvent(inputSource, MotionEvent.ACTION_UP, now, x1, y1, 0.0f);
}
@@ -237,7 +248,7 @@ public class Input {
System.err.println(" input text <string>");
System.err.println(" input keyevent <key code number or name>");
System.err.println(" input [touchscreen|touchpad] tap <x> <y>");
System.err.println(" input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2>");
System.err.println(" input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2> [duration(ms)]");
System.err.println(" input trackball press");
System.err.println(" input trackball roll <dx> <dy>");
}