Example usage for android.view MotionEvent getPointerId

List of usage examples for android.view MotionEvent getPointerId

Introduction

In this page you can find the example usage for android.view MotionEvent getPointerId.

Prototype

public final int getPointerId(int pointerIndex) 

Source Link

Document

Return the pointer identifier associated with a particular pointer data index in this event.

Usage

From source file:Main.java

private static int[] getPointerIds(MotionEvent e) {
    int n = e.getPointerCount();
    int[] r = new int[n];
    for (int i = 0; i < n; i++) {
        r[i] = e.getPointerId(i);
    }//from w  ww . j  ava  2 s  .c o m
    return r;
}

From source file:Main.java

private static int[] getPointerIds(final MotionEvent e) {
    final int n = e.getPointerCount();
    final int[] r = new int[n];
    for (int i = 0; i < n; i++) {
        r[i] = e.getPointerId(i);
    }//from ww  w  .  ja va2  s .com
    return r;
}

From source file:Main.java

private static int[] getPointerIds(final MotionEvent motionEvent) {
    final int pointerCount = motionEvent.getPointerCount();
    final int[] array = new int[pointerCount];
    for (int i = 0; i < pointerCount; ++i) {
        array[i] = motionEvent.getPointerId(i);
    }//from  w w w. ja v a  2 s .  co m
    return array;
}

From source file:Main.java

/**
 * Computes a Camera.Area corresponding to the new focus area to focus the camera on. This is
 * done by deriving a square around the center of a MotionEvent pointer (with side length equal
 * to FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH), then transforming this rectangle's/square's
 * coordinates into the (-1000, 1000) coordinate system used for camera focus areas.
 *
 * Also note that we operate on RectF instances for the most part, to avoid any integer
 * division rounding errors going forward. We only round at the very end for playing into
 * the final focus areas list./*  w w  w.j a va  2s.c  o  m*/
 *
 * @throws RuntimeException if unable to compute valid intersection between MotionEvent region
 * and SurfaceTexture region.
 */
protected static Camera.Area computeFocusAreaFromMotionEvent(final MotionEvent event,
        final int surfaceTextureWidth, final int surfaceTextureHeight) {
    // Get position of first touch pointer.
    final int pointerId = event.getPointerId(0);
    final int pointerIndex = event.findPointerIndex(pointerId);
    final float centerX = event.getX(pointerIndex);
    final float centerY = event.getY(pointerIndex);

    // Build event rect. Note that coordinates increase right and down, such that left <= right
    // and top <= bottom.
    final RectF eventRect = new RectF(centerX - FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH, // left
            centerY - FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH, // top
            centerX + FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH, // right
            centerY + FOCUS_AREA_MOTION_EVENT_EDGE_LENGTH // bottom
    );

    // Intersect this rect with the rect corresponding to the full area of the parent surface
    // texture, making sure we are not placing any amount of the eventRect outside the parent
    // surface's area.
    final RectF surfaceTextureRect = new RectF((float) 0, // left
            (float) 0, // top
            (float) surfaceTextureWidth, // right
            (float) surfaceTextureHeight // bottom
    );
    final boolean intersectSuccess = eventRect.intersect(surfaceTextureRect);
    if (!intersectSuccess) {
        throw new RuntimeException("MotionEvent rect does not intersect with SurfaceTexture rect; unable to "
                + "compute focus area");
    }

    // Transform into (-1000, 1000) focus area coordinate system. See
    // https://developer.android.com/reference/android/hardware/Camera.Area.html.
    // Note that if this is ever changed to a Rect instead of RectF, be cautious of integer
    // division rounding!
    final RectF focusAreaRect = new RectF((eventRect.left / surfaceTextureWidth) * 2000 - 1000, // left
            (eventRect.top / surfaceTextureHeight) * 2000 - 1000, // top
            (eventRect.right / surfaceTextureWidth) * 2000 - 1000, // right
            (eventRect.bottom / surfaceTextureHeight) * 2000 - 1000 // bottom
    );
    Rect focusAreaRectRounded = new Rect();
    focusAreaRect.round(focusAreaRectRounded);
    return new Camera.Area(focusAreaRectRounded, FOCUS_AREA_WEIGHT);
}

From source file:Main.java

public static void inspectEvent(MotionEvent e) {
    if (e == null)
        return;/*from w  ww. jav a2s . c o  m*/

    final int pointerCount = e.getPointerCount();

    Log.d(TAG, "Input: event time: " + e.getEventTime());
    for (int p = 0; p < pointerCount; p++) {
        Log.d(TAG, "Input:  pointer:" + e.getPointerId(p) + " x:" + e.getX(p) + " y:" + e.getY(p) + " action:"
                + e.getAction());
    }
}

From source file:Main.java

public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev, VelocityTracker tracker) {

    // Check the dot product of current velocities.
    // If the pointer that left was opposing another velocity vector, clear.
    tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
    final int upIndex = ev.getActionIndex();
    final int id1 = ev.getPointerId(upIndex);
    final float x1 = tracker.getXVelocity(id1);
    final float y1 = tracker.getYVelocity(id1);
    for (int i = 0, count = ev.getPointerCount(); i < count; i++) {
        if (i == upIndex)
            continue;

        final int id2 = ev.getPointerId(i);
        final float x = x1 * tracker.getXVelocity(id2);
        final float y = y1 * tracker.getYVelocity(id2);

        final float dot = x + y;
        if (dot < 0) {
            tracker.clear();/* www.j av  a 2 s.c  om*/
            break;
        }
    }
}

From source file:com.android.cts.uiautomator.TestGenericDetailFragment.java

private int getPointerId(MotionEvent event) {
    return event.getPointerId(getPointerIndex(event));
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private void onTouchActivePointer(int action, MotionEvent ev) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = ev.getPointerId(0);
        break;//  www . j a  v  a 2 s .  c  o  m
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mActivePointerId = INVALID_POINTER_ID;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
            mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
            mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
        }

        break;
    }

    mActivePointerIndex = MotionEventCompat.findPointerIndex(ev,
            mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}

From source file:me.wizos.loread.view.webview.NestedScrollWebView.java

private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = ev.getActionIndex();
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionY = (int) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }//from   www  . j  a  v a2  s  .  co  m
}

From source file:org.skia.viewer.ViewerActivity.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    int count = event.getPointerCount();
    for (int i = 0; i < count; i++) {
        final float x = event.getX(i);
        final float y = event.getY(i);
        final int owner = event.getPointerId(i);
        int action = event.getAction() & MotionEvent.ACTION_MASK;
        onTouched(mApplication.getNativeHandle(), owner, action, x, y);
    }//from ww w. ja v a 2  s.c  om
    return true;
}