From 921d82fcdcbd73be556bf5508771d145776f6160 Mon Sep 17 00:00:00 2001 From: Yu Shan Emily Lau Date: Thu, 14 Jul 2011 16:59:45 -0700 Subject: [PATCH] Add the Tap duration in the scripted monkey. Change-Id: Ie18872f6ab7934458f45fb2ac573a90a2c12319a --- .../android/commands/monkey/MonkeySourceScript.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java index f78c82569..a9a06096c 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java @@ -300,23 +300,29 @@ public class MonkeySourceScript implements MonkeyEventSource { } // Handle tap event - if ((s.indexOf(EVENT_KEYWORD_TAP) >= 0) && args.length == 2) { + if ((s.indexOf(EVENT_KEYWORD_TAP) >= 0) && args.length >= 2) { try { float x = Float.parseFloat(args[0]); float y = Float.parseFloat(args[1]); + long tapDuration = 0; + if (args.length == 3) { + tapDuration = Long.parseLong(args[2]); + } // Set the default parameters long downTime = SystemClock.uptimeMillis(); - MonkeyMotionEvent e1 = new MonkeyTouchEvent(MotionEvent.ACTION_DOWN) .setDownTime(downTime) .setEventTime(downTime) .addPointer(0, x, y, 1, 5); + mQ.addLast(e1); + if (tapDuration > 0){ + mQ.addLast(new MonkeyWaitEvent(tapDuration)); + } MonkeyMotionEvent e2 = new MonkeyTouchEvent(MotionEvent.ACTION_UP) .setDownTime(downTime) .setEventTime(downTime) .addPointer(0, x, y, 1, 5); - mQ.addLast(e1); mQ.addLast(e2); } catch (NumberFormatException e) { System.err.println("// " + e.toString());