Example usage for android.support.v4.view MotionEventCompat getY

List of usage examples for android.support.v4.view MotionEventCompat getY

Introduction

In this page you can find the example usage for android.support.v4.view MotionEventCompat getY.

Prototype

public static float getY(MotionEvent event, int pointerIndex) 

Source Link

Document

Call MotionEvent#getY(int) .

Usage

From source file:cn.d.fesa.wuf.ui.view.LazyViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*/*w  w w .  ja va 2  s .co  m*/
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onMotionEvent will be called and we do the actual
     * scrolling there.
     */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        if (DEBUG)
            Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we
    // are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
         * whether the user has moved far enough from his original down touch.
         */

        /*
        * Locally do absolute value. mLastMotionY is set to the y value
        * of the down event.
        */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be handled there.
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG)
                Log.v(TAG, "Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical
                // direction to be counted as a drag...  abort
                // any attempt to drag horizontally, to work correctly
                // with children that have scrolling containers.
                if (DEBUG)
                    Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /*
         * Remember location of down touch.
         * ACTION_DOWN always refers to pointer index 0.
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG)
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /*
    * The only time we want to intercept motion events is if we are in the
    * drag mode.
    */
    return mIsBeingDragged;
}

From source file:android.support.v7.widget.helper.ItemTouchHelper.java

/**
 * Checks whether we should select a View for swiping.
 *///from  w w w.j av  a  2 s  .  c  o  m
private boolean checkSelectForSwipe(int action, MotionEvent motionEvent, int pointerIndex) {
    if (mSelected != null || action != MotionEvent.ACTION_MOVE || mActionState == ACTION_STATE_DRAG
            || !mCallback.isItemViewSwipeEnabled()) {
        return false;
    }
    if (mRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
        return false;
    }
    final ViewHolder vh = findSwipedView(motionEvent);
    if (vh == null) {
        return false;
    }
    final int movementFlags = mCallback.getAbsoluteMovementFlags(mRecyclerView, vh);

    final int swipeFlags = (movementFlags & ACTION_MODE_SWIPE_MASK) >> (DIRECTION_FLAG_COUNT
            * ACTION_STATE_SWIPE);

    if (swipeFlags == 0) {
        return false;
    }

    // mDx and mDy are only set in allowed directions. We use custom x/y here instead of
    // updateDxDy to avoid swiping if user moves more in the other direction
    final float x = MotionEventCompat.getX(motionEvent, pointerIndex);
    final float y = MotionEventCompat.getY(motionEvent, pointerIndex);

    // Calculate the distance moved
    final float dx = x - mInitialTouchX;
    final float dy = y - mInitialTouchY;
    // swipe target is chose w/o applying flags so it does not really check if swiping in that
    // direction is allowed. This why here, we use mDx mDy to check slope value again.
    final float absDx = Math.abs(dx);
    final float absDy = Math.abs(dy);

    if (absDx < mSlop && absDy < mSlop) {
        return false;
    }
    if (absDx > absDy) {
        if (dx < 0 && (swipeFlags & LEFT) == 0) {
            return false;
        }
        if (dx > 0 && (swipeFlags & RIGHT) == 0) {
            return false;
        }
    } else {
        if (dy < 0 && (swipeFlags & UP) == 0) {
            return false;
        }
        if (dy > 0 && (swipeFlags & DOWN) == 0) {
            return false;
        }
    }
    mDx = mDy = 0f;
    mActivePointerId = MotionEventCompat.getPointerId(motionEvent, 0);
    select(vh, ACTION_STATE_SWIPE);
    return true;
}

From source file:com.wevalue.view.LazyViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*/*from w ww  .ja v  a 2s . com*/
     * This method JUST determines whether we want to intercept the motion. If we return true, onMotionEvent will be called and we do the actual scrolling there.
     */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        if (DEBUG)
            Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we
    // are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check whether the user has moved far enough from his original down touch.
         */

        /*
         * Locally do absolute value. mLastMotionY is set to the y value of the down event.
         */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on
            // content.
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be
            // handled there.
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG)
                Log.v(TAG, "Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical
                // direction to be counted as a drag... abort
                // any attempt to drag horizontally, to work correctly
                // with children that have scrolling containers.
                if (DEBUG)
                    Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /*
         * Remember location of down touch. ACTION_DOWN always refers to pointer index 0.
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG)
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /*
     * The only time we want to intercept motion events is if we are in the drag mode.
     */
    return mIsBeingDragged;
}

