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.android.cts.uiautomator.Test5DetailFragment.java

/**
 * Collects pointer touch information converting from relative to absolute before
 * storing it as ending touch coordinates.
 *
 * @param event/* w w w . j  ava 2 s .  co m*/
 * @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:android.support.v13.view.DragStartHelper.java

/**
 * Handle a touch event./*from   w  ww  .  jav a2s. co m*/
 * @param v The view the touch event has been dispatched to.
 * @param event The MotionEvent object containing full information about
 *        the event.
 * @return True if the listener has consumed the event, false otherwise.
 */
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
        mLastTouchX = (int) event.getX();
        mLastTouchY = (int) event.getY();
    }
    if (event.getAction() == MotionEvent.ACTION_MOVE
            && MotionEventCompat.isFromSource(event, InputDeviceCompat.SOURCE_MOUSE)
            && (MotionEventCompat.getButtonState(event) & MotionEventCompat.BUTTON_PRIMARY) != 0) {
        return mListener.onDragStart(v, this);
    }
    return false;
}

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 ww .j a  v a 2s  .c o 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]);
}

From source file:com.arthurpitman.common.SlidingPanel.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    float y = event.getY();
    int action = event.getActionMasked();
    int pointerId = event.getPointerId(event.getActionIndex());

    switch (action) {
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_DOWN:
        startTouchY = y;//  w  ww. j  a v a  2 s. c o  m
        startTouchScrollY = getScrollY();

        // if touch didn't occur on the actual control, ignore it
        float touchBoundary = viewHeight - collapsedHeight - startTouchScrollY;
        if (y < touchBoundary) {
            return false;
        }

        // start tracking velocity
        if (velocityTracker == null) {
            velocityTracker = VelocityTracker.obtain();
        } else {
            velocityTracker.clear();
        }
        velocityTracker.addMovement(event);
        break;

    case MotionEvent.ACTION_MOVE:
        // determine if a valid touch has started
        if (Math.abs(y - startTouchY) > touchSlop) {
            touchState = TOUCH_STARTED;
        }
        if (velocityTracker != null) {
            velocityTracker.addMovement(event);
        }

        // scroll as appropriate
        if (touchState == TOUCH_STARTED) {
            final int scrollDelta = (int) (startTouchY - y);
            scrollTo(0, Math.max(0, Math.min(viewHeight, startTouchScrollY + scrollDelta)));
        }
        break;

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
        if (touchState == TOUCH_STARTED) {
            final int currentScrollY = getScrollY();

            // get velocity
            float velocity = 0;
            if (velocityTracker != null) {
                velocityTracker.computeCurrentVelocity(1000);
                velocity = VelocityTrackerCompat.getYVelocity(velocityTracker, pointerId);
                velocityTracker.recycle();
                velocityTracker = null;
            }

            // snap to final scroll position
            int target = startTouchScrollY;
            if ((Math.abs(velocity) > minimumflingVelocity) || (Math.abs(y - startTouchY) > (viewHeight / 2))) {
                if (velocity < 0) {
                    target = viewHeight;
                } else {
                    target = 0;
                }
            }
            scroller.startScroll(0, currentScrollY, 0, target - currentScrollY);
            invalidate();
            touchState = TOUCH_NONE;
        }
        break;
    }
    return true;
}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

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

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mNotInitialized)
            touchStart(x, y);/* www . j  a  v  a2s .  c o  m*/
        break;

    case MotionEvent.ACTION_MOVE:
        if (!mNotInitialized) {
            touchMove(x, y);
            postInvalidate();
        }
        break;

    case MotionEvent.ACTION_UP:
        int posX = getWidth() - mClearImageSize - mClearBuff;
        //Log.d(Constants.TAG, "x: " + event.getX() + " y: " + event.getY() + " posX: " + posX + " posY: " + mClearBuff);
        if (event.getX() > posX && event.getY() < mClearImageSize + mClearBuff) {
            onClearSign();
        } else if (!mNotInitialized) {
            touchUp();
            invalidate();
        }
        break;

    default:
        break;
    }

    return true;
}

From source file:com.blogspot.holbohistorier.readonfree.BookView.java

protected void swipePage(View v, MotionEvent event, int book) {
    int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
    case (MotionEvent.ACTION_DOWN):
        swipeOriginX = event.getX();//from   w ww  .ja v a 2  s  .  c o m
        swipeOriginY = event.getY();
        break;

    case (MotionEvent.ACTION_UP):
        int quarterWidth = (int) (screenWidth * 0.25);
        float diffX = swipeOriginX - event.getX();
        float diffY = swipeOriginY - event.getY();
        float absDiffX = Math.abs(diffX);
        float absDiffY = Math.abs(diffY);

        if ((diffX > quarterWidth) && (absDiffX > absDiffY)) {
            try {
                navigator.goToNextChapter(index);
            } catch (Exception e) {
                errorMessage(getString(R.string.error_cannotTurnPage));
            }
        } else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) {
            try {
                navigator.goToPrevChapter(index);
            } catch (Exception e) {
                errorMessage(getString(R.string.error_cannotTurnPage));
            }
        }
        break;
    }

}

From source file:com.android.hareime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Receives hover events when accessibility is turned on in SDK versions ICS
 * and higher.//  www  .j  a  v a  2  s.c o m
 *
 * @param event The hover event.
 * @return {@code true} if the event is handled
 */
public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final Key key = tracker.getKeyOn(x, y);
    final Key previousKey = mLastHoverKey;

    mLastHoverKey = key;

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_EXIT:
        // Make sure we're not getting an EXIT event because the user slid
        // off the keyboard area, then force a key press.
        if (pointInView(x, y) && (key != null)) {
            getAccessibilityNodeProvider().simulateKeyPress(key);
        }
        //$FALL-THROUGH$
    case MotionEvent.ACTION_HOVER_ENTER:
        return onHoverKey(key, event);
    case MotionEvent.ACTION_HOVER_MOVE:
        if (key != previousKey) {
            return onTransitionKey(key, previousKey, event);
        } else {
            return onHoverKey(key, event);
        }
    }

    return false;
}

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

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }//from  w  w w . j  a  va2s . c  om
        } else {
            super.onInterceptTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

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

@Override
public boolean onTouchEvent(MotionEvent event) {

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }//  ww  w  .  j a v a2 s.  c  o  m
            //launchFullPhotoActivity(imageUrls);// WE HAVE A CLICK!!
        } else {
            super.onTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    /*if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP)
    {
    super.onTouchEvent(event);
    }*/

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onTouchEvent(event);
        }
    }

    return false;
}

From source file:adapters.PagerContainer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    //We capture any touches not already handled by the ViewPager
    // to implement scrolling from a touch outside the pager bounds.
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mInitialTouch.x = (int) ev.getX();
        mInitialTouch.y = (int) ev.getY();
    default:/*from w w  w  .  j a v  a2  s. c om*/
        ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y);
        break;
    }

    return mPager.dispatchTouchEvent(ev);
}