Example usage for android.view MotionEvent ACTION_CANCEL

List of usage examples for android.view MotionEvent ACTION_CANCEL

Introduction

In this page you can find the example usage for android.view MotionEvent ACTION_CANCEL.

Prototype

int ACTION_CANCEL

To view the source code for android.view MotionEvent ACTION_CANCEL.

Click Source Link

Document

Constant for #getActionMasked : The current gesture has been aborted.

Usage

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public boolean onTouch(View v, final MotionEvent event) {
    mGestureDetector.onTouchEvent(event);

    if (event.getPointerCount() > 1) {
        return true;
    }//from w w w  .  ja va2 s .  c o m

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mDownX = event.getX();
        mDownY = event.getY();
        isOnClick = true;
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (isOnClick) {
            swipe = false;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (isOnClick && (Math.abs(mDownX - event.getX()) > 120 || Math.abs(mDownY - event.getY()) > 120)) {
            swipe = true;
            isOnClick = false;
        }
        break;
    default:
        break;
    }

    return false;
}

From source file:com.ebaonet.lawyer.ui.weight.DraggableGridViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        // Don't handle edge touches immediately -- they may actually belong
        // to one of our
        // descendants.
        return false;
    }/*from w  w w . j  av  a2  s  .  com*/

    if (mPageCount <= 0) {
        // Nothing to present or scroll; nothing to touch.
        return false;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    final int action = ev.getAction();
    boolean needsInvalidate = false;

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        mScroller.abortAnimation();
        // Remember where the motion event started
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        DEBUG_LOG("Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                + " mIsUnableToDrag=" + mIsUnableToDrag);

        if (!mIsBeingDragged && mScrollState == SCROLL_STATE_IDLE) {
            mLastPosition = getPositionByXY((int) mLastMotionX, (int) mLastMotionY);
        } else {
            mLastPosition = -1;
        }
        if (mLastPosition >= 0) {
            mLastDownTime = System.currentTimeMillis();
        } else {
            mLastDownTime = Long.MAX_VALUE;
        }
        DEBUG_LOG("Down at mLastPosition=" + mLastPosition);
        mLastDragged = -1;
        break;
    }
    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        if (mLastDragged >= 0) {
            // change draw location of dragged visual
            final View v = getChildAt(mLastDragged);
            final int l = getScrollX() + (int) x - v.getWidth() / 2;
            final int t = getScrollY() + (int) y - v.getHeight() / 2;
            v.layout(l, t, l + v.getWidth(), t + v.getHeight());

            // check for new target hover
            if (mScrollState == SCROLL_STATE_IDLE) {
                final int target = getTargetByXY((int) x, (int) y);
                if (target != -1 && mLastTarget != target) {
                    animateGap(target);
                    mLastTarget = target;
                    DEBUG_LOG("Moved to mLastTarget=" + mLastTarget);
                }
                // edge holding
                final int edge = getEdgeByXY((int) x, (int) y);
                if (mLastEdge == -1) {
                    if (edge != mLastEdge) {
                        mLastEdge = edge;
                        mLastEdgeTime = System.currentTimeMillis();
                    }
                } else {
                    if (edge != mLastEdge) {
                        mLastEdge = -1;
                    } else {
                        if ((System.currentTimeMillis() - mLastEdgeTime) >= EDGE_HOLD_DURATION) {
                            performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                            triggerSwipe(edge);
                            mLastEdge = -1;
                        }
                    }
                }
            }
        } else if (!mIsBeingDragged) {
            final float xDiff = Math.abs(x - mLastMotionX);
            final float yDiff = Math.abs(y - mLastMotionY);
            DEBUG_LOG("Moved to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

            if (xDiff > mTouchSlop && xDiff > yDiff) {
                DEBUG_LOG("Starting drag!");
                mIsBeingDragged = true;
                requestParentDisallowInterceptTouchEvent(true);
                mLastMotionX = x - mInitialMotionX > 0 ? mInitialMotionX + mTouchSlop
                        : mInitialMotionX - mTouchSlop;
                mLastMotionY = y;
                setScrollState(SCROLL_STATE_DRAGGING);
                setScrollingCacheEnabled(true);
            }
        }
        // Not else! Note that mIsBeingDragged can be set above.
        if (mIsBeingDragged) {
            // Scroll to follow the motion event
            needsInvalidate |= performDrag(x);
        } else if (mLastPosition >= 0) {
            final int currentPosition = getPositionByXY((int) x, (int) y);
            DEBUG_LOG("Moved to currentPosition=" + currentPosition);
            if (currentPosition == mLastPosition) {
                if ((System.currentTimeMillis() - mLastDownTime) >= LONG_CLICK_DURATION) {
                    if (onItemLongClick(currentPosition)) {
                        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                        mLastDragged = mLastPosition;
                        requestParentDisallowInterceptTouchEvent(true);
                        mLastTarget = -1;
                        animateDragged();
                        mLastPosition = -1;
                    }
                    mLastDownTime = Long.MAX_VALUE;
                }
            } else {
                mLastPosition = -1;
            }
        }
        break;
    }
    case MotionEvent.ACTION_UP: {
        DEBUG_LOG("Touch up!!!");
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        if (mLastDragged >= 0) {
            rearrange();
        } else if (mIsBeingDragged) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
            final int width = getWidth();
            final int scrollX = getScrollX();
            final int currentPage = scrollX / width;
            final int offsetPixels = scrollX - currentPage * width;
            final float pageOffset = (float) offsetPixels / (float) width;
            final int totalDelta = (int) (x - mInitialMotionX);
            int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
            setCurrentItemInternal(nextPage, true, true, initialVelocity);

            mActivePointerId = INVALID_POINTER;
            endDrag();
        } else if (mLastPosition >= 0) {
            final int currentPosition = getPositionByXY((int) x, (int) y);
            DEBUG_LOG("Touch up!!! currentPosition=" + currentPosition);
            if (currentPosition == mLastPosition) {
                onItemClick(currentPosition);
            }
        }
        break;
    }
    case MotionEvent.ACTION_CANCEL:
        DEBUG_LOG("Touch cancel!!!");
        if (mLastDragged >= 0) {
            rearrange();
        } else if (mIsBeingDragged) {
            scrollToItem(mCurItem, true, 0, false);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        final float x = MotionEventCompat.getX(ev, index);
        mLastMotionX = x;
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(this);
    }
    return true;
}