From source file:com.example.show.NoPreloadViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /* /*from w  w  w  .j  a v  a  2 s  .  c o m*/
     * This method JUST determines whether we want to intercept the motion. 
     * If we return true, onMotionEvent will be called and we do the actual 
     * scrolling there. 
     */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.  
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.  
        if (DEBUG)
            Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we  
    // are dragging.  
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /* 
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check 
         * whether the user has moved far enough from his original down touch. 
         */

        /* 
        * Locally do absolute value. mLastMotionY is set to the y value 
        * of the down event. 
        */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.  
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be handled there.  
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG)
                Log.v(TAG, "Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical  
                // direction to be counted as a drag...  abort  
                // any attempt to drag horizontally, to work correctly  
                // with children that have scrolling containers.  
                if (DEBUG)
                    Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /* 
         * Remember location of down touch. 
         * ACTION_DOWN always refers to pointer index 0. 
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.  
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG)
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /* 
    * The only time we want to intercept motion events is if we are in the 
    * drag mode. 
    */
    return mIsBeingDragged;
}

From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /* /* www .  j  a  va  2  s  .com*/
     * This method JUST determines whether we want to intercept the motion. 
     * If we return true, onMotionEvent will be called and we do the actual 
     * scrolling there. 
     */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.  
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.  
        if (DEBUG) {
            Log.v(TAG, "Intercept done!");
        }
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we  
    // are dragging.  
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG) {
                Log.v(TAG, "Intercept returning true!");
            }
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG) {
                Log.v(TAG, "Intercept returning false!");
            }
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /* 
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check 
         * whether the user has moved far enough from his original down touch. 
         */

        /* 
        * Locally do absolute value. mLastMotionY is set to the y value 
        * of the down event. 
        */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.  
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG) {
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
        }

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be handled there.  
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG) {
                Log.v(TAG, "Starting drag!");
            }
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical  
                // direction to be counted as a drag...  abort  
                // any attempt to drag horizontally, to work correctly  
                // with children that have scrolling containers.  
                if (DEBUG) {
                    Log.v(TAG, "Starting unable to drag!");
                }
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /* 
         * Remember location of down touch. 
         * ACTION_DOWN always refers to pointer index 0. 
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.  
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG) {
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        }
        break;
    }

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

    /* 
    * The only time we want to intercept motion events is if we are in the 
    * drag mode. 
    */
    return mIsBeingDragged;
}

From source file:com.zhongsou.souyue.ui.UnScrollViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (!isCanScroll) {
        return false;
    }//  w  w  w.  j a  v a2 s  . c  om
    /*
     * This method JUST determines whether we want to intercept the motion.
    * If we return true, onMotionEvent will be called and we do the actual
    * scrolling there.
    */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        if (DEBUG)
            Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we
    // are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have
        * caught it. Check whether the user has moved far enough from his
        * original down touch.
        */

        /*
         * Locally do absolute value. mLastMotionY is set to the y value of
         * the down event.
         */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on
            // content.
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be
            // handled there.
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG)
                Log.v(TAG, "Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical
                // direction to be counted as a drag... abort
                // any attempt to drag horizontally, to work correctly
                // with children that have scrolling containers.
                if (DEBUG)
                    Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /*
         * Remember location of down touch. ACTION_DOWN always refers to
         * pointer index 0.
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG)
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /*
     * The only time we want to intercept motion events is if we are in the
     * drag mode.
     */
    return mIsBeingDragged;
}

