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.baitouwei.swiperefresh.ASwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!isDragging) { return super.onTouchEvent(ev); }/*from w w w. ja v a2 s. c om*/ final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_MOVE: final float y = getMotionEventY(ev, activePointerId); final float dragOffset = (int) (y - initialMotionY); if (isSwipeStatusEnsure) { if ((dragOffset < 0 && isSwipeDown == true) || (dragOffset > 0 && isSwipeDown == false)) { return false; } } if (dragOffset > 0) {//SwipeDown,PS:dragPercent and dragOffset is positive if (headerView.getVisibility() != VISIBLE) { headerView.setVisibility(VISIBLE); } isSwipeDown = true; dragPercent = dragOffset / (contentViewSwipeDownOffsetRange); if (dampAbleOfSwipeDown) { int targetY = dampCompute(Math.abs(dragOffset * parallaxFactorOfContentSwipeDown), contentViewSwipeDownOffsetRange, swipeDownDampRate); offsetContent(targetY - currentContentOffset, 1); } else { if (dragOffset < contentViewSwipeDownOffsetRange) { offsetContent((int) dragOffset - currentContentOffset, parallaxFactorOfContentSwipeDown); } } offsetHeader((int) (dragPercent * headerView.getOffsetRange() - headerView.getCurrentOffset())); if (swipeLayoutConfigListener.isReadyToRefresh(this, dragOffset)) { headerView.updateStatus(SwipeStatus.READY); } else { headerView.updateStatus(SwipeStatus.NORMAL); } headerView.updatePercent(dragPercent); } else {//SwipeUp,PS:dragPercent and dragOffset is negative if (footerView.getVisibility() != VISIBLE) { footerView.setVisibility(VISIBLE); } isSwipeDown = false; dragPercent = dragOffset / (contentViewSwipeUpOffsetRange); if (dampAbleOfSwipeUp) { int targetY = dampCompute(Math.abs(dragOffset * parallaxFactorOfContentSwipeUp), Math.abs(contentViewSwipeUpOffsetRange), swipeUpDampRate); offsetContent(-targetY - currentContentOffset, 1); } else { if (dragOffset > contentViewSwipeUpOffsetRange) { offsetContent((int) dragOffset - currentContentOffset, parallaxFactorOfContentSwipeUp); } } offsetFooter((int) (dragPercent * footerView.getOffsetRange() - footerView.getCurrentOffset())); if (swipeLayoutConfigListener.isReadyToLoadMore(this, dragOffset)) { footerView.updateStatus(SwipeStatus.READY); } else { footerView.updateStatus(SwipeStatus.NORMAL); } footerView.updatePercent(dragPercent); } if (isSwipeStatusEnsure == false) { isSwipeStatusEnsure = true; } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (isSwipeDown) { if (headerView.getSwipeStatus() == SwipeStatus.READY) { refreshStart(); } else { animateContentOffsetToPos(true, true, new OnAnimateContentOffsetListener() { @Override public void onOffsetEnd() { headerView.updateStatus(SwipeStatus.NORMAL); } }); animateHeaderOffsetToPos(true, new OnAnimateContentOffsetListener() { @Override public void onOffsetEnd() { headerView.updateStatus(SwipeStatus.NORMAL); } }); } } else { if (footerView.getSwipeStatus() == SwipeStatus.READY) { loadMoreStart(); } else { animateContentOffsetToPos(true, false, new OnAnimateContentOffsetListener() { @Override public void onOffsetEnd() { footerView.updateStatus(SwipeStatus.NORMAL); } }); animateFooterOffsetToPos(true, new OnAnimateContentOffsetListener() { @Override public void onOffsetEnd() { footerView.updateStatus(SwipeStatus.NORMAL); } }); } } isDragging = false; activePointerId = INVALID_POINTER; isSwipeStatusEnsure = false; break; } return true; }
From source file:android.support.design.widget.CoordinatorLayout.java
private boolean performIntercept(MotionEvent ev, final int type) { boolean intercepted = false; boolean newBlock = false; MotionEvent cancelEvent = null;/*from w ww . j a v a 2 s.c om*/ final int action = MotionEventCompat.getActionMasked(ev); final List<View> topmostChildList = mTempList1; getTopSortedChildren(topmostChildList); // Let topmost child views inspect first final int childCount = topmostChildList.size(); for (int i = 0; i < childCount; i++) { final View child = topmostChildList.get(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final Behavior b = lp.getBehavior(); if ((intercepted || newBlock) && action != MotionEvent.ACTION_DOWN) { // Cancel all behaviors beneath the one that intercepted. // If the event is "down" then we don't have anything to cancel yet. if (b != null) { if (cancelEvent == null) { final long now = SystemClock.uptimeMillis(); cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); } switch (type) { case TYPE_ON_INTERCEPT: b.onInterceptTouchEvent(this, child, cancelEvent); break; case TYPE_ON_TOUCH: b.onTouchEvent(this, child, cancelEvent); break; } } continue; } if (!intercepted && b != null) { switch (type) { case TYPE_ON_INTERCEPT: intercepted = b.onInterceptTouchEvent(this, child, ev); break; case TYPE_ON_TOUCH: intercepted = b.onTouchEvent(this, child, ev); break; } if (intercepted) { mBehaviorTouchView = child; } } // Don't keep going if we're not allowing interaction below this. // Setting newBlock will make sure we cancel the rest of the behaviors. final boolean wasBlocking = lp.didBlockInteraction(); final boolean isBlocking = lp.isBlockingInteractionBelow(this, child); newBlock = isBlocking && !wasBlocking; if (isBlocking && !newBlock) { // Stop here since we don't have anything more to cancel - we already did // when the behavior first started blocking things below this point. break; } } topmostChildList.clear(); return intercepted; }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
@Override public boolean onTouchEvent(final MotionEvent event) { // Return if animation is running if (mAnimator.isRunning()) return true; // If is not idle state, return if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Action down touch mIsActionDown = true;/*w ww. j av a 2 s. co m*/ if (!mIsViewPagerMode) break; // Detect if we touch down on tab, later to move mIsTabActionDown = (int) (event.getX() / mTabSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If tab touched, so move if (mIsTabActionDown) { mViewPager.setCurrentItem((int) (event.getX() / mTabSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set tab index relative to current coordinate if (mIsActionDown) setTabIndex((int) (event.getX() / mTabSize)); case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsTabActionDown = false; mIsActionDown = false; break; } return true; }
From source file:com.daiv.android.twitter.manipulations.widgets.swipe_refresh_layout.FullScreenSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;// w ww.j av a2s. c om mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } offsetTop = offsetTop / 6; updateContentOffsetTop((int) (offsetTop)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); resetTriggerPercentage(); updateContentOffsetTop(0); } else { updatePositionTimeout(); } mPrevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:com.bluepixel.android.sgpool.ui.widget.SwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;/*from ww w . ja va2 s.c o m*/ } if (!isEnabled() || mReturningToStart || canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; mCurrPercentage = 0; break; case MotionEvent.ACTION_MOVE: final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = y - mInitialMotionY; if (!mIsBeingDragged && yDiff > mTouchSlop) { mIsBeingDragged = true; } if (mIsBeingDragged) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); } else { // Just track the user's movement setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); updateContentOffsetTop((int) (yDiff)); if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } else { updatePositionTimeout(); } } mLastMotionY = y; } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionY = MotionEventCompat.getY(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mCurrPercentage = 0; mActivePointerId = INVALID_POINTER; return false; } return true; }
From source file:com.albedinsky.android.ui.widget.ViewPagerWidget.java
/** *///w w w . ja v a 2 s. c om @Override public boolean onTouchEvent(@NonNull MotionEvent event) { this.ensureDecorator(); if (!mDecorator.hasPrivateFlag(PFLAG_PAGE_SWIPING_ENABLED)) { return false; } if (mDecorator.onTouchEvent(event)) { this.requestParentDisallowInterceptTouchEvent(true); return true; } if (mDecorator.hasPrivateFlag(PFLAG_PAGE_FLING_SWIPING_ENABLED)) { this.ensureVelocityTracker(); mVelocityTracker.addMovement(event); switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mVelocityTracker.computeCurrentVelocity(UiConfig.VELOCITY_UNITS); final float xVelocity = mVelocityTracker.getXVelocity(); if (Math.abs(xVelocity) > mPageFlingSwipingSensitivity) { super.onTouchEvent(event); this.handleFling(xVelocity); return true; } } } return super.onTouchEvent(event); }
From source file:at.ac.uniklu.mobile.sportal.ui.viewpagerindicator.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; }//from www .j av a2s . 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; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } else { //Middle third if (mCenterItemClickListener != null) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } 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; }
From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: currPercentage = 0;//from ww w .ja va 2 s .com downEvent = MotionEvent.obtain(event); prevY = downEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (downEvent != null && !returningToStart) { final float eventY = event.getY(); float yDiff = eventY - downEvent.getY(); if (yDiff > touchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > distanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( accelerateInterpolator.getInterpolation(yDiff / distanceToTriggerSync)); float offsetTop = yDiff; if (prevY > eventY) { offsetTop = yDiff - touchSlop; } updateContentOffsetTop((int) (offsetTop)); // if (prevY > eventY && (target.getTop() < touchSlop)) { if (prevY > eventY && (circle.getTop() < touchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(cancel); } else { updatePositionTimeout(); } prevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (downEvent != null) { downEvent.recycle(); downEvent = null; } break; } return handled; }
From source file:com.doutech.bluetoothlost.view.SwipeListView.java
/** * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent) *///from www. j a va2 s . c o m @Override public boolean onInterceptTouchEvent(MotionEvent ev) { int action = MotionEventCompat.getActionMasked(ev); final float x = ev.getX(); final float y = ev.getY(); if (isEnabled() && touchListener.isSwipeEnabled()) { if (touchState == TOUCH_STATE_SCROLLING_X) { return touchListener.onTouch(this, ev); } switch (action) { // case MotionEvent.ACTION_MOVE: // checkInMoving(x, y); // return touchState == TOUCH_STATE_SCROLLING_Y; case MotionEvent.ACTION_DOWN: super.onInterceptTouchEvent(ev); touchListener.onTouch(this, ev); touchState = TOUCH_STATE_REST; lastMotionX = x; lastMotionY = y; return false; case MotionEvent.ACTION_CANCEL: touchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_UP: touchListener.onTouch(this, ev); return touchState == TOUCH_STATE_SCROLLING_Y; default: break; } } return super.onInterceptTouchEvent(ev); }
From source file:com.android.BluetoothManager.UI.viewpager.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/* w w w. jav a2 s . c o 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; 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; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } else { //Middle third if (mCenterItemClickListener != null) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } 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; }