From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java

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

    // "|" used deliberately here; both methods should be invoked.
    try {//from   w  w w .  ja va2s.  c  om
        final boolean interceptForDrag = isDrawerOpen(Gravity.RIGHT)
                ? mRightDragger.shouldInterceptTouchEvent(ev)
                : mLeftDragger.shouldInterceptTouchEvent(ev) | mRightDragger.shouldInterceptTouchEvent(ev);

        boolean interceptForTap = false;

        switch (action) {
        case MotionEvent.ACTION_DOWN: {
            final float x = ev.getX();
            final float y = ev.getY();
            mInitialMotionX = x;
            mInitialMotionY = y;
            if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) {
                interceptForTap = true;
            }
            mDisallowInterceptRequested = false;
            mChildrenCanceledTouch = false;
            break;
        }

        case MotionEvent.ACTION_MOVE: {
            // If we cross the touch slop, don't perform the delayed peek for an edge touch.
            if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
                mLeftCallback.removeCallbacks();
                mRightCallback.removeCallbacks();
            }
            break;
        }

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            closeDrawers(true);
            mDisallowInterceptRequested = false;
            mChildrenCanceledTouch = false;
        }
        }

        return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!isEnabled()) {
        // A disabled view that is clickable still consumes the touch
        // events, it just doesn't respond to them.
        return isClickable() || isLongClickable();
    }//from  w  w w  . j  a v  a 2s .c  o m

    initVelocityTrackerIfNotExists();
    mVelocityTracker.addMovement(ev);

    final int actionMasked = ev.getActionMasked();
    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN: {
        onTouchDown(ev);
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        onTouchMove(ev);
        break;
    }

    case MotionEvent.ACTION_UP: {
        onTouchUp(ev);
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        onTouchCancel();
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        final int x = (int) mLastTouchX;
        final int y = (int) mLastTouchY;
        final int motionPosition = pointToPosition(x, y);
        if (motionPosition >= 0) {
            // Remember where the motion event started
            final View child = getChildAt(motionPosition - mFirstPosition);
            //mMotionViewOriginalTop = child.getTop();
            mMotionPosition = motionPosition;
        }
        mTouchRemainderY = y;
        break;
    }

    case MotionEvent.ACTION_POINTER_DOWN: {
        // New pointers take over dragging duties
        final int index = ev.getActionIndex();
        final int id = ev.getPointerId(index);
        final int x = (int) ev.getX(index);
        final int y = (int) ev.getY(index);
        mMotionCorrection = 0;
        mActivePointerId = id;
        mLastTouchX = x;
        mLastTouchY = y;
        final int motionPosition = pointToPosition(x, y);
        if (motionPosition >= 0) {
            // Remember where the motion event started
            final View child = getChildAt(motionPosition - mFirstPosition);
            //mMotionViewOriginalTop = child.getTop();
            mMotionPosition = motionPosition;
        }
        mTouchRemainderY = y;
        break;
    }
    }

    return true;
}

