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() 

Source Link

Document

#getY(int) for the first pointer index (may be an arbitrary pointer identifier).

Usage

From source file:com.androidinspain.deskclock.VerticalViewPager.java

private MotionEvent flipXY(MotionEvent ev) {
    final float width = getWidth();
    final float height = getHeight();

    final float x = (ev.getY() / height) * width;
    final float y = (ev.getX() / width) * height;

    ev.setLocation(x, y);/*w w w .  j a va 2 s  .  c  o m*/

    return ev;
}

From source file:ms.sujinkim.com.test.MjpegViewGestureDetector.java

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    boolean value = false;
    try {/*from  ww w  .j  a  va 2  s  .com*/
        if (Math.abs(e1.getY() - e2.getY()) < FLING_MAX_OFF_PATH) {
            if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) {
                onFlingLeft(e1.getX() - e2.getX());
            } else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
                    && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) {
                onFlingRight(e2.getX() - e1.getX());
            }
            value = true;
        } else if (Math.abs(e1.getX() - e2.getX()) < FLING_MAX_OFF_PATH) {
            if (e1.getY() - e2.getY() > FLING_MIN_DISTANCE && Math.abs(velocityY) > FLING_VELOCITY_THRESHOLD) {
                onFlingUp(e1.getY() - e2.getY());
            } else if (e2.getY() - e1.getY() > FLING_MIN_DISTANCE
                    && Math.abs(velocityY) > FLING_VELOCITY_THRESHOLD) {
                onFlingDown(e2.getY() - e1.getY());
            }
            value = true;
        }
    } catch (Exception e) {
        /* Do nothing */
    }
    return value;
}

From source file:com.beyondar.example.CameraWithTouchEventsActivity.java

@Override
public void onTouchBeyondarView(MotionEvent event, BeyondarGLSurfaceView beyondarView) {

    float x = event.getX();
    float y = event.getY();

    ArrayList<BeyondarObject> geoObjects = new ArrayList<BeyondarObject>();

    // This method call is better to don't do it in the UI thread!
    beyondarView.getBeyondarObjectsOnScreenCoordinates(x, y, geoObjects);

    String textEvent = "";

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        textEvent = "Event type ACTION_DOWN: ";
        break;/*from   w  w  w  .  j a  v a  2 s  .  c  o m*/
    case MotionEvent.ACTION_UP:
        textEvent = "Event type ACTION_UP: ";
        break;
    case MotionEvent.ACTION_MOVE:
        textEvent = "Event type ACTION_MOVE: ";
        break;
    default:
        break;
    }

    Iterator<BeyondarObject> iterator = geoObjects.iterator();
    while (iterator.hasNext()) {
        BeyondarObject geoObject = iterator.next();
        textEvent = textEvent + " " + geoObject.getName();

    }
    mLabelText.setText("Event: " + textEvent);
}

From source file:cn.limc.androidcharts.event.SlipGestureDetector.java

private float calEventDistance(MotionEvent initalEvent, MotionEvent finalEvent) {
    float xSpan = initalEvent.getX() - finalEvent.getX();
    float ySpan = initalEvent.getY() - finalEvent.getY();
    return (float) Math.sqrt(xSpan * xSpan + ySpan * ySpan);
}

From source file:com.akingyin.librarys.widgets.XSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;//from   ww w  . j av  a 2 s  .c o  m
        xLast = ev.getX();
        yLast = ev.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        final float curX = ev.getX();
        final float curY = ev.getY();

        xDistance += Math.abs(curX - xLast);
        yDistance += Math.abs(curY - yLast);
        xLast = curX;
        yLast = curY;

        if (xDistance > yDistance) {
            return false;
        }
    }

    return super.onInterceptTouchEvent(ev);
}

From source file:com.aprz.easy_iosched.ui.widget.MultiSwipeRefreshLayout.java

/**
 * @return false if the scrolled horizontal distance is bigger than the vertical one
 *//*from w w  w. ja va  2s .  c o m*/
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mStartGestureX = event.getX();
        mStartGestureY = event.getY();
        mHorizontalScrollDetected = false;
        break;

    case MotionEvent.ACTION_MOVE:
        mHorizontalScrollDetected = Math.abs(event.getX() - mStartGestureX) > Math
                .abs(event.getY() - mStartGestureY);
        if (mHorizontalScrollDetected) {
            return false;
        }
        break;
    }

    return super.onInterceptTouchEvent(event);
}

From source file:projects.oss2015.cs.fundookid.Shoes.java

public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        x1 = touchevent.getX();//w  ww .j  a v a  2  s .  co  m
        y1 = touchevent.getY();
        break;
    }
    case MotionEvent.ACTION_UP: {
        x2 = touchevent.getX();
        y2 = touchevent.getY();

        //if left to right swipe event on screen
        if (x1 < x2) {
            if (mpCheer.isPlaying())
                mpCheer.stop();
            Intent i = new Intent(this, Colors.class);
            startActivity(i);
        }

        //if right to left swipe event on screen
        if (x1 > x2) {
            if (mpCheer.isPlaying())
                mpCheer.stop();
            Intent i = new Intent(this, Coat.class);
            startActivity(i);
        }

        break;
    }
    }
    return false;
}

From source file:com.android.deskclock.VerticalViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    try {/*from w w w  .j a  v  a2s  . com*/
        initializeParent();
        final float x = ev.getX();
        final float y = ev.getY();
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            mLastMotionX = x;
            mLastMotionY = y;
            if (!mParentViewPager.onTouchEvent(ev))
                return false;
            return verticalDrag(ev);
        }
        case MotionEvent.ACTION_MOVE: {
            final float xDiff = Math.abs(x - mLastMotionX);
            final float yDiff = Math.abs(y - mLastMotionY);
            if (!mHorizontalDrag && !mVerticalDrag) {
                if (xDiff > mTouchSlop && xDiff > yDiff) { // Swiping left and right
                    mHorizontalDrag = true;
                } else if (yDiff > mTouchSlop && yDiff > xDiff) { //Swiping up and down
                    mVerticalDrag = true;
                }
            }
            if (mHorizontalDrag) {
                return mParentViewPager.onTouchEvent(ev);
            } else if (mVerticalDrag) {
                return verticalDrag(ev);
            }
        }
        case MotionEvent.ACTION_UP: {
            if (mHorizontalDrag) {
                mHorizontalDrag = false;
                return mParentViewPager.onTouchEvent(ev);
            }
            if (mVerticalDrag) {
                mVerticalDrag = false;
                return verticalDrag(ev);
            }
        }
        }
        // Set both flags to false in case user lifted finger in the parent view pager
        mHorizontalDrag = false;
        mVerticalDrag = false;
    } catch (Exception e) {
        // The mParentViewPager shouldn't be null, but just in case. If this happens,
        // app should not crash, instead just ignore the user swipe input
        // TODO: handle the exception gracefully
    }
    return false;
}

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

private float getActiveY(MotionEvent ev) {
    try {//from ww  w  . ja  v a 2s  . com
        return MotionEventCompat.getY(ev, mActivePointerIndex);
    } catch (Exception e) {
        return ev.getY();
    }
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

/**
 * ???target View //from   w w  w.  ja  v a 2s.  c o m
 *
 * @param view
 * @param ev
 * @return
 */
public static boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getX() < x || ev.getX() > (x + view.getWidth()) || ev.getY() < y
            || ev.getY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}