Example usage for android.view MotionEvent getX

List of usage examples for android.view MotionEvent getX

Introduction

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

Prototype

public final float getX() 

Source Link

Document

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

Usage

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

/**
 * @return false if the scrolled horizontal distance is bigger than the vertical one
 *//*  ww  w  . j  a  v a  2 s . co 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:com.akingyin.librarys.widgets.XSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;/*w  ww  . j a  va2 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.awen.codebase.ui.VerticalViewPager.java

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

    float newX = (ev.getY() / height) * width;
    float newY = (ev.getX() / width) * height;

    ev.setLocation(newX, newY);//w  w w. j  a v  a2 s  . c o  m

    return ev;
}

From source file:com.android.wneng.widget.vertcalViewPager.VerticalViewPager.java

private MotionEvent swapTouchEvent(MotionEvent event) {
    float width = getWidth();
    float height = getHeight();

    float swappedX = (event.getY() / height) * width;
    float swappedY = (event.getX() / width) * height;

    event.setLocation(swappedX, swappedY);

    return 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();
        y1 = touchevent.getY();/* w  w w  . java 2  s . c o m*/
        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  ww  w  . j a  v a2  s  .  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: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);//from ww w.ja  v a 2 s  .c  o  m

    return ev;
}

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

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

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

/**
 * ???target View /*from  w w  w  .  j  a v a 2 s . 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;
}

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

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