From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    Log.i(TAG, "onTouchEvent()");
    mBottomDragger.processTouchEvent(ev);
    final int action = ev.getAction();
    boolean wantTouchEvents = true;
    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        Log.i(TAG, "onTouchEvent() -- ACTION_DOWN");
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;//from  ww w.ja v a 2s  . com
        mInitialMotionY = y;
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        Log.i(TAG, "onTouchEvent() -- ACTION_UP");
        final float x = ev.getX();
        final float y = ev.getY();
        boolean peekingOnly = true;
        final View touchedView = mBottomDragger.findTopChildUnder((int) x, (int) y);
        if (touchedView != null && isContentView(touchedView)) {
            final float dx = x - mInitialMotionX;
            final float dy = y - mInitialMotionY;
            final int slop = mBottomDragger.getTouchSlop();
            if (dx * dx + dy * dy < slop * slop) {
                // Taps close a dimmed open drawer but only if it isn't
                // locked open.
                final View openDrawer = findOpenDrawer();
                if (openDrawer != null) {
                    peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN;
                }
            }
        }
        closeDrawers(peekingOnly);
        mDisallowInterceptRequested = false;
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        Log.i(TAG, "onTouchEvent() -- ACTION_CANCEL");
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }
    }

    boolean result = wantTouchEvents;
    Log.i(TAG, "onTouchEvent() -- result = " + result);
    return result;
}

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java

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

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

    boolean interceptForTap = false;

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

    case MotionEvent.ACTION_MOVE: {
        // If we cross the touch slop, don't perform the delayed peek for an edge touch.
        if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            mLeftCallback.removeCallbacks();
            mRightCallback.removeCallbacks();
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }

    return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
}

