TouchEvent implements Serializable { public MotionEvent getConstructedMotionEvent(int maxX, int maxY) { MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[this.subEvents.size()]; MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[this.subEvents.size()]; this.generateDataMultiTouch(pointerCoords,pointerProperties,this.subEvents); this.calculateCorrectCords(pointerCoords,maxX,maxY); return MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), action, counterPointer, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, 0, 0 ); } TouchEvent(float x, float y, int action, long downTime);  TouchEvent(MotionEvent m);  TouchEvent(MotionEvent m, Point screenSize); MotionEvent getConstructedMotionEvent(int maxX, int maxY); @Override String toString(); public float x; public float y; public int action; public long downTime; }
@Test public void getConstructedMotionEvent() { MotionEvent m = MotionEvent.obtain( 100, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 100, 200, 0); TouchEvent t = new TouchEvent(m); MotionEvent mnew = t.getConstructedMotionEvent(1, 1); assertMotionEventEqual(mnew, m); }
@Test public void assertGetConstructedMotionEventMultiTouch() { int eventCounter = 3; MotionEvent.PointerCoords cordsArray[] = new MotionEvent.PointerCoords[3]; MotionEvent.PointerProperties propertiesArray[] = new MotionEvent.PointerProperties[3]; MotionEvent.PointerProperties prop1 = new MotionEvent.PointerProperties(); prop1.id = 0; prop1.toolType = MotionEvent.TOOL_TYPE_FINGER; MotionEvent.PointerProperties prop2 = new MotionEvent.PointerProperties(); prop2.id = 1; prop2.toolType = MotionEvent.TOOL_TYPE_FINGER; MotionEvent.PointerProperties prop3 = new MotionEvent.PointerProperties(); prop3.id = 2; prop3.toolType = MotionEvent.TOOL_TYPE_FINGER; MotionEvent.PointerCoords cord1 = new MotionEvent.PointerCoords(); cord1.x = 100; cord1.y = 200; cord1.size = 1; MotionEvent.PointerCoords cord2 = new MotionEvent.PointerCoords(); cord1.x = 300; cord1.y = 400; cord1.size = 1; MotionEvent.PointerCoords cord3 = new MotionEvent.PointerCoords(); cord1.x = 500; cord1.y = 600; cord1.size = 1; cordsArray[0] = cord1; cordsArray[1] = cord2; cordsArray[2] = cord3; propertiesArray[0] = prop1; propertiesArray[1] = prop2; propertiesArray[2] = prop3; MotionEvent m = MotionEvent.obtain( 100, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN,eventCounter,propertiesArray,cordsArray,0, 0,1,1,0,0,0,0); Log.d("TEst", "getConstructedMotionEventMultiTouch: " + m); TouchEvent t = new TouchEvent(m); MotionEvent mnew = t.getConstructedMotionEvent(1, 1); assertMotionEventEqualMultiTouch(mnew, m); }