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.example.SmartBoard.DrawingView.java

public void onTouchLineMode(MotionEvent event) {
    int eventaction = event.getAction();

    int X = (int) event.getX();
    int Y = (int) event.getY();

    switch (eventaction) {

    case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on
        // a ball

        points = new Point[2];
        startX = X;//from  w  w w.j  av  a  2s.  co  m
        startY = Y;
        linePath.from(X, Y);
        linePath.to(X, Y);

        finished = false;
        if (points[0] == null) {
            //initialize rectangle.
            points[0] = new Point();
            points[0].x = X;
            points[0].y = Y;

            points[1] = new Point();
            points[1].x = X;
            points[1].y = Y + 30;

            for (Point pt : points) {
                colorballs.add(new ColorBall(getContext(), R.drawable.dot_drag_handle, pt));
            }

            invalidate();
        }
        break;
    case MotionEvent.ACTION_MOVE: // touch drag with the ball
        linePath.to(X, Y);
        colorballs.get(1).setX(X);
        colorballs.get(1).setY(Y);
        invalidate();
        break;

    case MotionEvent.ACTION_UP:
        // touch drop - just do things here after dropping
        linePath.to(X, Y);
        colorballs.get(1).setX(X);
        colorballs.get(1).setY(Y);
        finished = true;

        break;
    }
    // redraw the canvas
    invalidate();
    return;

}

From source file:cl.monsoon.s1next.widget.PhotoView.java

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    final int action = e.getAction();
    boolean handled = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (mQuickScaleEnabled) {
            mDownFocusX = e.getX();/*from ww  w  .j a v  a  2s .  c o m*/
            mDownFocusY = e.getY();
        }

        break;
    case MotionEvent.ACTION_UP:
        if (mQuickScaleEnabled) {
            handled = scale(e);
        }

        break;
    case MotionEvent.ACTION_MOVE:
        if (mQuickScaleEnabled && mDoubleTapOccurred) {
            final int deltaX = (int) (e.getX() - mDownFocusX);
            final int deltaY = (int) (e.getY() - mDownFocusY);
            int distance = (deltaX * deltaX) + (deltaY * deltaY);
            if (distance > sTouchSlopSquare) {
                mDoubleTapOccurred = false;
            }
        }

        break;
    }
    return handled;
}

From source file:com.example.SmartBoard.DrawingView.java

public void onTouchCircleMode(MotionEvent event) {
    int eventaction = event.getAction();

    int X = (int) event.getX();
    int Y = (int) event.getY();

    switch (eventaction) {

    case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on
        // a ball
        finished = false;/* ww w .ja v a  2s .c  o m*/
        if (points[0] == null) {
            //initialize rectangle.
            points[0] = new Point();
            points[0].x = X;
            points[0].y = Y;

            points[1] = new Point();
            points[1].x = X;
            points[1].y = Y + 30;

            points[2] = new Point();
            points[2].x = X + 30;
            points[2].y = Y + 30;

            points[3] = new Point();
            points[3].x = X + 30;
            points[3].y = Y;

            balID = 2;
            groupId = 1;
            // declare each ball with the ColorBall class
            for (Point pt : points) {
                colorballs.add(new ColorBall(getContext(), R.drawable.dot_drag_handle, pt));
            }
        }
        invalidate();
        break;

    case MotionEvent.ACTION_MOVE: // touch drag with the ball

        if (balID > -1) {
            // move the balls the same as the finger
            colorballs.get(balID).setX(X);
            colorballs.get(balID).setY(Y);

            if (groupId == 1) {
                colorballs.get(1).setX(colorballs.get(0).getX());
                colorballs.get(1).setY(colorballs.get(2).getY());
                colorballs.get(3).setX(colorballs.get(2).getX());
                colorballs.get(3).setY(colorballs.get(0).getY());
            } else {
                colorballs.get(0).setX(colorballs.get(1).getX());
                colorballs.get(0).setY(colorballs.get(3).getY());
                colorballs.get(2).setX(colorballs.get(3).getX());
                colorballs.get(2).setY(colorballs.get(1).getY());
            }

            invalidate();
        }

        break;

    case MotionEvent.ACTION_UP:
        // touch drop - just do things here after dropping
        finished = true;

        break;
    }
    // redraw the canvas
    invalidate();
    return;

}

From source file:com.juick.android.MessagesFragment.java

private boolean canStartScroll(MotionEvent event) {
    View view = JuickMessagesAdapter.findViewForCoordinates(
            (ViewGroup) getActivity().getWindow().getDecorView(), event.getX(), event.getY());
    while (view != null) {
        Object tag = view.getTag();
        if (tag instanceof String) {
            String stag = (String) tag;
            if (stag.contains("horizontal-slider")) {
                return false;
            }/*from  w w  w.  j  a va  2 s .c om*/
        }
        if (view instanceof ImageGallery) {
            return false;
        }
        if (view.getParent() instanceof View) {
            view = (View) view.getParent();
        } else {
            break;
        }
    }
    return true;
}

From source file:com.android.launcher3.folder.FolderIcon.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    // Call the superclass onTouchEvent first, because sometimes it changes the state to
    // isPressed() on an ACTION_UP
    boolean result = super.onTouchEvent(event);

    // Check for a stylus button press, if it occurs cancel any long press checks.
    if (mStylusEventHelper.onMotionEvent(event)) {
        mLongPressHelper.cancelLongPress();
        return true;
    }/*from  www .j av a2  s  .  c  om*/

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mLongPressHelper.postCheckForLongPress();
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mLongPressHelper.cancelLongPress();
        break;
    case MotionEvent.ACTION_MOVE:
        if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) {
            mLongPressHelper.cancelLongPress();
        }
        break;
    }
    return result;
}

