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:com.android.audiorecorder.gallery.widget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;//from   w  ww  . j av  a  2s. c  om
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:cn.iotguard.GalleryWidget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        ////from ww  w . j av a  2  s . co  m
        if (GalleryFileActivity.ll_dibumenu != null
                && GalleryFileActivity.ll_dibumenu.getVisibility() == View.GONE) {
            GalleryFileActivity.ll_dibumenu.setVisibility(View.VISIBLE);
        }
        if (Show_bigpic2.ll_dibumenu != null && Show_bigpic2.ll_dibumenu.getVisibility() == View.GONE) {
            Show_bigpic2.ll_dibumenu.setVisibility(View.VISIBLE);
        }

        //
        if (GalleryFileActivity.timeCount != null) {
            GalleryFileActivity.timeCount.cancel();
        }
        GalleryFileActivity.timeCount = new TimeCount_pic_dibu(Millis.pic_dibus, 1000);
        GalleryFileActivity.timeCount.start();
        System.out.println("pic    ");
        if (Show_bigpic2.timeCount != null) {
            Show_bigpic2.timeCount.cancel();
        }
        Show_bigpic2.timeCount = new TimeCount_pic_dibu_showbigpic2(Millis.pic_dibus, 1000);
        Show_bigpic2.timeCount.start();

        break;
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;/*from w  w w .  j  ava  2s.c  o  m*/
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

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

/**
 * Collects pointer touch information converting from relative to absolute before
 * storing it as ending touch coordinates.
 *
 * @param event/*from ww w  .  j a  v a  2s . co m*/
 * @param view
 * @param pointerIndex
 */
private void collectEndAction(MotionEvent event, View view, int pointerIndex) {
    int offsetInScreen[] = new int[2];
    view.getLocationOnScreen(offsetInScreen);
    mPointerEvents[getPointerId(event)].endX = (int) (event.getX(pointerIndex) + offsetInScreen[0]);
    mPointerEvents[getPointerId(event)].endY = (int) (event.getY(pointerIndex) + offsetInScreen[1]);
}

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

/**
 * Collects pointer touch information converting from relative to absolute before
 * storing it as starting touch coordinates.
 *
 * @param event//from w  w w  .  j  a v a  2s  .co m
 * @param view
 * @param pointerIndex
 */
private void collectStartAction(MotionEvent event, View view, int pointerIndex) {
    int offsetInScreen[] = new int[2];
    view.getLocationOnScreen(offsetInScreen);
    mPointerEvents[getPointerId(event)].startX = (int) (event.getX(pointerIndex) + offsetInScreen[0]);
    mPointerEvents[getPointerId(event)].startY = (int) (event.getY(pointerIndex) + offsetInScreen[1]);
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Get a key that a hover event is on./*  w  w w  . j  a  v a  2s.c  o m*/
 *
 * @param event The hover event.
 * @return key The key that the <code>event</code> is on.
 */
protected final Key getHoverKeyOf(final MotionEvent event) {
    final int actionIndex = event.getActionIndex();
    final int x = (int) event.getX(actionIndex);
    final int y = (int) event.getY(actionIndex);
    return mKeyDetector.detectHitKey(x, y);
}

From source file:ch.fhnw.comgr.GLES3Activity.java

public boolean handleTouchMove(final MotionEvent event) {
    final int x0 = (int) event.getX(0);
    final int y0 = (int) event.getY(0);
    int touchCount = event.getPointerCount();
    //Log.i(TAG, "Mv:" + touchCount);

    if (touchCount == 1) {
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onMouseMove(x0, y0);
            }/*from   ww  w . j  a v a  2  s  . co  m*/
        });
    } else if (touchCount == 2) {
        final int x1 = (int) event.getX(1);
        final int y1 = (int) event.getY(1);
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onTouch2Move(x0, y0, x1, y1);
            }
        });
    }
    myView.requestRender();
    return true;
}

From source file:com.jest.phone.PhoneActivity.java

private float spacing(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return FloatMath.sqrt(x * x + y * y);
}

From source file:ch.fhnw.comgr.GLES3Activity.java

/**
 * Events://w ww. j a  v a2  s. c o  m
 * <p>
 * Finger Down
 * -----------
 * Just tap on screen -> onMouseDown, onMouseUp
 * Tap and hold       -> onMouseDown
 * release   -> onMouseUp
 * 2 Fingers same time -> onTouch2Down
 * 2 Fingers not same time -> onMouseDown, onMouseUp, onTouch2Down
 * <p>
 * Finger Up
 * ---------
 * 2 Down, release one -> onTouch2Up
 * release other one -> onMouseUp
 * 2 Down, release one, put another one down -> onTouch2Up, onTouch2Down
 * 2 Down, release both same time -> onTouch2Up
 * 2 Down, release both not same time -> onTouch2Up
 */

public boolean handleTouchDown(final MotionEvent event) {
    int touchCount = event.getPointerCount();
    final int x0 = (int) event.getX(0);
    final int y0 = (int) event.getY(0);
    //Log.i(TAG, "Dn:" + touchCount);

    // just got a new single touch
    if (touchCount == 1) {
        // get time to detect double taps
        long touchNowMS = System.currentTimeMillis();
        long touchDeltaMS = touchNowMS - lastTouchMS;
        lastTouchMS = touchNowMS;

        if (touchDeltaMS < 250)
            myView.queueEvent(new Runnable() {
                public void run() {
                    GLES3Lib.onDoubleClick(1, x0, y0);
                }
            });
        else
            myView.queueEvent(new Runnable() {
                public void run() {
                    GLES3Lib.onMouseDown(1, x0, y0);
                }
            });
    }

    // it's two fingers but one delayed (already executed mouse down
    else if (touchCount == 2 && pointersDown == 1) {
        final int x1 = (int) event.getX(1);
        final int y1 = (int) event.getY(1);
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onMouseUp(1, x0, y0);
            }
        });
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onTouch2Down(x0, y0, x1, y1);
            }
        });
        // it's two fingers at the same time
    } else if (touchCount == 2) {
        // get time to detect double taps
        long touchNowMS = System.currentTimeMillis();
        long touchDeltaMS = touchNowMS - lastTouchMS;
        lastTouchMS = touchNowMS;

        final int x1 = (int) event.getX(1);
        final int y1 = (int) event.getY(1);

        if (touchDeltaMS < 250)
            myView.queueEvent(new Runnable() {
                public void run() {
                    GLES3Lib.onMenuButton();
                }
            });
        else
            myView.queueEvent(new Runnable() {
                public void run() {
                    GLES3Lib.onTouch2Down(x0, y0, x1, y1);
                }
            });
    }
    pointersDown = touchCount;
    myView.requestRender();
    return true;
}

From source file:ch.fhnw.comgr.GLES3Activity.java

public boolean handleTouchUp(final MotionEvent event) {
    int touchCount = event.getPointerCount();
    //Log.i(TAG, "Up:" + touchCount + " x: " + (int)event.getX(0) + " y: " + (int)event.getY(0));
    final int x0 = (int) event.getX(0);
    final int y0 = (int) event.getY(0);
    if (touchCount == 1) {
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onMouseUp(1, x0, y0);
            }/*from w  w  w.j  a  v  a  2  s .co m*/
        });
    } else if (touchCount == 2) {
        final int x1 = (int) event.getX(1);
        final int y1 = (int) event.getY(1);
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onTouch2Up(x0, y0, x1, y1);
            }
        });
    }

    pointersDown = touchCount;
    myView.requestRender();
    return true;
}