From source file:com.kinth.mmspeed.ui.CustomViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (isScrollable == false) {
        return false;
    }// w ww  . j  av  a2 s.c  om
    /*
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onMotionEvent will be called and we do the actual
     * scrolling there.
     */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        if (DEBUG)
            Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we
    // are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
         * whether the user has moved far enough from his original down touch.
         */

        /*
        * Locally do absolute value. mLastMotionY is set to the y value
        * of the down event.
        */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be handled there.
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG)
                Log.v(TAG, "Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical
                // direction to be counted as a drag...  abort
                // any attempt to drag horizontally, to work correctly
                // with children that have scrolling containers.
                if (DEBUG)
                    Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /*
         * Remember location of down touch.
         * ACTION_DOWN always refers to pointer index 0.
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG)
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /*
    * The only time we want to intercept motion events is if we are in the
    * drag mode.
    */
    return mIsBeingDragged;
}

From source file:com.juyujuyu.SwipeLoadLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;/*from w w w.ja  va2  s . c om*/
    }

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

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

    case MotionEvent.ACTION_MOVE: {
        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 overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
        if (mIsBeingDragged) {
            //                    if (overscrollTop > 0) {
            //                        moveSpinner(overscrollTop);
            //                    } else {
            //                        return false;
            //                    }
            moveSpinner(overscrollTop);
        }
        break;
    }
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        pointerIndex = MotionEventCompat.getActionIndex(ev);
        if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_POINTER_DOWN event but have an invalid action index.");
            return false;
        }
        mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        break;
    }

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

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

        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
        mIsBeingDragged = false;
        finishSpinner(overscrollTop);
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    case MotionEvent.ACTION_CANCEL:
        return false;
    }

    return true;
}

From source file:com.bm.wjsj.View.LazyViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*//from   w  ww  .ja  v a2 s  . c  o  m
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onMotionEvent will be called and we do the actual
     * scrolling there.
     */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        if (DEBUG)
            Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we
    // are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have
         * caught it. Check whether the user has moved far enough from his
         * original down touch.
         */

        /*
         * Locally do absolute value. mLastMotionY is set to the y value of
         * the down event.
         */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on
            // content.
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be
            // handled there.
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG)
                Log.v(TAG, "Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical
                // direction to be counted as a drag... abort
                // any attempt to drag horizontally, to work correctly
                // with children that have scrolling containers.
                if (DEBUG)
                    Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /*
         * Remember location of down touch. ACTION_DOWN always refers to
         * pointer index 0.
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG)
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /*
     * The only time we want to intercept motion events is if we are in the
     * drag mode.
     */
    return mIsBeingDragged;
}

From source file:com.sno.customintegration.customhome.view.LazyViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*/*from   w  ww. ja v  a2 s .c  o  m*/
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onMotionEvent will be called and we do the actual
     * scrolling there.
     */

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        if (DEBUG)
            Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we
    // are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            if (DEBUG)
                Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have
         * caught it. Check whether the user has moved far enough from his
         * original down touch.
         */

        /*
         * Locally do absolute value. mLastMotionY is set to the y value of
         * the down event.
         */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on
            // content.
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        final int scrollX = getScrollX();
        @SuppressWarnings("unused")
        final boolean atEdge = (dx > 0 && scrollX == 0)
                || (dx < 0 && mAdapter != null && scrollX >= (mAdapter.getCount() - 1) * getWidth() - 1);
        if (DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (canScroll(this, false, (int) dx, (int) x, (int) y)) {
            // Nested view has scrollable area under this point. Let it be
            // handled there.
            mInitialMotionX = mLastMotionX = x;
            mLastMotionY = y;
            return false;
        }
        if (xDiff > mTouchSlop && xDiff > yDiff) {
            if (DEBUG)
                Log.v(TAG, "Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical
                // direction to be counted as a drag... abort
                // any attempt to drag horizontally, to work correctly
                // with children that have scrolling containers.
                if (DEBUG)
                    Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /*
         * Remember location of down touch. ACTION_DOWN always refers to
         * pointer index 0.
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        if (DEBUG)
            Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                    + "mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /*
     * The only time we want to intercept motion events is if we are in the
     * drag mode.
     */
    return mIsBeingDragged;
}