Search in sources :

Example 41 with PointerProperties

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

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 42 with PointerProperties

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

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 43 with PointerProperties

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

the class DocumentHolderTest method createEvent.

public MotionEvent createEvent(int tooltype) {
    long time = SystemClock.uptimeMillis();
    PointerProperties[] properties = new PointerProperties[] { new PointerProperties() };
    properties[0].toolType = tooltype;
    PointerCoords[] coords = new PointerCoords[] { new PointerCoords() };
    Rect rect = new Rect();
    mHolder.itemView.getHitRect(rect);
    coords[0].x = rect.left;
    coords[0].y = rect.top;
    return MotionEvent.obtain(// down time
    time, // event time
    time, // action
    MotionEvent.ACTION_UP, // pointer count
    1, // pointer properties
    properties, // pointer coords
    coords, // metastate
    0, // button state
    0, // xprecision
    0, // yprecision
    0, // deviceid
    0, // edgeflags
    0, // source
    0, // flags
    0);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) Rect(android.graphics.Rect) PointerProperties(android.view.MotionEvent.PointerProperties)

Example 44 with PointerProperties

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

the class Rotator method generateRotateGesture.

public void generateRotateGesture(int size, PointF center1, PointF center2) {
    double incrementFactor = 0;
    float startX1 = center1.x;
    float startY1 = center1.y;
    float startX2 = center2.x;
    float startY2 = center2.y;
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    // pointer 1
    float x1 = startX1;
    float y1 = startY1;
    // pointer 2
    float x2 = startX2;
    float y2 = startY2;
    PointerCoords[] pointerCoords = new PointerCoords[2];
    PointerCoords pc1 = new PointerCoords();
    PointerCoords pc2 = new PointerCoords();
    pc1.x = x1;
    pc1.y = y1;
    pc1.pressure = 1;
    pc1.size = 1;
    pc2.x = x2;
    pc2.y = y2;
    pc2.pressure = 1;
    pc2.size = 1;
    pointerCoords[0] = pc1;
    pointerCoords[1] = pc2;
    PointerProperties[] pointerProperties = new PointerProperties[2];
    PointerProperties pp1 = new PointerProperties();
    PointerProperties pp2 = new PointerProperties();
    pp1.id = 0;
    pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pp2.id = 1;
    pp2.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pointerProperties[0] = pp1;
    pointerProperties[1] = pp2;
    MotionEvent event;
    // send the initial touches
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, pointerProperties, pointerCoords, // metaState, buttonState
    0, // metaState, buttonState
    0, // x precision
    1, // y precision
    1, // deviceId, edgeFlags
    0, // deviceId, edgeFlags
    0, InputDevice.SOURCE_TOUCHSCREEN, // source, flags
    0);
    _instrument.sendPointerSync(event);
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_DOWN + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
    switch(size) {
        case 0:
            {
                incrementFactor = 0.01;
            }
            break;
        case 1:
            {
                incrementFactor = 0.1;
            }
            break;
    }
    for (double i = 0; i < Math.PI; i += incrementFactor) {
        eventTime += EVENT_TIME_INTERVAL_MS;
        pointerCoords[0].x += Math.cos(i);
        pointerCoords[0].y += Math.sin(i);
        pointerCoords[1].x += Math.cos(i + Math.PI);
        pointerCoords[1].y += Math.sin(i + Math.PI);
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        _instrument.sendPointerSync(event);
    }
    // and remove them fingers from the screen
    eventTime += EVENT_TIME_INTERVAL_MS;
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_UP + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, 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, 1, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    _instrument.sendPointerSync(event);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) MotionEvent(android.view.MotionEvent)

Example 45 with PointerProperties

use of android.view.MotionEvent.PointerProperties 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)

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