From source file:com.android.hcframe.DraggableGridViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        // Don't handle edge touches immediately -- they may actually belong to one of our
        // descendants.
        return false;
    }//from   w  w w.  j  av  a 2 s  . c o  m

    if (mPageCount <= 0) {
        // Nothing to present or scroll; nothing to touch.
        return false;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    final int action = ev.getAction();
    boolean needsInvalidate = false;

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        mScroller.abortAnimation();
        // Remember where the motion event started
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        HcLog.D("Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                + " mIsUnableToDrag=" + mIsUnableToDrag);

        if (!mIsBeingDragged && mScrollState == SCROLL_STATE_IDLE) {
            mLastPosition = getPositionByXY((int) mLastMotionX, (int) mLastMotionY);
        } else {
            mLastPosition = -1;
        }
        if (mLastPosition >= 0) {
            mLastDownTime = System.currentTimeMillis();
        } else {
            mLastDownTime = Long.MAX_VALUE;
        }
        HcLog.D("Down at mLastPosition=" + mLastPosition);
        mLastDragged = -1;
        break;
    }
    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        if (mLastDragged >= 0) {
            // change draw location of dragged visual
            final View v = getChildAt(mLastDragged);
            final int l = getScrollX() + (int) x - v.getWidth() / 2;
            final int t = getScrollY() + (int) y - v.getHeight() / 2;
            v.layout(l, t, l + v.getWidth(), t + v.getHeight());

            // check for new target hover
            if (mScrollState == SCROLL_STATE_IDLE) {
                final int target = getTargetByXY((int) x, (int) y);
                if (target != -1 && mLastTarget != target) {
                    animateGap(target);
                    mLastTarget = target;
                    HcLog.D("Moved to mLastTarget=" + mLastTarget);
                }
                // edge holding
                final int edge = getEdgeByXY((int) x, (int) y);
                if (mLastEdge == -1) {
                    if (edge != mLastEdge) {
                        mLastEdge = edge;
                        mLastEdgeTime = System.currentTimeMillis();
                    }
                } else {
                    if (edge != mLastEdge) {
                        mLastEdge = -1;
                    } else {
                        if ((System.currentTimeMillis() - mLastEdgeTime) >= EDGE_HOLD_DURATION) {
                            performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                            triggerSwipe(edge);
                            mLastEdge = -1;
                        }
                    }
                }
            }
        } else if (!mIsBeingDragged) {
            final float xDiff = Math.abs(x - mLastMotionX);
            final float yDiff = Math.abs(y - mLastMotionY);
            HcLog.D("Moved to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

            if (xDiff > mTouchSlop && xDiff > yDiff) {
                HcLog.D("Starting drag!");
                mIsBeingDragged = true;
                requestParentDisallowInterceptTouchEvent(true);
                mLastMotionX = x - mInitialMotionX > 0 ? mInitialMotionX + mTouchSlop
                        : mInitialMotionX - mTouchSlop;
                mLastMotionY = y;
                setScrollState(SCROLL_STATE_DRAGGING);
                setScrollingCacheEnabled(true);
            }
        }
        // Not else! Note that mIsBeingDragged can be set above.
        if (mIsBeingDragged) {
            // Scroll to follow the motion event
            needsInvalidate |= performDrag(x);
        } else if (mLastPosition >= 0) {
            final int currentPosition = getPositionByXY((int) x, (int) y);
            HcLog.D("Moved to currentPosition=" + currentPosition);
            if (currentPosition == mLastPosition) {
                if ((System.currentTimeMillis() - mLastDownTime) >= LONG_CLICK_DURATION) {
                    if (onItemLongClick(currentPosition)) {
                        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                        mLastDragged = mLastPosition;
                        requestParentDisallowInterceptTouchEvent(true);
                        mLastTarget = -1;
                        animateDragged();
                        mLastPosition = -1;
                    }
                    mLastDownTime = Long.MAX_VALUE;
                }
            } else {
                mLastPosition = -1;
            }
        }
        break;
    }
    case MotionEvent.ACTION_UP: {
        HcLog.D("Touch up!!!");
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        if (mLastDragged >= 0) {
            rearrange();
        } else if (mIsBeingDragged) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
            final int width = getWidth();
            final int scrollX = getScrollX();
            final int currentPage = scrollX / width;
            final int offsetPixels = scrollX - currentPage * width;
            final float pageOffset = (float) offsetPixels / (float) width;
            final int totalDelta = (int) (x - mInitialMotionX);
            int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
            setCurrentItemInternal(nextPage, true, true, initialVelocity);

            mActivePointerId = INVALID_POINTER;
            endDrag();
        } else if (mLastPosition >= 0) {
            final int currentPosition = getPositionByXY((int) x, (int) y);
            HcLog.D("Touch up!!! currentPosition=" + currentPosition);
            if (currentPosition == mLastPosition) {
                onItemClick(currentPosition);
            }
        }
        break;
    }
    case MotionEvent.ACTION_CANCEL:
        HcLog.D("Touch cancel!!!");
        if (mLastDragged >= 0) {
            rearrange();
        } else if (mIsBeingDragged) {
            scrollToItem(mCurItem, true, 0, false);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        final float x = MotionEventCompat.getX(ev, index);
        mLastMotionX = x;
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(this);
    }
    return true;
}

