/** * Applies all changes that were set via {@link #setMovement(int, float, float) the setMovement(...)} method. */ public void applyMovements() { int pointerCount = pointerIds.size(); PointerCoords[] coords = new PointerCoords[pointerCount]; PointerProperties[] properties = new PointerProperties[pointerCount]; int i = 0; for (Integer pointerId : pointerIds) { coords[i] = pointerPositionsMap.get(pointerId); properties[i] = pointerPropertiesMap.get(pointerId); i++; } injectMultipointMotionEvent(coords, properties); }
private void injectMultipointMotionEvent(PointerCoords[] coords, PointerProperties[] properties) { int pointerCount = coords.length; long now = SystemClock.uptimeMillis(); MotionEvent event = MotionEvent.obtain(now, now, // when the event happened MotionEvent.ACTION_MOVE, // event type pointerCount, // number of pointers properties, // pointer properties coords, // pointer coordinate descriptors DEFAULT_META_STATE, 0, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEVICE_ID, DEFAULT_EDGE_FLAGS, DEFAULT_INPUT_SOURCE, 0 // no flags ); injectMethodFacade(event); }
@CalledByNative void setPointer(int index, int x, int y, int id) { assert (0 <= index && index < MAX_NUM_POINTERS); // Convert coordinates from density independent pixels to density dependent pixels. float scaleFactor = getDisplay().getDipScale(); PointerCoords coords = new PointerCoords(); coords.x = scaleFactor * x; coords.y = scaleFactor * y; coords.pressure = 1.0f; mPointerCoords[index] = coords; PointerProperties properties = new PointerProperties(); properties.id = id; mPointerProperties[index] = properties; }
TouchPointer(int startX, int startY, int deltaX, int deltaY, int id, float scale) { mStartX = startX * scale; mStartY = startY * scale; mDeltaX = deltaX * scale; mDeltaY = deltaY * scale; if (deltaX != 0 || deltaY != 0) { mStepX = mDeltaX / Math.abs(mDeltaX + mDeltaY); mStepY = mDeltaY / Math.abs(mDeltaX + mDeltaY); } else { mStepX = 0; mStepY = 0; } mProperties = new PointerProperties(); mProperties.id = id; mProperties.toolType = MotionEvent.TOOL_TYPE_FINGER; mCoords = new PointerCoords(); mCoords.x = mStartX; mCoords.y = mStartY; mCoords.pressure = 1.0f; }
GenericTouchGesture(ContentViewCore contentViewCore, int startX0, int startY0, int deltaX0, int deltaY0, int startX1, int startY1, int deltaX1, int deltaY1) { mContentViewCore = contentViewCore; float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor(); mPointers = new TouchPointer[2]; mPointers[0] = new TouchPointer(startX0, startY0, deltaX0, deltaY0, 0, scale); mPointers[1] = new TouchPointer(startX1, startY1, deltaX1, deltaY1, 1, scale); mPointerProperties = new PointerProperties[2]; mPointerProperties[0] = mPointers[0].getProperties(); mPointerProperties[1] = mPointers[1].getProperties(); mPointerCoords = new PointerCoords[2]; mPointerCoords[0] = mPointers[0].getCoords(); mPointerCoords[1] = mPointers[1].getCoords(); }
GenericTouchGesture(ContentViewCore contentViewCore, int startX, int startY, int deltaX, int deltaY) { mContentViewCore = contentViewCore; float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor(); int scaledTouchSlop = getScaledTouchSlop(); mPointers = new TouchPointer[1]; mPointers[0] = new TouchPointer(startX, startY, deltaX, deltaY, 0, scale, scaledTouchSlop); mPointerProperties = new PointerProperties[1]; mPointerProperties[0] = mPointers[0].getProperties(); mPointerCoords = new PointerCoords[1]; mPointerCoords[0] = mPointers[0].getCoords(); }
GenericTouchGesture(ContentViewCore contentViewCore, int startX0, int startY0, int deltaX0, int deltaY0, int startX1, int startY1, int deltaX1, int deltaY1) { mContentViewCore = contentViewCore; float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor(); int scaledTouchSlop = getScaledTouchSlop(); mPointers = new TouchPointer[2]; mPointers[0] = new TouchPointer(startX0, startY0, deltaX0, deltaY0, 0, scale, scaledTouchSlop); mPointers[1] = new TouchPointer(startX1, startY1, deltaX1, deltaY1, 1, scale, scaledTouchSlop); mPointerProperties = new PointerProperties[2]; mPointerProperties[0] = mPointers[0].getProperties(); mPointerProperties[1] = mPointers[1].getProperties(); mPointerCoords = new PointerCoords[2]; mPointerCoords[0] = mPointers[0].getCoords(); mPointerCoords[1] = mPointers[1].getCoords(); }
@CalledByNative void setPointer(int index, int x, int y, int id) { assert (0 <= index && index < MAX_NUM_POINTERS); // Convert coordinates from density independent pixels to density dependent pixels. float scaleFactor = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor(); PointerCoords coords = new PointerCoords(); coords.x = scaleFactor * x; coords.y = scaleFactor * y; coords.pressure = 1.0f; mPointerCoords[index] = coords; PointerProperties properties = new PointerProperties(); properties.id = id; mPointerProperties[index] = properties; }
private void injectFingerRegisterEvent(int newPointerId) { int pointerCount = pointerIds.size(); int action = pointerCount == 1 ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_POINTER_DOWN; PointerCoords[] coords = new PointerCoords[pointerCount]; PointerProperties[] properties = new PointerProperties[pointerCount]; int i = 0; for (Integer pointerId : pointerIds) { coords[i] = pointerPositionsMap.get(pointerId); properties[i] = pointerPropertiesMap.get(pointerId); i++; } long now = SystemClock.uptimeMillis(); MotionEvent event = MotionEvent.obtain(now, now, action, pointerCount, properties, coords, DEFAULT_META_STATE, 0, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEVICE_ID, DEFAULT_EDGE_FLAGS, DEFAULT_INPUT_SOURCE, 0); if (action == MotionEvent.ACTION_POINTER_DOWN) { int newPointerIndex = event.findPointerIndex(newPointerId); event.setAction(action | (newPointerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); } injectMethodFacade(event); }
private void injectFingerUnregisterEvent(int upPointerId) { int pointerCount = pointerIds.size(); int action = pointerCount == 1 ? MotionEvent.ACTION_UP : MotionEvent.ACTION_POINTER_UP; PointerCoords[] coords = new PointerCoords[pointerCount]; PointerProperties[] properties = new PointerProperties[pointerCount]; int i = 0; for (Integer pointerId : pointerIds) { coords[i] = pointerPositionsMap.get(pointerId); properties[i] = pointerPropertiesMap.get(pointerId); if (upPointerId == pointerId) { coords[i].pressure = 0.0f; } i++; } long now = SystemClock.uptimeMillis(); MotionEvent event = MotionEvent.obtain(now, now, action, pointerCount, properties, coords, DEFAULT_META_STATE, 0, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEVICE_ID, DEFAULT_EDGE_FLAGS, DEFAULT_INPUT_SOURCE, 0); if (action == MotionEvent.ACTION_POINTER_UP) { int newPointerIndex = event.findPointerIndex(upPointerId); event.setAction(action | (newPointerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); } injectMethodFacade(event); }
private static MotionInputEventParams toMotionEventInputParams( final int actionCode, final PointerCoords coordinates, final int button, final PointerProperties properties, final long startDelta) { final MotionInputEventParams evtParams = new MotionInputEventParams(); evtParams.actionCode = actionCode; evtParams.coordinates = coordinates; evtParams.button = button; evtParams.properties = properties; evtParams.startDelta = startDelta; return evtParams; }
private static PointerProperties[] filterPointerProperties( final List<MotionInputEventParams> motionEventsParams, final boolean shouldHovering) { final List<PointerProperties> result = new ArrayList<>(); for (final MotionInputEventParams eventParams : motionEventsParams) { if (shouldHovering && HOVERING_ACTIONS.contains(eventParams.actionCode)) { result.add(eventParams.properties); } else if (!shouldHovering && !HOVERING_ACTIONS.contains(eventParams.actionCode)) { result.add(eventParams.properties); } } return result.toArray(new PointerProperties[result.size()]); }
final MotionEvent.PointerProperties c() { MotionEvent.PointerProperties localPointerProperties = new MotionEvent.PointerProperties(); localPointerProperties.toolType = 1; localPointerProperties.id = this.b; return localPointerProperties; }
GenericTouchGesture(ContentViewCore contentViewCore, int startX, int startY, int deltaX, int deltaY) { mContentViewCore = contentViewCore; float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor(); mPointers = new TouchPointer[1]; mPointers[0] = new TouchPointer(startX, startY, deltaX, deltaY, 0, scale); mPointerProperties = new PointerProperties[1]; mPointerProperties[0] = mPointers[0].getProperties(); mPointerCoords = new PointerCoords[1]; mPointerCoords[0] = mPointers[0].getCoords(); }
TouchPointer(int startX, int startY, int deltaX, int deltaY, int id, float scale, int scaledTouchSlop) { mStartX = startX * scale; mStartY = startY * scale; float scaledDeltaX = deltaX * scale; float scaledDeltaY = deltaY * scale; if (scaledDeltaX != 0 || scaledDeltaY != 0) { // The touch handler only considers a pointer as moving once // it's been moved by more than scaledTouchSlop pixels. We // thus increase the delta distance so the move is actually // registered as covering the specified distance. float distance = (float)Math.sqrt(scaledDeltaX * scaledDeltaX + scaledDeltaY * scaledDeltaY); mDeltaX = scaledDeltaX * (1 + scaledTouchSlop / distance); mDeltaY = scaledDeltaY * (1 + scaledTouchSlop / distance); } else { mDeltaX = scaledDeltaX; mDeltaY = scaledDeltaY; } if (deltaX != 0 || deltaY != 0) { mStepX = mDeltaX / Math.abs(mDeltaX + mDeltaY); mStepY = mDeltaY / Math.abs(mDeltaX + mDeltaY); } else { mStepX = 0; mStepY = 0; } mProperties = new PointerProperties(); mProperties.id = id; mProperties.toolType = MotionEvent.TOOL_TYPE_FINGER; mCoords = new PointerCoords(); mCoords.x = mStartX; mCoords.y = mStartY; mCoords.pressure = 1.0f; }
private void readEmbeddedMotionEvent(final JsonReader jsonReader, final ReplayData replayData, final int actionType) throws IOException { jsonReader.beginObject(); PointerProperties[] pointerPropertiesArray = null; while (jsonReader.hasNext()) { // pointerIds/xyt final String name = jsonReader.nextName(); if (name.equals("pointerIds")) { pointerPropertiesArray = readPointerProperties(jsonReader); } else if (name.equals("xyt")) { readPointerData(jsonReader, replayData, actionType, pointerPropertiesArray); } } jsonReader.endObject(); }
private PointerProperties[] readPointerProperties(final JsonReader jsonReader) throws IOException { final ArrayList<PointerProperties> pointerPropertiesArrayList = new ArrayList<PointerProperties>(); jsonReader.beginArray(); while (jsonReader.hasNext()) { final PointerProperties pointerProperties = new PointerProperties(); pointerProperties.id = jsonReader.nextInt(); pointerProperties.toolType = MotionEvent.TOOL_TYPE_UNKNOWN; pointerPropertiesArrayList.add(pointerProperties); } jsonReader.endArray(); return pointerPropertiesArrayList.toArray( new PointerProperties[pointerPropertiesArrayList.size()]); }
private void addMotionEventData(final ReplayData replayData, final int actionType, final long time, final PointerProperties[] pointerProperties, final PointerCoords[] pointerCoords) { replayData.mActions.add(actionType); replayData.mTimes.add(time); replayData.mPointerPropertiesArrays.add(pointerProperties); replayData.mPointerCoordsArrays.add(pointerCoords); }
public MotionEventSynthesizer(View target, WindowAndroidProvider windowProvider) { mTarget = target; mWindowProvider = windowProvider; mPointerProperties = new PointerProperties[MAX_NUM_POINTERS]; mPointerCoords = new PointerCoords[MAX_NUM_POINTERS]; }
PointerProperties getProperties() { return mProperties; }
TouchEventSynthesizer(ContentViewCore contentViewCore) { mContentViewCore = contentViewCore; mPointerProperties = new PointerProperties[MAX_NUM_POINTERS]; mPointerCoords = new PointerCoords[MAX_NUM_POINTERS]; }
private void readPointerData(final JsonReader jsonReader, final ReplayData replayData, final int actionType, final PointerProperties[] pointerPropertiesArray) throws IOException { if (pointerPropertiesArray == null) { Log.e(TAG, "PointerIDs must be given before xyt data in json for MotionEvent"); jsonReader.skipValue(); return; } long time = UNINITIALIZED_LONG; jsonReader.beginArray(); while (jsonReader.hasNext()) { // Array of historical data jsonReader.beginObject(); final ArrayList<PointerCoords> pointerCoordsArrayList = new ArrayList<PointerCoords>(); while (jsonReader.hasNext()) { // Time/data object final String name = jsonReader.nextName(); if (name.equals("t")) { time = jsonReader.nextLong(); } else if (name.equals("d")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { // array of data per pointer final PointerCoords pointerCoords = readPointerCoords(jsonReader); if (pointerCoords != null) { pointerCoordsArrayList.add(pointerCoords); } } jsonReader.endArray(); } else { jsonReader.skipValue(); } } jsonReader.endObject(); // Data was recorded as historical events, but must be split apart into // separate MotionEvents for replaying if (time != UNINITIALIZED_LONG) { addMotionEventData(replayData, actionType, time, pointerPropertiesArray, pointerCoordsArrayList.toArray( new PointerCoords[pointerCoordsArrayList.size()])); } else { Log.e(TAG, "Time not assigned in json for MotionEvent"); } } jsonReader.endArray(); }