Search in sources :

Example 31 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project robotium by RobotiumTech.

the class Tapper method generateTapGesture.

public void generateTapGesture(int numTaps, PointF... points) {
    MotionEvent event;
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    // pointer 1
    float x1 = points[0].x;
    float y1 = points[0].y;
    float x2 = 0;
    float y2 = 0;
    if (points.length == 2) {
        // pointer 2
        x2 = points[1].x;
        y2 = points[1].y;
    }
    PointerCoords[] pointerCoords = new PointerCoords[points.length];
    PointerCoords pc1 = new PointerCoords();
    pc1.x = x1;
    pc1.y = y1;
    pc1.pressure = 1;
    pc1.size = 1;
    pointerCoords[0] = pc1;
    PointerCoords pc2 = new PointerCoords();
    if (points.length == 2) {
        pc2.x = x2;
        pc2.y = y2;
        pc2.pressure = 1;
        pc2.size = 1;
        pointerCoords[1] = pc2;
    }
    PointerProperties[] pointerProperties = new PointerProperties[points.length];
    PointerProperties pp1 = new PointerProperties();
    pp1.id = 0;
    pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pointerProperties[0] = pp1;
    PointerProperties pp2 = new PointerProperties();
    if (points.length == 2) {
        pp2.id = 1;
        pp2.toolType = MotionEvent.TOOL_TYPE_FINGER;
        pointerProperties[1] = pp2;
    }
    int i = 0;
    while (i != numTaps) {
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, points.length, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        _instrument.sendPointerSync(event);
        if (points.length == 2) {
            event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_DOWN + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), points.length, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
            _instrument.sendPointerSync(event);
            eventTime += EVENT_TIME_INTERVAL_MS;
            event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_UP + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), points.length, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
            _instrument.sendPointerSync(event);
        }
        eventTime += EVENT_TIME_INTERVAL_MS;
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, points.length, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        _instrument.sendPointerSync(event);
        i++;
    }
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) MotionEvent(android.view.MotionEvent)

Example 32 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project platform_frameworks_base by android.

the class MagnificationGestureHandler method getTempPointerCoordsWithMinSize.

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

Example 33 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project platform_frameworks_base by android.

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 34 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project platform_frameworks_base by android.

the class TouchExplorer method onDoubleTap.

@Override
public boolean onDoubleTap(MotionEvent event, int policyFlags) {
    // Ignore the event if we aren't touch exploring.
    if (mCurrentState != STATE_TOUCH_EXPLORING) {
        return false;
    }
    // Remove pending event deliveries.
    mSendHoverEnterAndMoveDelayed.cancel();
    mSendHoverExitDelayed.cancel();
    if (mSendTouchExplorationEndDelayed.isPending()) {
        mSendTouchExplorationEndDelayed.forceSendAndRemove();
    }
    if (mSendTouchInteractionEndDelayed.isPending()) {
        mSendTouchInteractionEndDelayed.forceSendAndRemove();
    }
    final int pointerIndex = event.getActionIndex();
    final int pointerId = event.getPointerId(pointerIndex);
    Point clickLocation = mTempPoint;
    final int result = computeClickLocation(clickLocation);
    if (result == CLICK_LOCATION_NONE) {
        // consumed.
        return true;
    }
    // Do the click.
    PointerProperties[] properties = new PointerProperties[1];
    properties[0] = new PointerProperties();
    event.getPointerProperties(pointerIndex, properties[0]);
    PointerCoords[] coords = new PointerCoords[1];
    coords[0] = new PointerCoords();
    coords[0].x = clickLocation.x;
    coords[0].y = clickLocation.y;
    MotionEvent click_event = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), MotionEvent.ACTION_DOWN, 1, properties, coords, 0, 0, 1.0f, 1.0f, event.getDeviceId(), 0, event.getSource(), event.getFlags());
    final boolean targetAccessibilityFocus = (result == CLICK_LOCATION_ACCESSIBILITY_FOCUS);
    sendActionDownAndUp(click_event, policyFlags, targetAccessibilityFocus);
    click_event.recycle();
    return true;
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) Point(android.graphics.Point) PointerProperties(android.view.MotionEvent.PointerProperties) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Example 35 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project android_frameworks_base by DirtyUnicorns.

the class UiObject method performTwoPointerGesture.

/**
     * Generates a two-pointer gesture with arbitrary starting and ending points.
     *
     * @param startPoint1 start point of pointer 1
     * @param startPoint2 start point of pointer 2
     * @param endPoint1 end point of pointer 1
     * @param endPoint2 end point of pointer 2
     * @param steps the number of steps for the gesture. Steps are injected 
     * about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete.
     * @return <code>true</code> if all touch events for this gesture are injected successfully,
     *         <code>false</code> otherwise
     * @since API Level 18
     */
public boolean performTwoPointerGesture(Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps) {
    // avoid a divide by zero
    if (steps == 0)
        steps = 1;
    final float stepX1 = (endPoint1.x - startPoint1.x) / steps;
    final float stepY1 = (endPoint1.y - startPoint1.y) / steps;
    final float stepX2 = (endPoint2.x - startPoint2.x) / steps;
    final float stepY2 = (endPoint2.y - startPoint2.y) / steps;
    int eventX1, eventY1, eventX2, eventY2;
    eventX1 = startPoint1.x;
    eventY1 = startPoint1.y;
    eventX2 = startPoint2.x;
    eventY2 = startPoint2.y;
    // allocate for steps plus first down and last up
    PointerCoords[] points1 = new PointerCoords[steps + 2];
    PointerCoords[] points2 = new PointerCoords[steps + 2];
    // Include the first and last touch downs in the arrays of steps
    for (int i = 0; i < steps + 1; i++) {
        PointerCoords p1 = new PointerCoords();
        p1.x = eventX1;
        p1.y = eventY1;
        p1.pressure = 1;
        p1.size = 1;
        points1[i] = p1;
        PointerCoords p2 = new PointerCoords();
        p2.x = eventX2;
        p2.y = eventY2;
        p2.pressure = 1;
        p2.size = 1;
        points2[i] = p2;
        eventX1 += stepX1;
        eventY1 += stepY1;
        eventX2 += stepX2;
        eventY2 += stepY2;
    }
    // ending pointers coordinates
    PointerCoords p1 = new PointerCoords();
    p1.x = endPoint1.x;
    p1.y = endPoint1.y;
    p1.pressure = 1;
    p1.size = 1;
    points1[steps + 1] = p1;
    PointerCoords p2 = new PointerCoords();
    p2.x = endPoint2.x;
    p2.y = endPoint2.y;
    p2.pressure = 1;
    p2.size = 1;
    points2[steps + 1] = p2;
    return performMultiPointerGesture(points1, points2);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) Point(android.graphics.Point)

Aggregations

PointerCoords (android.view.MotionEvent.PointerCoords)46 PointerProperties (android.view.MotionEvent.PointerProperties)26 Point (android.graphics.Point)20 MotionEvent (android.view.MotionEvent)16 Paint (android.graphics.Paint)7 Rect (android.graphics.Rect)5 InputDevice (android.view.InputDevice)5 GesturePoint (android.gesture.GesturePoint)1