From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java

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

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

    boolean interceptForTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;/*ww  w . j  a va2  s .  com*/
        mInitialMotionY = y;
        if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;
        }
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        // If we cross the touch slop, don't perform the delayed peek for an edge touch.
        if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            mLeftCallback.removeCallbacks();
            mRightCallback.removeCallbacks();
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }

    return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
}

From source file:cn.usmaker.ben.view.refresh.NeuSwipeRefreshLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;//from ww w.  j ava2s. co  m
    }

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || canChildScrollDown() || mRefreshing) {
            // Fail fast if we're not in a state where a swipe is possible
            return false;
        }
        break;
    case TOP:
    default:
        if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) {
            // Fail fast if we're not in a state where a swipe is possible
            return false;
        }
        break;
    }

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

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            float originalDragPercent = overscrollTop / mTotalDragDistance;
            if (originalDragPercent < 0) {
                return false;
            }
            float dragPercent = Math.min(1f, Math.abs(originalDragPercent));
            float adjustedPercent = (float) Math.max(dragPercent - .4, 0) * 5 / 3;
            float extraOS = Math.abs(overscrollTop) - mTotalDragDistance;
            float slingshotDist = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : mSpinnerFinalOffset;
            float tensionSlingshotPercent = Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist);
            float tensionPercent = (float) ((tensionSlingshotPercent / 4)
                    - Math.pow((tensionSlingshotPercent / 4), 2)) * 2f;
            float extraMove = (slingshotDist) * tensionPercent * 2;

            // int targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            int targetY;
            if (mDirection == NeuSwipeRefreshLayoutDirection.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = (float) (adjustedPercent * .8f);
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(rotation);
            setTargetOffsetTopAndBottom(targetY - mCurrentTargetOffsetTop, true /* requires update */);
        }
        break;
    }
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

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

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        if (mActivePointerId == INVALID_POINTER) {
            if (action == MotionEvent.ACTION_UP) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        if (!mScale) {
                            startScaleDownAnimation(null);
                        }
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mTopDragger.processTouchEvent(ev);//  w w w  .  j  a  v  a  2  s  . c o m
    mBottomDragger.processTouchEvent(ev);

    final int action = ev.getAction();
    boolean wantTouchEvents = true;

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        final float x = ev.getX();
        final float y = ev.getY();
        boolean peekingOnly = true;
        final View touchedView = mTopDragger.findTopChildUnder((int) x, (int) y);
        if (touchedView != null && isContentView(touchedView)) {
            final float dx = x - mInitialMotionX;
            final float dy = y - mInitialMotionY;
            final int slop = mTopDragger.getTouchSlop();
            if (dx * dx + dy * dy < slop * slop) {
                // Taps close a dimmed open drawer but only if it isn't locked open.
                final View openDrawer = findOpenDrawer();
                if (openDrawer != null) {
                    peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN;
                }
            }
        }
        closeDrawers(peekingOnly);
        mDisallowInterceptRequested = false;
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }
    }

    return wantTouchEvents;
}