我有一個儀器,我想用來測試我的應用程序,但我似乎無法得到捏縮放模擬正確。這是我目前的代碼。它的要點是:按下手指1和手指2,將它們相互靠近移動,然後釋放它們。如何製作MotionEvent進行縮放?
private void performZoomTest(int numUpdates) {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
float x1 = 0;
float y1 = 0;
Display main = activity.getWindowManager().getDefaultDisplay();
float x2 = main.getWidth();
float y2 = main.getHeight();
float xstep = x2/(2 * numUpdates);
float ystep = y2/(2 * numUpdates);
int id1 = 0 << MotionEvent.ACTION_POINTER_ID_SHIFT;
int id2 = 1 << MotionEvent.ACTION_POINTER_ID_SHIFT;
MotionEvent event =
MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN + id1,
x1, y1, 0);
sendPointerSync(event);
event =
MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN + id2,
x2, y2, 0);
sendPointerSync(event);
waitForIdleSync();
for (int i = 0; i < numUpdates; i++) {
eventTime = SystemClock.uptimeMillis();
Log.i("",Integer.toString(i));
x1 += xstep;
y1 += ystep;
x2 -= xstep;
y2 -= ystep;
event =
MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_MOVE + id1,
x1, y1, 0);
Log.i("id1", Integer.toString(MotionEvent.ACTION_MOVE + id1));
sendPointerSync(event);
event =
MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_MOVE + id2,
x2, y2, 0);
Log.i("id1", Integer.toString(MotionEvent.ACTION_MOVE + id2));
sendPointerSync(event);
waitForIdleSync();
}
eventTime = SystemClock.uptimeMillis();
event =
MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_UP + id1,
x1, y1, 0);
sendPointerSync(event);
event =
MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_UP + id2,
x2, y2, 0);
sendPointerSync(event);
waitForIdleSync();
}
結果似乎是應用程序將兩個事件視爲不同的事件,並且不會將它們註冊爲單個事件。有沒有更好的方法來做到這一點?
這怎麼可能?有很多應用程序依賴於它,如何不支持單元測試? – Alex 2011-06-10 20:05:33
問問在框架上工作的人。 :-) 我不知道... – stk 2011-06-12 02:00:42