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:Main.java

public static boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);/*from ww  w  .  ja  va  2  s  .co m*/
    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:Main.java

/**
 * get coordinate in parent's coordinate system
 * //from   ww w. j a va  2  s  .  c om
 * @param view target view
 * @param location an array of two integers in which to hold the coordinates
 */
public static void getCoordinateInParent(View view, MotionEvent event, int[] location) {
    if (view == null || event == null || view.getParent() == null || location.length < 2) {
        return;
    }
    int parentLocation[] = new int[2];
    ((View) view.getParent()).getLocationOnScreen(parentLocation);
    if (parentLocation != null && parentLocation.length > 1) {
        location[0] = (int) event.getX() - parentLocation[0];
        location[1] = (int) event.getY() - parentLocation[1];
    }
}

From source file:Main.java

public static MotionEvent hoverMotionEventAtPosition(View view, int action, int xPercent, int yPercent) {
    MotionEvent ev = motionEventAtPosition(view, action, xPercent, yPercent);

    MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1];
    pointerProperties[0] = new MotionEvent.PointerProperties();

    MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
    pointerCoords[0] = new MotionEvent.PointerCoords();
    pointerCoords[0].x = ev.getX();//from   ww  w.  j  a  v a  2s .  com
    pointerCoords[0].y = ev.getY();

    return MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), 1, pointerProperties,
            pointerCoords, ev.getMetaState(), 0, ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(),
            ev.getEdgeFlags(), InputDevice.SOURCE_CLASS_POINTER, ev.getFlags());
}

From source file:Main.java

public static void addTouchFeedback(final ImageView view) {
    view.setOnTouchListener(new View.OnTouchListener() {
        private Rect rect;

        @Override/*www .  j  a  va  2s .  c  om*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                view.setColorFilter(Color.argb(50, 0, 0, 0));
                rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                view.setColorFilter(Color.argb(0, 0, 0, 0));
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())) {
                    view.setColorFilter(Color.argb(0, 0, 0, 0));
                }
            }
            return false;
        }
    });
}

From source file:Main.java

public static void handleAutoCloseKeyboard(boolean isAutoCloseKeyboard, View currentFocusView,
        MotionEvent motionEvent, Object dialogOrActivity) {
    if (isAutoCloseKeyboard && motionEvent.getAction() == MotionEvent.ACTION_DOWN && currentFocusView != null
            && (currentFocusView instanceof EditText) && dialogOrActivity != null) {
        int[] leftTop = { 0, 0 };
        currentFocusView.getLocationInWindow(leftTop);
        int left = leftTop[0];
        int top = leftTop[1];
        int bottom = top + currentFocusView.getHeight();
        int right = left + currentFocusView.getWidth();
        if (!(motionEvent.getX() > left && motionEvent.getX() < right && motionEvent.getY() > top
                && motionEvent.getY() < bottom)) {
            if (dialogOrActivity instanceof Dialog) {
                closeKeyboard((Dialog) dialogOrActivity);
            } else if (dialogOrActivity instanceof Activity) {
                closeKeyboard((Activity) dialogOrActivity);
            }//from www .  j  a va2s  . c om
        }
    }
}

From source file:android.support.test.testapp.VerticalViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    event.setLocation(event.getY() * getWidth() / getHeight(), event.getX() * getHeight() / getWidth());
    return super.onTouchEvent(event);
}

From source file:com.bjgas.common.DirectionalViewPager.java

/**
 * Swaps the X and Y coordinates of your touch event
 */// w  ww  .  j av a  2s .  co  m
@Override
public boolean onTouchEvent(MotionEvent ev) {
    // swap the x and y coords of the touch event
    ev.setLocation(ev.getY(), ev.getX());

    return super.onTouchEvent(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: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 av a  2s . co  m

    return ev;
}

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

private boolean verticalDrag(MotionEvent ev) {
    final float x = ev.getX();
    final float y = ev.getY();
    ev.setLocation(y, x);/*from w  w  w.j  ava2s  .c  o m*/
    return super.onTouchEvent(ev);
}