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.aretha.slidemenu.SlideMenu.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final float x = ev.getX();
    final float y = ev.getY();
    final int currentState = mCurrentState;
    if (STATE_DRAG == currentState || STATE_SCROLL == currentState) {
        return true;
    }/*w  w w. ja va 2 s  .  c  o m*/
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mPressedX = mLastMotionX = x;
        mIsTapContent = isTapContent(x, y);
        return isOpen() && mIsTapContent;
    case MotionEvent.ACTION_MOVE:
        float distance = x - mPressedX;
        if (Math.abs(distance) >= mTouchSlop && mIsTapContent) {
            if (!canScroll(this, (int) distance, (int) x, (int) y)) {
                setCurrentState(STATE_DRAG);
                return true;
            }
        }
    }

    return super.onInterceptTouchEvent(ev);
}

From source file:com.bluepixel.android.sgpool.ui.widget.SwipeRefreshLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;//  w w w  . j a  v  a2 s .  co m
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
        // Fail fast if we're not in a state where a swipe is possible
        return false;
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        break;

    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
            return false;
        }

        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = y - mInitialMotionY;

        if (!mIsBeingDragged && yDiff > mTouchSlop) {
            mIsBeingDragged = true;
        }

        if (mIsBeingDragged) {
            // User velocity passed min velocity; trigger a refresh
            if (yDiff > mDistanceToTriggerSync) {
                // User movement passed distance; trigger a refresh
                startRefresh();
            } else {
                // Just track the user's movement
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updateContentOffsetTop((int) (yDiff));
                if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) {
                    // If the user puts the view back at the top, we
                    // don't need to. This shouldn't be considered
                    // cancelling the gesture as the user can restart from the top.
                    removeCallbacks(mCancel);
                } else {
                    updatePositionTimeout();
                }
            }
            mLastMotionY = y;
        }
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    return true;
}

From source file:com.bluepixel.android.sgpool.ui.widget.SwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();//  ww  w  . j ava 2 s .  c  o m

    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
        // Fail fast if we're not in a state where a swipe is possible
        return false;
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        break;

    case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
            Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
            return false;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
            return false;
        }

        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = y - mInitialMotionY;
        if (yDiff > mTouchSlop) {
            mLastMotionY = y;
            mIsBeingDragged = true;
        }
        break;

    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mActivePointerId = INVALID_POINTER;
        break;
    }

    return mIsBeingDragged;
}

From source file:com.aincc.libtest.activity.flip.FlipViewGroup.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int tempCurrentViewId = currentItem;
        if (event.getY() < getHeight() / 2) {
            if (tempCurrentViewId > 0) {
                tempCurrentViewId--;/*from  w  ww. ja v a2s .  co  m*/
            }
            renderer.getCards().handleTouchEventDown(true, tempCurrentViewId, getPrevPrevView());
        } else {
            if (tempCurrentViewId < adapter.getCount() - 1) {
                tempCurrentViewId++;
            }
            renderer.getCards().handleTouchEventDown(false, tempCurrentViewId, getNextNextView());
        }
    }

    return renderer.getCards().handleTouchEvent(event);
}

