/** * Extracts the touch point data from a MotionEvent, converts each point into a marshallable * object and passes the set of points to the JNI layer to be transmitted to the remote host. * * @param event The event to send to the remote host for injection. NOTE: This object must be * updated to represent the remote machine's coordinate system before calling this function. */ public void sendTouchEvent(MotionEvent event) { int action = event.getActionMasked(); TouchEventData.EventType touchEventType = TouchEventData.EventType.fromMaskedAction(action); List<TouchEventData> touchEventList = new ArrayList<TouchEventData>(); if (action == MotionEvent.ACTION_MOVE) { // In order to process all of the events associated with an ACTION_MOVE event, we need // to walk the list of historical events in order and add each event to our list, then // retrieve the current move event data. int pointerCount = event.getPointerCount(); int historySize = event.getHistorySize(); for (int h = 0; h < historySize; ++h) { for (int p = 0; p < pointerCount; ++p) { touchEventList.add( new TouchEventData( event.getPointerId(p), event.getHistoricalX(p, h), event.getHistoricalY(p, h), event.getHistoricalSize(p, h), event.getHistoricalSize(p, h), event.getHistoricalOrientation(p, h), event.getHistoricalPressure(p, h))); } } for (int p = 0; p < pointerCount; p++) { touchEventList.add( new TouchEventData( event.getPointerId(p), event.getX(p), event.getY(p), event.getSize(p), event.getSize(p), event.getOrientation(p), event.getPressure(p))); } } else { // For all other events, we only want to grab the current/active pointer. The event // contains a list of every active pointer but passing all of of these to the host can // cause confusion on the remote OS side and result in broken touch gestures. int activePointerIndex = event.getActionIndex(); touchEventList.add( new TouchEventData( event.getPointerId(activePointerIndex), event.getX(activePointerIndex), event.getY(activePointerIndex), event.getSize(activePointerIndex), event.getSize(activePointerIndex), event.getOrientation(activePointerIndex), event.getPressure(activePointerIndex))); } if (!touchEventList.isEmpty()) { mInjector.sendTouchEvent(touchEventType, touchEventList.toArray(new TouchEventData[0])); } }