List of usage examples for android.view MotionEvent ACTION_CANCEL
int ACTION_CANCEL
To view the source code for android.view MotionEvent ACTION_CANCEL.
Click Source Link
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
@Override public boolean onTouchEvent(MotionEvent event) { if (this.sections == null || this.sections.size() < 1) return super.onTouchEvent(event); float eventY = event.getY(); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { this.setBackgroundColor(Color.TRANSPARENT); this.floatView.setVisibility(INVISIBLE); return true; }//from w w w.ja v a2 s . c o m if (this.touchWrapArea && eventY < this.drawBeginY || eventY > this.drawEndY) { return super.onTouchEvent(event); } switch (action) { case MotionEvent.ACTION_DOWN: this.setBackgroundColor(this.viewBackground); this.floatView.setVisibility(VISIBLE); this.showFloatView(eventY); return true; case MotionEvent.ACTION_MOVE: this.showFloatView(eventY); return true; } return super.onTouchEvent(event); }
From source file:android.support.v7.widget.ForwardingListener.java
/** * Handles forwarded motion events and determines when to stop * forwarding./*from w ww . j a v a2 s . c om*/ * * @param srcEvent motion event in source view coordinates * @return true to continue forwarding motion events, false to cancel */ private boolean onTouchForwarded(MotionEvent srcEvent) { final View src = mSrc; final ShowableListMenu popup = getPopup(); if (popup == null || !popup.isShowing()) { return false; } final DropDownListView dst = (DropDownListView) popup.getListView(); if (dst == null || !dst.isShown()) { return false; } // Convert event to destination-local coordinates. final MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent); toGlobalMotionEvent(src, dstEvent); toLocalMotionEvent(dst, dstEvent); // Forward converted event to destination view, then recycle it. final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId); dstEvent.recycle(); // Always cancel forwarding when the touch stream ends. final int action = MotionEventCompat.getActionMasked(srcEvent); final boolean keepForwarding = action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_CANCEL; return handled && keepForwarding; }
From source file:com.cnh.library.materialdrawer.view.BezelImageView.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { // Check for clickable state and do nothing if disabled if (!this.isClickable()) { this.isSelected = false; return super.onTouchEvent(event); }//from w w w .j a v a 2 s . com // Set selected state based on Motion Event switch (event.getAction()) { case MotionEvent.ACTION_DOWN: this.isSelected = true; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_SCROLL: case MotionEvent.ACTION_OUTSIDE: case MotionEvent.ACTION_CANCEL: this.isSelected = false; break; } // Redraw image and return super type this.invalidate(); return super.dispatchTouchEvent(event); }
From source file:cn.ieclipse.af.view.ScrollLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); }//from ww w . jav a 2 s . c o m mVelocityTracker.addMovement(event); final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: if (debug) { Log.v(TAG, "event down!"); } if (!mScroller.isFinished()) { mScroller.abortAnimation(); } mLastMotionX = x; break; case MotionEvent.ACTION_MOVE: int deltaX = (int) (mLastMotionX - x); mLastMotionX = x; scrollBy(deltaX, 0); break; case MotionEvent.ACTION_UP: if (debug) { Log.v(TAG, "event : up"); } // if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); if (debug) { Log.v(TAG, "velocityX:" + velocityX); } if (velocityX > mSnapVelocity) { if (mCurScreen > 0) { // Fling enough to move left if (debug) { Log.v(TAG, "snap left"); } snapToScreen(mCurScreen - 1); } else { // TODO disableWipe(false); snapToDestination(); } } else if (velocityX < -mSnapVelocity) { if (mCurScreen < getChildCount() - 1) { // Fling enough to move right if (debug) { Log.v(TAG, "snap right"); } snapToScreen(mCurScreen + 1); } else { // TODO disableWipe(false); snapToDestination(); } } else { snapToDestination(); } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } // } mTouchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; break; } return true; }
From source file:com.devexweb.googlemapsapi.lib.BottomSheetBehaviorGoogleMapsLike.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; }//from w w w .j av a 2s.c o m int action = MotionEventCompat.getActionMasked(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.INVALID_POINTER_ID; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return false; } break; case MotionEvent.ACTION_DOWN: int initialX = (int) event.getX(); mInitialY = (int) event.getY(); if (mState == STATE_ANCHOR_POINT) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; } else { View scroll = mNestedScrollingChildRef.get(); if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; } } mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID && !parent.isPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) { return true; } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. View scroll = mNestedScrollingChildRef.get(); return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY()) && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java
@Override public void onTouchEvent(final RecyclerView recyclerView, final MotionEvent event) { // We should only be here if we intercepted the touch due to swipe. Assert.isTrue(mIsSwiping);/*from www .j a v a 2 s .c om*/ // We are now tracking a swipe gesture. mVelocityTracker.addMovement(event); final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_OUTSIDE: case MotionEvent.ACTION_MOVE: if (hasValidGestureSwipeTarget()) { mListItemView.setSwipeTranslationX(event.getX() - mInitialX); } break; case MotionEvent.ACTION_UP: if (hasValidGestureSwipeTarget()) { final float maxVelocity = mMaximumFlingVelocity; mVelocityTracker.computeCurrentVelocity(UNIT_SECONDS, maxVelocity); final float velocityX = getLastComputedXVelocity(); final float translationX = mListItemView.getSwipeTranslationX(); int swipeDirection = SWIPE_DIRECTION_NONE; if (translationX != 0) { swipeDirection = translationX > 0 ? SWIPE_DIRECTION_RIGHT : SWIPE_DIRECTION_LEFT; } else if (velocityX != 0) { swipeDirection = velocityX > 0 ? SWIPE_DIRECTION_RIGHT : SWIPE_DIRECTION_LEFT; } final boolean fastEnough = isTargetSwipedFastEnough(); final boolean farEnough = isTargetSwipedFarEnough(); final boolean shouldDismiss = (fastEnough || farEnough); if (shouldDismiss) { if (fastEnough) { animateDismiss(mListItemView, velocityX); } else { animateDismiss(mListItemView, swipeDirection); } } else { animateRestore(mListItemView, velocityX); } onSwipeGestureEnd(mListItemView, shouldDismiss ? swipeDirection : SWIPE_DIRECTION_NONE); } else { onGestureEnd(); } break; case MotionEvent.ACTION_CANCEL: if (hasValidGestureSwipeTarget()) { animateRestore(mListItemView, 0f); onSwipeGestureEnd(mListItemView, SWIPE_DIRECTION_NONE); } else { onGestureEnd(); } break; } }
From source file:com.douban.rexxar.view.NestedWebView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mEnableNestedScroll) { return super.onTouchEvent(ev); }/*from w w w . ja v a2 s.com*/ boolean returnValue = false; MotionEvent event = MotionEvent.obtain(ev); final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { mNestedOffsetY = 0; } int eventX = (int) event.getX(); int eventY = (int) event.getY(); event.offsetLocation(0, -mNestedOffsetY); switch (action) { case MotionEvent.ACTION_MOVE: if (mNestedScrollEstablish) { mVelocityTracker.addMovement(ev); int deltaX = mLastX - eventX; int deltaY = mLastY - eventY; // ??? if (mOptimizeHorizontalScroll) { // ?? if (!mScrollHorizontalEstablish && !mScrollVerticalEstablish) { if (Math.abs(deltaX) > Math.abs(deltaY) * 1.5 && Math.abs(deltaX) > mTouchSlop) { mScrollHorizontalEstablish = true; } else if (Math.abs(deltaY) > Math.abs(deltaX) && Math.abs(deltaY) > mTouchSlop) { mScrollVerticalEstablish = true; mFrozenX = eventX; } } } mLastX = eventX; if (mScrollHorizontalEstablish) { event.offsetLocation(0, deltaY); // ? returnValue = super.onTouchEvent(event); } else { // ? if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mOffsetInWindow)) { deltaY -= mScrollConsumed[1]; mLastY = eventY - mOffsetInWindow[1]; mNestedOffsetY += mOffsetInWindow[1]; event.offsetLocation(0, -mOffsetInWindow[1]); } else { mLastY = eventY; } // parent?consumedelta?webView? int oldScrollY = getScrollY(); if ((deltaY < 0 && getScrollY() > 0) || deltaY > 0) { // ??? if (mScrollVerticalEstablish) { event.offsetLocation(mFrozenX - eventX, 0); returnValue = super.onTouchEvent(event); } else { returnValue = super.onTouchEvent(event); } mLastYWebViewConsume = event.getY(); } else { // FIXME ?? if (mScrollVerticalEstablish) { event.offsetLocation(mFrozenX - eventX, mLastYWebViewConsume - event.getY()); } else { event.offsetLocation(0, mLastYWebViewConsume - event.getY()); } super.onTouchEvent(event); } // deltaY if (deltaY == getScrollY() - oldScrollY) { // ??? } else if (deltaY < getScrollY() - oldScrollY) { // if (getScrollY() <= 5) { int dyConsumed = oldScrollY - getScrollY(); int dyUnconsumed = deltaY - (getScrollY() - oldScrollY); if (dispatchNestedScroll(0, dyConsumed, 0, dyUnconsumed, mOffsetInWindow)) { mNestedOffsetY += mOffsetInWindow[1]; mLastY -= mOffsetInWindow[1]; event.offsetLocation(0, mOffsetInWindow[1]); } } returnValue = true; } else { // ??? } } } else { returnValue = super.onTouchEvent(event); } break; case MotionEvent.ACTION_DOWN: mLastYWebViewConsume = event.getY(); returnValue = super.onTouchEvent(event); mLastX = eventX; mLastY = eventY; // start NestedScroll mNestedScrollEstablish = startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); mScrollHorizontalEstablish = false; mScrollVerticalEstablish = false; initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); break; case MotionEvent.ACTION_CANCEL: if (mNestedScrollEstablish) { returnValue = super.onTouchEvent(event); // end NestedScroll stopNestedScroll(); } else { returnValue = super.onTouchEvent(event); } mScrollHorizontalEstablish = false; mScrollVerticalEstablish = false; mFrozenX = 0; recycleVelocityTracker(); break; case MotionEvent.ACTION_UP: if (mNestedScrollEstablish) { if (mScrollHorizontalEstablish) { // ? event.offsetLocation(0, mLastY - eventY); } returnValue = super.onTouchEvent(event); final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) velocityTracker.getYVelocity(); if ((Math.abs(initialVelocity) > mMinimumVelocity) && getScrollY() == 0) { flingWithNestedDispatch(-initialVelocity); } else {// end NestedScroll stopNestedScroll(); } } else { returnValue = super.onTouchEvent(event); } mScrollHorizontalEstablish = false; mScrollVerticalEstablish = false; mFrozenX = 0; recycleVelocityTracker(); break; } return returnValue; }
From source file:com.deanlib.ootb.widget.loopviewpager.LoopViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { try {//w w w .j a v a 2s . c o m if (ev.getPointerCount() > 1 && mIsDisallowIntercept) { requestDisallowInterceptTouchEvent(false); boolean handled = super.dispatchTouchEvent(ev); requestDisallowInterceptTouchEvent(true); return handled; } super.onTouchEvent(ev); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mDownX = ev.getX(); mDownY = ev.getY(); downTime = System.currentTimeMillis(); break; case MotionEvent.ACTION_MOVE: /* //?? if(Math.abs(ev.getX()-mDownX) > 0 ){ return true; }else{ return false; } */ if (Math.abs(ev.getX() - mDownX) > 0) { return true; } else { return false; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: break; default: break; } } catch (Exception e) { e.printStackTrace(); } return true; }
From source file:com.android.volley.ui.PhotoView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (mScaleGetureDetector == null || mGestureDetector == null) { // We're being destroyed; ignore any touch events return true; }//from w ww. j a v a2 s . co m mScaleGetureDetector.onTouchEvent(event); mGestureDetector.onTouchEvent(event); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (!mTranslateRunnable.mRunning) { snap(); } break; } return true; }
From source file:com.dotit.gireve.ihm.viewpager.CirclePageIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; }/*from w ww . ja v a 2s . c o m*/ 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; mViewPager.fakeDragBy(deltaX); } 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.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; }