+ * Command to "tap" at a location (Sends a down and up touch
+ * event).
+ */
+ private static class TapCommand implements MonkeyCommand {
+ // tap x y
+ public MonkeyEvent translateCommand(List<String> command,
+ CommandQueue queue) {
+ if (command.size() == 3) {
+ int x = 0;
+ int y = 0;
+ try {
+ x = Integer.parseInt(command.get(1));
+ y = Integer.parseInt(command.get(2));
+ } catch (NumberFormatException e) {
+ // Ok, it wasn't a number
+ Log.e(TAG, "Got something that wasn't a number", e);
+ return null;
+ }
+
+ queue.enqueueEvent(new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
+ -1, MotionEvent.ACTION_DOWN,
+ x, y, 0));
+ queue.enqueueEvent(new MonkeyMotionEvent(MonkeyEvent.EVENT_TYPE_POINTER,
+ -1, MotionEvent.ACTION_UP,
+ x, y, 0));
+ return new MonkeyNoopEvent();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Command to "press" a buttons (Sends an up and down key event.)
+ */
+ private static class PressCommand implements MonkeyCommand {
+ // press keycode
+ public MonkeyEvent translateCommand(List<String> command,
+ CommandQueue queue) {
+ if (command.size() == 2) {
+ int keyCode = getKeyCode(command.get(1));
+ if (keyCode < 0) {
+ // Ok, you gave us something bad.
+ Log.e(TAG, "Can't find keyname: " + command.get(1));
+ return null;
+ }
+
+ queue.enqueueEvent(new MonkeyKeyEvent(KeyEvent.ACTION_DOWN, keyCode));
+ queue.enqueueEvent(new MonkeyKeyEvent(KeyEvent.ACTION_UP, keyCode));
+ return new MonkeyNoopEvent();
+
+ }
+ return null;
+ }
+ }
+
+ /**