Search in sources :

Example 36 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by AOSPA.

the class InteractionController method performMultiPointerGesture.

/**
     * Performs a multi-touch gesture
     *
     * Takes a series of touch coordinates for at least 2 pointers. Each pointer must have
     * all of its touch steps defined in an array of {@link PointerCoords}. By having the ability
     * to specify the touch points along the path of a pointer, the caller is able to specify
     * complex gestures like circles, irregular shapes etc, where each pointer may take a
     * different path.
     *
     * To create a single point on a pointer's touch path
     * <code>
     *       PointerCoords p = new PointerCoords();
     *       p.x = stepX;
     *       p.y = stepY;
     *       p.pressure = 1;
     *       p.size = 1;
     * </code>
     * @param touches each array of {@link PointerCoords} constitute a single pointer's touch path.
     *        Multiple {@link PointerCoords} arrays constitute multiple pointers, each with its own
     *        path. Each {@link PointerCoords} in an array constitute a point on a pointer's path.
     * @return <code>true</code> if all points on all paths are injected successfully, <code>false
     *        </code>otherwise
     * @since API Level 18
     */
public boolean performMultiPointerGesture(PointerCoords[]... touches) {
    boolean ret = true;
    if (touches.length < 2) {
        throw new IllegalArgumentException("Must provide coordinates for at least 2 pointers");
    }
    // Get the pointer with the max steps to inject.
    int maxSteps = 0;
    for (int x = 0; x < touches.length; x++) maxSteps = (maxSteps < touches[x].length) ? touches[x].length : maxSteps;
    // specify the properties for each pointer as finger touch
    PointerProperties[] properties = new PointerProperties[touches.length];
    PointerCoords[] pointerCoords = new PointerCoords[touches.length];
    for (int x = 0; x < touches.length; x++) {
        PointerProperties prop = new PointerProperties();
        prop.id = x;
        prop.toolType = MotionEvent.TOOL_TYPE_FINGER;
        properties[x] = prop;
        // for each pointer set the first coordinates for touch down
        pointerCoords[x] = touches[x][0];
    }
    // Touch down all pointers
    long downTime = SystemClock.uptimeMillis();
    MotionEvent event;
    event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    ret &= injectEventSync(event);
    for (int x = 1; x < touches.length; x++) {
        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), getPointerAction(MotionEvent.ACTION_POINTER_DOWN, x), x + 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        ret &= injectEventSync(event);
    }
    // Move all pointers
    for (int i = 1; i < maxSteps - 1; i++) {
        // for each pointer
        for (int x = 0; x < touches.length; x++) {
            // check if it has coordinates to move
            if (touches[x].length > i)
                pointerCoords[x] = touches[x][i];
            else
                pointerCoords[x] = touches[x][touches[x].length - 1];
        }
        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, touches.length, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        ret &= injectEventSync(event);
        SystemClock.sleep(MOTION_EVENT_INJECTION_DELAY_MILLIS);
    }
    // For each pointer get the last coordinates
    for (int x = 0; x < touches.length; x++) pointerCoords[x] = touches[x][touches[x].length - 1];
    // touch up
    for (int x = 1; x < touches.length; x++) {
        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), getPointerAction(MotionEvent.ACTION_POINTER_UP, x), x + 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        ret &= injectEventSync(event);
    }
    Log.i(LOG_TAG, "x " + pointerCoords[0].x);
    // first to touch down is last up
    event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    ret &= injectEventSync(event);
    return ret;
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Example 37 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by AOSPA.

the class TouchExplorer method offsetEvent.

/**
     * Offsets all pointers in the given event by adding the specified X and Y
     * offsets.
     *
     * @param event The event to offset.
     * @param offsetX The X offset.
     * @param offsetY The Y offset.
     * @return An event with the offset pointers or the original event if both
     *         offsets are zero.
     */
