如何使用Espresso執行多點觸摸刷卡?例如用兩根手指向右滑動。如何使用Espresso執行多點觸摸刷卡?
1
A
回答
2
由於@Daniel建議,我創建MotionEvents的定製版本,因爲使用多個手指時,你必須注入ACTION_POINTER_DOWN/UP,而不是ACTION_DOWN/UP。 我創建LinearSwipe的twoFinger版本,像這樣:
private static Swiper.Status sendLinearSwipe(UiController uiController,
float[] startCoordinates,
float[] startCoordinatesSecondFinger,
float[] endCoordinates,
float[]endCoordinatesSecondFinger,
float[] precision,
float[] precisionSecond,
int duration) {
checkNotNull(uiController);
checkNotNull(startCoordinates);
checkNotNull(startCoordinatesSecondFinger);
checkNotNull(endCoordinates);
checkNotNull(endCoordinatesSecondFinger);
checkNotNull(precision);
checkNotNull(precisionSecond);
float[][] steps = interpolate(startCoordinates, endCoordinates, SWIPE_EVENT_COUNT);
float[][] stepsSecondFinger = interpolate(startCoordinatesSecondFinger, endCoordinatesSecondFinger, SWIPE_EVENT_COUNT);
final int delayBetweenMovements = duration/steps.length;
final int delayBetweenMovementsSecondFinger = duration/stepsSecondFinger.length;
int maxLength=Math.min(steps.length, stepsSecondFinger.length);
MotionEvent downEvent;
downEvent = MotionEvents.sendDown(uiController, steps[0], precision,true).down;
MotionEvent downEventSecondFinger;
downEventSecondFinger = MotionEvents.sendDown(uiController,stepsSecondFinger[0], precisionSecond,false).down;
try {
for (int i = 1; i < maxLength; i++) {
if (sendMovement(uiController, steps[i], downEvent)) return Status.FAILURE;
if (sendMovement(uiController, stepsSecondFinger[i], downEventSecondFinger)) return Status.FAILURE;
long desiredTime = downEvent.getDownTime() + delayBetweenMovements * i;
long desiredTimeSecondFinger = downEventSecondFinger.getDownTime() + delayBetweenMovementsSecondFinger * i;
long timeUntilDesired = desiredTime - SystemClock.uptimeMillis();
long timeUntilDesiredSecondFinger = desiredTimeSecondFinger - SystemClock.uptimeMillis();
loopMainThread(uiController, timeUntilDesired);
loopMainThread(uiController, timeUntilDesiredSecondFinger);
}
if (!MotionEvents.sendUp(uiController, downEventSecondFinger, endCoordinatesSecondFinger,false)) {
Log.e(TAG, "Injection of up event as part of the swipe failed. Sending cancel event.");
MotionEvents.sendCancel(uiController, downEventSecondFinger);
return Swiper.Status.FAILURE;
}
} finally {
downEvent.recycle();
downEventSecondFinger.recycle();
}
return Swiper.Status.SUCCESS;
}
private static void loopMainThread(UiController uiController, long timeUntilDesired) {
if (timeUntilDesired > 10) {
uiController.loopMainThreadForAtLeast(timeUntilDesired);
}
}
private static boolean sendMovement(UiController uiController, float[] step, MotionEvent downEvent) {
if (!MotionEvents.sendMovement(uiController, downEvent, step)) {
Log.e(TAG, "Injection of move event as part of the swipe failed. Sending cancel event.");
MotionEvents.sendCancel(uiController, downEvent);
return true;
}
return false;
}
現在,它完美的作品!由於@Daniel
1
咖啡不提供該功能,但你可以通過
- 注射兩降事件
- 注入幾雙運動事件,每一個手指
- 注入兩個上事件做自己
意式濃縮咖啡有一些實用工具可以使它更容易。特別是,MotionEvents
類有一些輔助方法來創建和注入這些低級事件。
您可能要參考sendLinearSwipe
代碼包含大部分邏輯的單點觸摸刷卡。
如果您將其編寫爲ViewAction
,它將完全適合Espresso框架(例如,您可以輕鬆地等待空閒資源)。
+0
謝謝,我現在的工作。但是,當我注入兩個事件時它失敗了。但是,如果我只注入一個事件,它可以正常工作:) – HowieH 2015-03-18 14:16:57
相關問題
- 1. 多點觸摸刷卡不工作
- 2. 在單次刷卡上創建多點觸摸事件
- 3. 觸摸/刷卡後恢復flexslider
- 4. 觸摸開始與多點觸摸讓
- 5. 如何讓Qwt接受觸摸和多點觸摸事件?
- 6. 使用Libgdx在Robovm上多點觸摸
- 7. 使用monkeyrunner的多點觸摸操作
- 8. Android Espresso Test卡住執行(click());
- 9. 如何檢測多點觸摸事件?
- 10. 如何防止在Android中刷卡時發生觸摸事件?
- 11. 如何檢測onTouchEvent()中的單點觸摸以及多點觸摸()
- 12. 多點觸摸檢測
- 13. 多點觸摸事件
- 14. 多點觸摸android系統
- 15. iPhone多點觸摸座標
- 16. soundpool中的多點觸摸
- 17. C#WPF WebBrowser多點觸摸
- 18. 在單點觸摸越來越多點觸摸事件
- 19. 當多個觸摸靠得太近時,iOS觸摸會卡住?
- 20. jquery動能啓用標準垂直觸摸刷卡
- 21. 使用Espresso執行點擊隨機列表元素
- 22. 如何使用Espresso點擊Android Gallery
- 23. 表面:多焦點,多點觸摸,多應用
- 24. 如何通過Espresso執行ArrayList中的第一項的點擊
- 25. 如何使用刷卡庫
- 26. UIImageView觸摸點
- 27. 實現多點觸摸......需要存儲的第二觸摸
- 28. 如何使用Espresso執行EditText的actionDone事件
- 29. Android RecyclerView:點擊行刷卡
- 30. UIRefreshControl - 如何在觸摸釋放後進行刷新操作?
您是否還可以在您的示例中包含interpolate方法? – Adrian 2016-03-23 10:03:45