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:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

@Override
public boolean onTouch(@Nullable final View view, @NonNull final MotionEvent event) {
    if (mListViewWrapper.getAdapter() == null) {
        return false;
    }//from  ww  w .  j  a v  a 2s. com

    if (mVirtualListCount == -1 || mActiveSwipeCount == 0) {
        mVirtualListCount = mListViewWrapper.getCount() - mListViewWrapper.getHeaderViewsCount();
    }

    if (mViewWidth < 2) {
        mViewWidth = mListViewWrapper.getListView().getWidth();
    }

    boolean result;

    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
        result = handleDownEvent(view, event);
        break;
    case MotionEvent.ACTION_MOVE:
        result = handleMoveEvent(view, event);
        break;
    case MotionEvent.ACTION_CANCEL:
        result = handleCancelEvent();
        break;
    case MotionEvent.ACTION_UP:
        result = handleUpEvent(event);
        break;
    default:
        result = false;
    }

    return result;
}

From source file:com.spoiledmilk.ibikecph.map.MapActivity.java

protected boolean onImgSwiperTouch(View view, MotionEvent event) {
    if (leftContainer.getVisibility() != View.VISIBLE) {
        leftContainer.setVisibility(View.VISIBLE);
    }//  www .j av  a  2s .co  m
    if (mapDisabledView.getVisibility() != View.VISIBLE) {
        mapDisabledView.setVisibility(View.VISIBLE);
    }
    switch (event.getAction()) {
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        view.setPressed(false);
        if (moveCount <= 3)
            translate(slidden ? -maxSlide : maxSlide, true);
        else
            translate(0, true);
        break;
    case MotionEvent.ACTION_DOWN:
        moveCount = 0;
        view.setPressed(true);
        touchX = event.getX();
        break;
    case MotionEvent.ACTION_MOVE:
        if (moveCount++ < 3)
            break;
        newTouchX = event.getX();
        delta = newTouchX - touchX;
        translate(delta, false);
        touchX = newTouchX;
        break;
    }

    if (slidden && mapDisabledView.getVisibility() != View.GONE) {
        mapDisabledView.setVisibility(View.GONE);
    }

    return true;
}

From source file:com.chauthai.overscroll.BouncyAdapter.java

private void initTouchListener() {
    mRecyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
        @Override//from www.j  av  a  2 s  .  com
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
            switch (e.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mPrevTime = SystemClock.elapsedRealtime();
                mShouldUseSpring = false;

                mSpringScroller.stopScroll();
                mIsScrollBack = false;
                rv.stopScroll();
                break;

            case MotionEvent.ACTION_MOVE:
                break;

            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                onActionUp();
                break;
            }

            mGestureOnIntercept = true;
            mGestureDetector.onTouchEvent(e);

            // return true so that RecyclerView won't scroll when the user scroll.
            // We scroll it using scrollBy().
            return shouldInterceptTouch();
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
            mGestureOnIntercept = false;
            mGestureDetector.onTouchEvent(e);

            switch (e.getAction()) {
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mGestureOnIntercept = true;
                onActionUp();
                break;
            }
        }
    });
}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent e) {
    if (e.getEventTime() < mResumeTime) {
        if (MediaPhone.DEBUG) {
            Log.d(DebugUtilities.getLogTag(this),
                    "Discarded touch event with start time earlier than onResume()");
        }//from  w  w  w .  ja  v a  2s. co  m
        return true;
    }

    if (mGestureDetector != null) {
        if (mGestureDetector.onTouchEvent(e)) {
            e.setAction(MotionEvent.ACTION_CANCEL); // swipe detected - don't do the normal event
        }
    }

    try {
        return super.dispatchTouchEvent(e);
    } catch (NullPointerException ex) {
        if (MediaPhone.DEBUG) {
            Log.d(DebugUtilities.getLogTag(this),
                    "Catching touch event Null Pointer Exception; ignoring touch");
        }
        return true; // reported on Play Store - see: http://stackoverflow.com/a/13031529/1993220
    }
}

From source file:am.widget.tabstrip.TabStripHelper.java

boolean onTouchEvent(MotionEvent event) {
    if (mClickable) {
        final float x = event.getX();
        final float y = event.getY();
        final int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mClickPosition = PagerAdapter.POSITION_NONE;
            mDownX = x;// w ww  . j ava2  s . co  m
            mDownY = y;
            break;
        case MotionEvent.ACTION_UP:
            mClickPosition = PagerAdapter.POSITION_NONE;
            if (mPager != null && getPageCount() > 0) {
                if (mView instanceof TabStripView)
                    mClickPosition = ((TabStripView) mView).getClickedPosition(mDownX, mDownY, x, y);
                else if (mView instanceof TabStripViewGroup)
                    mClickPosition = ((TabStripViewGroup) mView).getClickedPosition(mDownX, mDownY, x, y);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            mClickPosition = PagerAdapter.POSITION_NONE;
            break;
        }
    }
    if (mDoubleClickable) {
        final float x = event.getX();
        final float y = event.getY();
        final int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mFirstDownX = mSecondDownX;
            mFirstDownY = mSecondDownY;
            mSecondDownX = x;
            mSecondDownY = y;
            break;
        case MotionEvent.ACTION_UP:
            final long downTime = event.getDownTime();
            if (mLastUpTime != 0 && downTime - mLastUpTime < DOUBLE_TAP_TIMEOUT) {
                mDoubleClicked = true;
                if (mView instanceof TabStripView)
                    mFirstPosition = ((TabStripView) mView).getClickedPosition(mFirstDownX, mFirstDownY,
                            mFirstUpX, mFirstUpY);
                else if (mView instanceof TabStripViewGroup)
                    mFirstPosition = ((TabStripViewGroup) mView).getClickedPosition(mFirstDownX, mFirstDownY,
                            mFirstUpX, mFirstUpY);
                if (mView instanceof TabStripView)
                    mSecondPosition = ((TabStripView) mView).getClickedPosition(mSecondDownX, mSecondDownY, x,
                            y);
                else if (mView instanceof TabStripViewGroup)
                    mSecondPosition = ((TabStripViewGroup) mView).getClickedPosition(mSecondDownX, mSecondDownY,
                            x, y);
                mLastUpTime = 0;
            } else {
                mDoubleClicked = false;
                mFirstPosition = PagerAdapter.POSITION_NONE;
                mSecondPosition = PagerAdapter.POSITION_NONE;
                mFirstUpX = x;
                mFirstUpY = y;
                mLastUpTime = event.getEventTime();
            }
            break;
        case MotionEvent.ACTION_CANCEL:

            break;
        }
    }

    return false;
}

