Merge "more fixes to monkey motion event timing" into jb-dev

This commit is contained in:
Guang Zhu
2012-05-06 17:13:21 -07:00
committed by Android (Google) Code Review

View File

@@ -328,7 +328,7 @@ public class MonkeySourceScript implements MonkeyEventSource {
try {
float x = Float.parseFloat(args[0]);
float y = Float.parseFloat(args[1]);
long tapDuration = 0;
long tapDuration = 5;
if (args.length == 3) {
tapDuration = Long.parseLong(args[2]);
}
@@ -396,6 +396,7 @@ public class MonkeySourceScript implements MonkeyEventSource {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MonkeyWaitEvent wayPointDelay = new MonkeyWaitEvent(5);
if (stepCount > 0) {
float xStep = (xEnd - xStart) / stepCount;
float yStep = (yEnd - yStart) / stepCount;
@@ -406,6 +407,7 @@ public class MonkeySourceScript implements MonkeyEventSource {
mQ.addLast(e);
for (int i = 0; i < stepCount; ++i) {
mQ.addLast(wayPointDelay);
x += xStep;
y += yStep;
eventTime = SystemClock.uptimeMillis();
@@ -414,6 +416,7 @@ public class MonkeySourceScript implements MonkeyEventSource {
mQ.addLast(e);
}
mQ.addLast(wayPointDelay);
eventTime = SystemClock.uptimeMillis();
e = new MonkeyTouchEvent(MotionEvent.ACTION_UP).setDownTime(downTime)
.setEventTime(eventTime).addPointer(0, x, y, 1, 5);
@@ -808,16 +811,24 @@ public class MonkeySourceScript implements MonkeyEventSource {
/**
* Adjust motion downtime and eventtime according to current system time.
*
* @param e A KeyEvent
* @param e A MotionEvent
*/
private void adjustMotionEventTime(MonkeyMotionEvent e) {
long updatedDownTime = 0;
long thisEventTime = SystemClock.uptimeMillis();
long thisDownTime = e.getDownTime();
updatedDownTime = SystemClock.uptimeMillis();
if (e.getDownTime() < 0) {
e.setDownTime(updatedDownTime);
if (thisDownTime == mLastRecordedDownTimeMotion) {
// this event is the same batch as previous one
e.setDownTime(mLastExportDownTimeMotion);
} else {
// this event is the start of a new batch
mLastRecordedDownTimeMotion = thisDownTime;
// update down time to match current time
e.setDownTime(thisEventTime);
mLastExportDownTimeMotion = thisEventTime;
}
e.setEventTime(updatedDownTime);
// always refresh event time
e.setEventTime(thisEventTime);
}
/**