From source file:com.android.volley.ui.PhotoView.java

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    final int action = e.getAction();
    boolean handled = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (mQuickScaleEnabled) {
            mDownFocusX = e.getX();// www . j  av  a  2s. com
            mDownFocusY = e.getY();
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mQuickScaleEnabled) {
            handled = scale(e);
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mQuickScaleEnabled && mDoubleTapOccurred) {
            final int deltaX = (int) (e.getX() - mDownFocusX);
            final int deltaY = (int) (e.getY() - mDownFocusY);
            int distance = (deltaX * deltaX) + (deltaY * deltaY);
            if (distance > sTouchSlopSquare) {
                mDoubleTapOccurred = false;
            }
        }
        break;

    }
    return handled;
}

From source file:com.example.SmartBoard.DrawingView.java

public void onTouchRectangleMode(MotionEvent event) {
    int eventaction = event.getAction();

    int X = (int) event.getX();
    int Y = (int) event.getY();

    switch (eventaction) {

    case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on
        // a ball
        finished = false;// ww w .j  a va 2s.  c  o m
        if (points[0] == null) {
            //initialize rectangle.
            points[0] = new Point();
            points[0].x = X;
            points[0].y = Y;

            points[1] = new Point();
            points[1].x = X;
            points[1].y = Y + 30;

            points[2] = new Point();
            points[2].x = X + 30;
            points[2].y = Y + 30;

            points[3] = new Point();
            points[3].x = X + 30;
            points[3].y = Y;

            balID = 2;
            groupId = 1;
            // declare each ball with the ColorBall class
            for (Point pt : points) {
                colorballs.add(new ColorBall(getContext(), R.drawable.dot_drag_handle, pt));
            }
        } else {
            //resize rectangle
            balID = -1;
            groupId = -1;
            for (int i = colorballs.size() - 1; i >= 0; i--) {
                ColorBall ball = colorballs.get(i);
                // check if inside the bounds of the ball (circle)
                // get the center for the ball
                int centerX = ball.getX() + ball.getWidthOfBall();
                int centerY = ball.getY() + ball.getHeightOfBall();

                // calculate the radius from the touch to the center of the
                // ball
                double radCircle = Math
                        .sqrt((double) (((centerX - X) * (centerX - X)) + (centerY - Y) * (centerY - Y)));

                if (radCircle < ball.getWidthOfBall()) {

                    balID = ball.getID();
                    if (balID == 1 || balID == 3) {
                        groupId = 2;
                    } else {
                        groupId = 1;
                    }
                    invalidate();
                    break;
                }
                invalidate();
            }
        }
        break;

    case MotionEvent.ACTION_MOVE: // touch drag with the ball

        if (balID > -1) {
            // move the balls the same as the finger
            colorballs.get(balID).setX(X);
            colorballs.get(balID).setY(Y);

            if (groupId == 1) {
                colorballs.get(1).setX(colorballs.get(0).getX());
                colorballs.get(1).setY(colorballs.get(2).getY());
                colorballs.get(3).setX(colorballs.get(2).getX());
                colorballs.get(3).setY(colorballs.get(0).getY());
            } else {
                colorballs.get(0).setX(colorballs.get(1).getX());
                colorballs.get(0).setY(colorballs.get(3).getY());
                colorballs.get(2).setX(colorballs.get(3).getX());
                colorballs.get(2).setY(colorballs.get(1).getY());
            }

            invalidate();
        }

        break;

    case MotionEvent.ACTION_UP:
        // touch drop - just do things here after dropping
        finished = true;

        break;
    }
    // redraw the canvas
    invalidate();
    return;

}

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    // "|" used deliberately here; both methods should be invoked.
    final boolean interceptForDrag = mDragger.shouldInterceptTouchEvent(ev);

    boolean interceptForTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        if (onScreen() > 0 && isContentView(mDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;/*from   w  w w . j  a v a 2s. c  o  m*/
        }
        mChildrenCanceledTouch = false;
        break;
    }
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mChildrenCanceledTouch = false;
    }
    }

    return interceptForDrag || interceptForTap || mChildrenCanceledTouch;
}

From source file:androidVNC.VncCanvasActivity.java

/**
 * Pan based on touch motions/*from  w  w w.jav a2s  .  c o m*/
 *
 * @param event
 */
private boolean pan(MotionEvent event) {
    float curX = event.getX();
    float curY = event.getY();
    int dX = (int) (panTouchX - curX);
    int dY = (int) (panTouchY - curY);

    return vncCanvas.pan(dX, dY);
}

From source file:com.android.dialer.widget.OverlappingPaneLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    // Preserve the open state based on the last view that was touched.
    if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) {
        // After the first things will be slideable.
        final View secondChild = getChildAt(1);
        if (secondChild != null) {
            mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY());
        }//from w  w  w. j  a  v a  2 s. co  m
    }

    if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        if (!mIsInNestedScroll) {
            mDragHelper.cancel();
        }
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        if (!mIsInNestedScroll) {
            mDragHelper.cancel();
        }
        return false;
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mIsUnableToDrag = false;
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;

        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float x = ev.getX();
        final float y = ev.getY();
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        if (ady > slop && adx > ady || !isCapturableViewUnder((int) x, (int) y)) {
            if (!mIsInNestedScroll) {
                mDragHelper.cancel();
            }
            mIsUnableToDrag = true;
            return false;
        }
    }
    }

    final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev);

    return interceptForDrag;
}