From source file:com.bolaa.medical.view.banner.CirclePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }//from   ww  w  .j  ava  2 s  .  co  m
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            if (!mViewPager.isFakeDragging()) {
                mViewPager.beginFakeDrag();
            }

            mLastMotionX = x;

            // tyl ?beginFakeDrag()false,pagermFakeDragging???,
            // ?isFakeDragging()?false??fakeDragBy()
            if (mViewPager != null && mViewPager.isFakeDragging()) {
                try {
                    mViewPager.fakeDragBy(deltaX);
                } catch (NullPointerException e) {
                    LogUtil.w(e);
                    return true;
                }
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                mViewPager.setCurrentItem(mCurrentPage - 1);
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                mViewPager.setCurrentItem(mCurrentPage + 1);
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager != null && mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        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:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

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. jav a2  s.  co 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:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java

@CallSuper
public void disableTouchesTillFingersAreUp() {
    mKeyPressTimingHandler.cancelAllMessages();
    mKeyPreviewsManager.cancelAllPreviews();

    for (int trackerIndex = 0, trackersCount = mPointerTrackers
            .size(); trackerIndex < trackersCount; trackerIndex++) {
        PointerTracker tracker = mPointerTrackers.valueAt(trackerIndex);
        sendOnXEvent(MotionEvent.ACTION_CANCEL, 0, 0, 0, tracker);
        tracker.setAlreadyProcessed();/*from www.  j  a  va2s  .c  om*/
    }

    mTouchesAreDisabledTillLastFingerIsUp = true;
}

From source file:com.cssweb.android.view.FTrendView.java

/**
 * true?,false??//w w w. jav a 2s.  c om
 */
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        touchesBegan(event);
        break;

    case MotionEvent.ACTION_MOVE:
        touchesMoved(event);
        break;

    case MotionEvent.ACTION_UP:
        touchesEnded(event);
        break;

    case MotionEvent.ACTION_CANCEL:
        break;
    }
    return true;
}

From source file:co.vn.e_alarm.customwiget.SlidingLayer.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled) {
        return false;
    }//  w  w  w . j av  a 2 s  .  c  om

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

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        /*
         * Return event touch to children view.
         */
        mIsDragging = false;
        mIsUnableToDrag = false;

        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        return false;
    }

    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsDragging) {
            return true;
        } else if (mIsUnableToDrag) {
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        if (pointerIndex == -1) {
            mActivePointerId = INVALID_POINTER;
            break;
        }

        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float dy = y - mLastY;
        final float yDiff = Math.abs(y - mLastY);

        if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) {
            // mIsDragging = true;
            mLastX = x;
            setDrawingCacheEnabled(true);
        } else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) {
            // mIsDragging = true;
            mLastY = y;
            setDrawingCacheEnabled(true);
        }
        float matY = (float) Math.abs(corY - ev.getRawY());
        float matX = (float) Math.abs(corX - ev.getRawX());
        if (matY - 100 > 0) {
            mIsDragging = true;
            setDrawingCacheEnabled(true);
            // Dang di chuyen len
        } else if (matX - 100 > 0) {
            mIsDragging = false;
        }
        if (matY == 0) {
            setDrawingCacheEnabled(false);
        }

        /*   }else{
        mIsDragging = false;
        setDrawingCacheEnabled(true);
           }*/
        /* }else if(corX +150 > ev.getRawX()){
        mIsDragging = false;
        setDrawingCacheEnabled(true);
        }else if(corX +150 < ev.getRawX()){
        mIsDragging = false;
        setDrawingCacheEnabled(true);
        }*/
        // double corY = ev.getY();

        break;

    case MotionEvent.ACTION_DOWN:
        corX = ev.getRawX();
        corY = ev.getRawY();
        mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK
                : MotionEventCompat.ACTION_POINTER_INDEX_MASK);
        mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId);
        mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId);
        if (allowSlidingFromHereX(ev, mInitialX)) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // If nobody else got the focus we use it to close the layer
            return super.onInterceptTouchEvent(ev);
        } else if (allowSlidingFromHereY(ev, mInitialY)) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // If nobody else got the focus we use it to close the layer
            return super.onInterceptTouchEvent(ev);
        } else {
            mIsUnableToDrag = true;
        }
        break;
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

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

    return mIsDragging;
}