Example usage for android.view MotionEvent getY

List of usage examples for android.view MotionEvent getY

Introduction

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

Prototype

public final float getY(int pointerIndex) 

Source Link

Document

Returns the Y coordinate of this event for the given pointer index (use #getPointerId(int) to find the pointer identifier for this index).

Usage

From source file:Main.java

public static float getY(MotionEvent event, int pindex) {
    return event.getY(pindex);
}

From source file:Main.java

public static void resolveMiddlePoint(PointF point, MotionEvent event) {
    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  av  a 2 s.  com
}

From source file:Main.java

/**
 * Calculate the mid point of two pointers
 *///w  w  w  .  j a  v  a  2  s .  c  om
public static void midPoint(PointF point, MotionEvent event) {
    float x = event.getX(0) + event.getX(1) + event.getX(2);
    float y = event.getY(0) + event.getY(1) + event.getY(2);
    point.set(x / 3, y / 3);
}

From source file:Main.java

public static void midpoint(MotionEvent event, PointF point) {
    float x1 = event.getX(0);
    float y1 = event.getY(0);
    float x2 = event.getX(1);
    float y2 = event.getY(1);
    midpoint(x1, y1, x2, y2, point);//ww w  . j a v  a  2s  .  c om
}

From source file:Main.java

public static float distance(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return (float) Math.sqrt(x * x + y * y);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static float distance(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    Math.sqrt(x * x + y * y);/*from  w ww. j a v a2 s . c om*/
    return (float) Math.sqrt(x * x + y * y);
}

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 ww w.  j  a v a 2  s .  co m
    }
}

From source file:Main.java

public static void inspectEvent(MotionEvent e) {
    if (e == null)
        return;//from w  w w . j  a  v  a 2s  . 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

/**
 * 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 av  a2 s .  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:com.android.view.leg.ImageDetailFragmentLeg.java

private void midPoint(PointF point, MotionEvent event) {
    float x = event.getX(0) + event.getX(1);
    float y = event.getY(0) + event.getY(1);
    point.set(x / 2, y / 2);/*www  . j a v  a2 s . c  o  m*/
}