Search in sources :

Example 6 with PointerCoords

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

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

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

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)

Example 8 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project XobotOS by xamarin.

the class PointerLocationView method addPointerEvent.

public void addPointerEvent(MotionEvent event) {
    synchronized (mPointers) {
        final int action = event.getAction();
        int NP = mPointers.size();
        if (action == MotionEvent.ACTION_DOWN || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
            final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> // will be 0 for down
            MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            if (action == MotionEvent.ACTION_DOWN) {
                for (int p = 0; p < NP; p++) {
                    final PointerState ps = mPointers.get(p);
                    ps.clearTrace();
                    ps.mCurDown = false;
                }
                mCurDown = true;
                mCurNumPointers = 0;
                mMaxNumPointers = 0;
                mVelocity.clear();
            }
            mCurNumPointers += 1;
            if (mMaxNumPointers < mCurNumPointers) {
                mMaxNumPointers = mCurNumPointers;
            }
            final int id = event.getPointerId(index);
            while (NP <= id) {
                PointerState ps = new PointerState();
                mPointers.add(ps);
                NP++;
            }
            if (mActivePointerId < 0 || !mPointers.get(mActivePointerId).mCurDown) {
                mActivePointerId = id;
            }
            final PointerState ps = mPointers.get(id);
            ps.mCurDown = true;
        }
        final int NI = event.getPointerCount();
        mVelocity.addMovement(event);
        mVelocity.computeCurrentVelocity(1);
        final int N = event.getHistorySize();
        for (int historyPos = 0; historyPos < N; historyPos++) {
            for (int i = 0; i < NI; i++) {
                final int id = event.getPointerId(i);
                final PointerState ps = mCurDown ? mPointers.get(id) : null;
                final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
                event.getHistoricalPointerCoords(i, historyPos, coords);
                if (mPrintCoords) {
                    logCoords("Pointer", action, i, coords, id, event.getToolType(i), event.getButtonState());
                }
                if (ps != null) {
                    ps.addTrace(coords.x, coords.y);
                }
            }
        }
        for (int i = 0; i < NI; i++) {
            final int id = event.getPointerId(i);
            final PointerState ps = mCurDown ? mPointers.get(id) : null;
            final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
            event.getPointerCoords(i, coords);
            if (mPrintCoords) {
                logCoords("Pointer", action, i, coords, id, event.getToolType(i), event.getButtonState());
            }
            if (ps != null) {
                ps.addTrace(coords.x, coords.y);
                ps.mXVelocity = mVelocity.getXVelocity(id);
                ps.mYVelocity = mVelocity.getYVelocity(id);
                mVelocity.getEstimator(id, -1, -1, ps.mEstimator);
                ps.mToolType = event.getToolType(i);
            }
        }
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) {
            final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> // will be 0 for UP
            MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            final int id = event.getPointerId(index);
            final PointerState ps = mPointers.get(id);
            ps.mCurDown = false;
            if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
                mCurDown = false;
                mCurNumPointers = 0;
            } else {
                mCurNumPointers -= 1;
                if (mActivePointerId == id) {
                    mActivePointerId = event.getPointerId(index == 0 ? 1 : 0);
                }
                ps.addTrace(Float.NaN, Float.NaN);
            }
        }
        postInvalidate();
    }
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) Paint(android.graphics.Paint)

Example 9 with PointerCoords

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

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

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

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)

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