Example usage for android.view MotionEvent getPointerCount

List of usage examples for android.view MotionEvent getPointerCount

Introduction

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

Prototype

public final int getPointerCount() 

Source Link

Document

The number of pointers of data contained in this event.

Usage

From source file:Main.java

static void midPointOfEvent(PointF point, MotionEvent event) {
    if (event.getPointerCount() == 2) {
        float x = event.getX(0) + event.getX(1);
        float y = event.getY(0) + event.getY(1);
        point.set(x / 2, y / 2);//from   w  w  w .j a  v a  2 s .co m
    }
}

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);/*ww w  .  ja  va 2 s  .  co m*/
    }
    return r;
}

From source file:Main.java

public static boolean isMultiTouch(MotionEvent motionEvent) {
    return 1 < motionEvent.getPointerCount();
}

From source file:Main.java

private static PointerCoords[] getPointerCoords(MotionEvent e) {
    int n = e.getPointerCount();
    PointerCoords[] r = new PointerCoords[n];
    for (int i = 0; i < n; i++) {
        r[i] = new PointerCoords();
        e.getPointerCoords(i, r[i]);//w w w . j a  v  a 2  s  .c om
    }
    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  .jav a2s. c  o  m
    }
    return r;
}

From source file:Main.java

private static PointerCoords[] getPointerCoords(final MotionEvent e) {
    final int n = e.getPointerCount();
    final PointerCoords[] r = new PointerCoords[n];
    for (int i = 0; i < n; i++) {
        r[i] = new PointerCoords();
        e.getPointerCoords(i, r[i]);//www .  j  ava2  s.  c  om
    }
    return r;
}

From source file:Main.java

private static MotionEvent.PointerCoords[] getPointerCoords(final MotionEvent motionEvent) {
    final int pointerCount = motionEvent.getPointerCount();
    final MotionEvent.PointerCoords[] array = new MotionEvent.PointerCoords[pointerCount];
    for (int i = 0; i < pointerCount; ++i) {
        motionEvent.getPointerCoords(i, array[i] = new MotionEvent.PointerCoords());
    }/*from  www.ja  va2s  . c o  m*/
    return array;
}

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 . j  av  a 2 s. c o  m*/
    return array;
}

From source file:Main.java

public static void inspectEvent(MotionEvent e) {
    if (e == null)
        return;/*from   ww w  .j  av a2  s .  co 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

private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();

    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount; i++) {
        xy[2 * i] = pointerCoords[i].x;/* w w w  .j ava 2  s. co  m*/
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount; i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation);
    }

    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords,
            metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags);

    return n;
}