more fixes to monkey motion event timing

Last attempt to fix ACTION_MOVE ended up breaking stuff
elsewhere.

For a touch based gesture, it usually have a group of motion
events, and typically they have the same down time and individual
event times. Example: a tap should have ACTION_DOWN with same
down time and event time, and subsequent ACTION_UP should have
the same down time as previous one, but a fresh event time.
Similar situation applies to ACTION_DOWN, ACTION_MOVEs,
ACTION_UP sequence of a drag/scroll/fling gesture

In addition, a 5ms delay is added for a tap between DOWN and
UP. And a 5ms delay is added for each injected event in a drag
gesture

Change-Id: I8e65e578152b1c1ff1fa4c0f476ef45806826479
This commit is contained in:
Guang Zhu
2012-05-04 12:52:34 -07:00
parent a8863a9614
commit 77dc0d2eab

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);
}
/**