development
Révision | 6310bf8f3be51ec84f7ecbed4116d633232d864b (tree) |
---|---|
l'heure | 2011-02-10 08:56:04 |
Auteur | Yu Shan Emily Lau <yslau@goog...> |
Commiter | Android (Google) Code Review |
Merge "Added the Drag action to the scripted moneky"
@@ -115,6 +115,8 @@ public class MonkeySourceScript implements MonkeyEventSource { | ||
115 | 115 | |
116 | 116 | private static final String EVENT_KEYWORD_PRESSANDHOLD = "PressAndHold"; |
117 | 117 | |
118 | + private static final String EVENT_KEYWORD_DRAG = "Drag"; | |
119 | + | |
118 | 120 | // a line at the end of the header |
119 | 121 | private static final String STARTING_DATA_LINE = "start data >>"; |
120 | 122 |
@@ -345,6 +347,44 @@ public class MonkeySourceScript implements MonkeyEventSource { | ||
345 | 347 | return; |
346 | 348 | } |
347 | 349 | |
350 | + // Handle drag event | |
351 | + if ((s.indexOf(EVENT_KEYWORD_DRAG) >= 0) && args.length == 5) { | |
352 | + float xStart = Float.parseFloat(args[0]); | |
353 | + float yStart = Float.parseFloat(args[1]); | |
354 | + float xEnd = Float.parseFloat(args[2]); | |
355 | + float yEnd = Float.parseFloat(args[3]); | |
356 | + int stepCount = Integer.parseInt(args[4]); | |
357 | + | |
358 | + float x = xStart; | |
359 | + float y = yStart; | |
360 | + long downTime = SystemClock.uptimeMillis(); | |
361 | + long eventTime = SystemClock.uptimeMillis(); | |
362 | + | |
363 | + if (stepCount > 0) { | |
364 | + float xStep = (xEnd - xStart) / stepCount; | |
365 | + float yStep = (yEnd - yStart) / stepCount; | |
366 | + | |
367 | + MonkeyMotionEvent e = | |
368 | + new MonkeyTouchEvent(MotionEvent.ACTION_DOWN).setDownTime(downTime) | |
369 | + .setEventTime(eventTime).addPointer(0, x, y, 1, 5); | |
370 | + mQ.addLast(e); | |
371 | + | |
372 | + for (int i = 0; i < stepCount; ++i) { | |
373 | + x += xStep; | |
374 | + y += yStep; | |
375 | + eventTime = SystemClock.uptimeMillis(); | |
376 | + e = new MonkeyTouchEvent(MotionEvent.ACTION_MOVE).setDownTime(downTime) | |
377 | + .setEventTime(eventTime).addPointer(0, x, y, 1, 5); | |
378 | + mQ.addLast(e); | |
379 | + } | |
380 | + | |
381 | + eventTime = SystemClock.uptimeMillis(); | |
382 | + e = new MonkeyTouchEvent(MotionEvent.ACTION_UP).setDownTime(downTime) | |
383 | + .setEventTime(eventTime).addPointer(0, x, y, 1, 5); | |
384 | + mQ.addLast(e); | |
385 | + } | |
386 | + } | |
387 | + | |
348 | 388 | // Handle flip events |
349 | 389 | if (s.indexOf(EVENT_KEYWORD_FLIP) >= 0 && args.length == 1) { |
350 | 390 | boolean keyboardOpen = Boolean.parseBoolean(args[0]); |