diff options
author | Chet Haase <chet@google.com> | 2012-10-02 19:27:40 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2012-10-02 19:30:03 -0700 |
commit | 4ec7ea72d2a9de6b79b11f7e0d12def5b58ef878 (patch) | |
tree | c699d35f371e343be3471b1e3f8109dd7070856c /cmds/input/src/com | |
parent | 369a7f493e10af296138e50b922414afaa127313 (diff) | |
download | frameworks_base-4ec7ea72d2a9de6b79b11f7e0d12def5b58ef878.zip frameworks_base-4ec7ea72d2a9de6b79b11f7e0d12def5b58ef878.tar.gz frameworks_base-4ec7ea72d2a9de6b79b11f7e0d12def5b58ef878.tar.bz2 |
Change adb-shell-input utility to use duration for swipe
Change-Id: Id48fade60a07220c0672697f5771b75f984ee5bd
Diffstat (limited to 'cmds/input/src/com')
-rwxr-xr-x | cmds/input/src/com/android/commands/input/Input.java | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/cmds/input/src/com/android/commands/input/Input.java b/cmds/input/src/com/android/commands/input/Input.java index a21df0d..cdbc405 100755 --- a/cmds/input/src/com/android/commands/input/Input.java +++ b/cmds/input/src/com/android/commands/input/Input.java @@ -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>"); } |