private MotionEvent offsetEvent(MotionEvent event, int offsetX, int offsetY) {
    if (offsetX == 0 && offsetY == 0) {
        return event;
    }
    final int remappedIndex = event.findPointerIndex(mLongPressingPointerId);
    final int pointerCount = event.getPointerCount();
    PointerProperties[] props = PointerProperties.createArray(pointerCount);
    PointerCoords[] coords = PointerCoords.createArray(pointerCount);
    for (int i = 0; i < pointerCount; i++) {
        event.getPointerProperties(i, props[i]);
        event.getPointerCoords(i, coords[i]);
        if (i == remappedIndex) {
            coords[i].x += offsetX;
            coords[i].y += offsetY;
        }
    }
    return MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), event.getPointerCount(), props, coords, event.getMetaState(), event.getButtonState(), 1.0f, 1.0f, event.getDeviceId(), event.getEdgeFlags(), event.getSource(), event.getFlags());
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) Point(android.graphics.Point)

Example 38 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by AOSPA.

the class MagnificationGestureHandler method getTempPointerPropertiesWithMinSize.

private PointerProperties[] getTempPointerPropertiesWithMinSize(int size) {
    final int oldSize = (mTempPointerProperties != null) ? mTempPointerProperties.length : 0;
    if (oldSize < size) {
        PointerProperties[] oldTempPointerProperties = mTempPointerProperties;
        mTempPointerProperties = new PointerProperties[size];
        if (oldTempPointerProperties != null) {
            System.arraycopy(oldTempPointerProperties, 0, mTempPointerProperties, 0, oldSize);
        }
    }
    for (int i = oldSize; i < size; i++) {
        mTempPointerProperties[i] = new PointerProperties();
    }
    return mTempPointerProperties;
}
Also used : PointerProperties(android.view.MotionEvent.PointerProperties)

Example 39 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by ResurrectionRemix.

the class MagnificationGestureHandler method getTempPointerPropertiesWithMinSize.

private PointerProperties[] getTempPointerPropertiesWithMinSize(int size) {
    final int oldSize = (mTempPointerProperties != null) ? mTempPointerProperties.length : 0;
    if (oldSize < size) {
        PointerProperties[] oldTempPointerProperties = mTempPointerProperties;
        mTempPointerProperties = new PointerProperties[size];
        if (oldTempPointerProperties != null) {
            System.arraycopy(oldTempPointerProperties, 0, mTempPointerProperties, 0, oldSize);
        }
    }
    for (int i = oldSize; i < size; i++) {
        mTempPointerProperties[i] = new PointerProperties();
    }
    return mTempPointerProperties;
}
Also used : PointerProperties(android.view.MotionEvent.PointerProperties)

Example 40 with PointerProperties

use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by ResurrectionRemix.

the class EdgeGestureInputFilter method getTempPointerPropertiesWithMinSizeLocked.

private PointerProperties[] getTempPointerPropertiesWithMinSizeLocked(int size) {
    final int oldSize = mTempPointerProperties.length;
    if (oldSize < size) {
        PointerProperties[] oldTempPointerProperties = mTempPointerProperties;
        mTempPointerProperties = new PointerProperties[size];
        System.arraycopy(oldTempPointerProperties, 0, mTempPointerProperties, 0, oldSize);
    }
    for (int i = oldSize; i < size; i++) {
        mTempPointerProperties[i] = new PointerProperties();
    }
    return mTempPointerProperties;
}
Also used : PointerProperties(android.view.MotionEvent.PointerProperties)

Aggregations

PointerProperties (android.view.MotionEvent.PointerProperties)55 PointerCoords (android.view.MotionEvent.PointerCoords)38 Point (android.graphics.Point)22 MotionEvent (android.view.MotionEvent)19 Pair (android.util.Pair)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Test (org.junit.Test)7 Rect (android.graphics.Rect)5 DeviceProfile (com.android.launcher3.DeviceProfile)2 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)2 GesturePoint (android.gesture.GesturePoint)1 HiddenApi (org.robolectric.annotation.HiddenApi)1 Implementation (org.robolectric.annotation.Implementation)1