From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        currPercentage = 0;//ww w  .  ja  va2s.  c o m
        downEvent = MotionEvent.obtain(event);
        prevY = downEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (downEvent != null && !returningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - downEvent.getY();
            if (yDiff > touchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > distanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    handled = true;
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            accelerateInterpolator.getInterpolation(yDiff / distanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (prevY > eventY) {
                        offsetTop = yDiff - touchSlop;
                    }
                    updateContentOffsetTop((int) (offsetTop));
                    //                            if (prevY > eventY && (target.getTop() < touchSlop)) {
                    if (prevY > eventY && (circle.getTop() < touchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(cancel);
                    } else {
                        updatePositionTimeout();
                    }
                    prevY = event.getY();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (downEvent != null) {
            downEvent.recycle();
            downEvent = null;
        }
        break;
    }
    return handled;
}

From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    int actionMasked = MotionEventCompat.getActionMasked(event);
    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN:
        mDownX = event.getX();/*from  w w  w.ja v  a2  s.c o m*/
        mDisallowedParentIntercept = false;
    case MotionEvent.ACTION_MOVE:
        int x = (int) event.getX();
        if (!mDisallowedParentIntercept && Math.abs(x - mDownX) > mScaledTouchSlop) {
            getParent().requestDisallowInterceptTouchEvent(true);
            mDisallowedParentIntercept = true;
        }
        Item item = findItemByPoint(x, (int) event.getY());
        if (mTargetItem != item) {
            mTargetItem = item;
            if (item != null) {
                item.setSelected(!item.isSelected());
                ItemState state = new ItemState();
                state.item = item;
                state.isSelected = item.isSelected();
                if (mItemState == null) {
                    mItemState = state;
                } else {
                    state.next = mItemState;
                    mItemState = state;
                }
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mItemState != null) {
            ItemState state = mItemState;
            while (state != null) {
                state.item.setSelected(!state.isSelected);
                state = state.next;
            }
        }
    case MotionEvent.ACTION_UP:
        requestLayout();
        invalidate();
        mTargetItem = null;
        if (mDisallowedParentIntercept) {
            getParent().requestDisallowInterceptTouchEvent(false);
        }
        mItemState = null;
        break;
    }
    return true;
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

private void touchBegan(MotionEvent event) {
    endAnimation();/*from   w w  w .j  ava2  s. c  o  m*/

    float x = event.getX();
    mTouchStartX = x;
    mTouchStartY = event.getY();
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mStartOffset = mOffset;

    mTouchMoved = false;

    mTouchStartPos = (x / mWidth) * MOVE_POS_MULTIPLE - 5;
    mTouchStartPos /= 2;

    mVelocity = VelocityTracker.obtain();
    mVelocity.addMovement(event);
}

From source file:com.appunite.list.FastScroller.java

boolean onTouchEvent(MotionEvent me) {
    if (mState == STATE_NONE) {
        return false;
    }// ww  w  . j a  v a 2 s. c o m

    final int action = me.getAction();

    if (action == MotionEvent.ACTION_DOWN) {
        if (isPointInside(me.getX(), me.getY())) {
            if (!mList.isInScrollingContainerUnhide()) {
                beginDrag();
                return true;
            }
            mInitialTouchY = me.getY();
            startPendingDrag();
        }
    } else if (action == MotionEvent.ACTION_UP) { // don't add ACTION_CANCEL here
        if (mPendingDrag) {
            // Allow a tap to scroll.
            beginDrag();

            final int viewHeight = mList.getHeight();
            // Jitter
            int newThumbY = (int) me.getY() - mThumbH + 10;
            if (newThumbY < 0) {
                newThumbY = 0;
            } else if (newThumbY + mThumbH > viewHeight) {
                newThumbY = viewHeight - mThumbH;
            }
            mThumbY = newThumbY;
            scrollTo((float) mThumbY / (viewHeight - mThumbH));

            cancelPendingDrag();
            // Will hit the STATE_DRAGGING check below
        }
        if (mState == STATE_DRAGGING) {
            if (mList != null) {
                // ViewGroup does the right thing already, but there might
                // be other classes that don't properly reset on touch-up,
                // so do this explicitly just in case.
                mList.requestDisallowInterceptTouchEvent(false);
                mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            }
            setState(STATE_VISIBLE);
            final Handler handler = mHandler;
            handler.removeCallbacks(mScrollFade);
            if (!mAlwaysShow) {
                handler.postDelayed(mScrollFade, 1000);
            }

            mList.invalidate();
            return true;
        }
    } else if (action == MotionEvent.ACTION_MOVE) {
        if (mPendingDrag) {
            final float y = me.getY();
            if (Math.abs(y - mInitialTouchY) > mScaledTouchSlop) {
                setState(STATE_DRAGGING);
                if (mListAdapter == null && mList != null) {
                    getSectionsFromIndexer();
                }
                if (mList != null) {
                    mList.requestDisallowInterceptTouchEvent(true);
                    mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
                }

                cancelFling();
                cancelPendingDrag();
                // Will hit the STATE_DRAGGING check below
            }
        }
        if (mState == STATE_DRAGGING) {
            final int viewHeight = mList.getHeight();
            // Jitter
            int newThumbY = (int) me.getY() - mThumbH + 10;
            if (newThumbY < 0) {
                newThumbY = 0;
            } else if (newThumbY + mThumbH > viewHeight) {
                newThumbY = viewHeight - mThumbH;
            }
            if (Math.abs(mThumbY - newThumbY) < 2) {
                return true;
            }
            mThumbY = newThumbY;
            // If the previous scrollTo is still pending
            if (mScrollCompleted) {
                scrollTo((float) mThumbY / (viewHeight - mThumbH));
            }
            return true;
        }
    } else if (action == MotionEvent.ACTION_CANCEL) {
        cancelPendingDrag();
    }
    return false;
}

From source file:com.aretha.slidemenu.SlideMenu.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    final float x = event.getX();
    final float y = event.getY();
    final int currentState = mCurrentState;
    final boolean isTapContent = mIsTapContent;

    mVelocityTracker.addMovement(event);

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mPressedX = mLastMotionX = x;/* w ww  . j a v a  2s  .c  o  m*/
        mIsTapContent = isTapContent(x, y);
        if (mIsTapContent) {
            mScroller.abortAnimation();
        }
        mVelocityTracker = VelocityTracker.obtain();
        break;
    case MotionEvent.ACTION_MOVE:
        if (Math.abs(x - mPressedX) >= mTouchSlop && isTapContent && currentState != STATE_DRAG) {
            setCurrentState(STATE_DRAG);
        }
        if (STATE_DRAG != currentState) {
            mLastMotionX = x;
            return false;
        }

        drag(mLastMotionX, x);
        mLastMotionX = x;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
        if (STATE_DRAG == currentState) {
            mVelocityTracker.computeCurrentVelocity(1000);
            endDrag(x, mVelocityTracker.getXVelocity());
        } else if (isTapContent) {
            performContentClick();
        }
        mVelocityTracker.recycle();
        mIsTapContent = false;
        break;
    }

    return true;
}

From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java

private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
    final Rect bounds = mTempRect;
    mThumb.copyBounds(bounds);/*from   w  ww  .  j a va2s. com*/
    //Grow the current thumb rect for a bigger touch area
    bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));

    if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
        //If the user clicked outside the thumb, we compute the current position
        //and force an immediate drag to it.                    setProgress(mMax-1);

        mIsDragging = true;
        mDragOffset = (bounds.width() / 2) - mAddedTouchBounds;
        updateDragging(ev);
        //As the thumb may have moved, get the bounds again
        mThumb.copyBounds(bounds);
        bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    }
    if (mIsDragging) {
        setPressed(true);
        attemptClaimDrag();
        setHotspot(ev.getX(), ev.getY());
        mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
    }

    return mIsDragging;
}