List of usage examples for android.view ViewParent requestDisallowInterceptTouchEvent
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept);
From source file:com.appunite.list.AbsListView.java
private boolean startScrollIfNeeded(int y) { // Check if we have moved far enough that it looks more like a // scroll than a tap final int deltaY = y - mMotionY; final int distance = Math.abs(deltaY); final boolean overscroll = getScrollY() != 0; if (overscroll || distance > mTouchSlop) { createScrollingCache();/* www . j a v a2 s .co m*/ if (overscroll) { mTouchMode = TOUCH_MODE_OVERSCROLL; mMotionCorrection = 0; } else { mTouchMode = TOUCH_MODE_SCROLL; mMotionCorrection = deltaY > 0 ? mTouchSlop : -mTouchSlop; } final Handler handler = getHandler(); // Handler should not be null unless the AbsListView is not attached to a // window, which would make it very hard to scroll it... but the monkeys // say it's possible. if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } setPressed(false); View motionView = getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); // Time to start stealing events! Once we've stolen them, don't let anyone // steal from us final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } scrollIfNeeded(y); return true; } return false; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private boolean maybeStartScrolling(int delta) { final boolean isOverScroll = (mOverScroll != 0); if (Math.abs(delta) <= mTouchSlop && !isOverScroll) { return false; }/* w w w.j a v a 2 s. com*/ if (isOverScroll) { mTouchMode = TOUCH_MODE_OVERSCROLL; } else { mTouchMode = TOUCH_MODE_DRAGGING; } // Time to start stealing events! Once we've stolen them, don't // let anyone steal from us. final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } cancelCheckForLongPress(); setPressed(false); View motionView = getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); return true; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private void handleDragChange(int delta) { // Time to start stealing events! Once we've stolen them, don't // let anyone steal from us. final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); }/*from w ww. j a v a 2 s. c om*/ final int motionIndex; if (mMotionPosition >= 0) { motionIndex = mMotionPosition - mFirstPosition; } else { // If we don't have a motion position that we can reliably track, // pick something in the middle to make a best guess at things below. motionIndex = getChildCount() / 2; } int motionViewPrevStart = 0; View motionView = this.getChildAt(motionIndex); if (motionView != null) { motionViewPrevStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); } boolean atEdge = scrollListItemsBy(delta); motionView = this.getChildAt(motionIndex); if (motionView != null) { final int motionViewRealStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); if (atEdge) { final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart); updateOverScrollState(delta, overscroll); } } }
From source file:com.appunite.list.AbsListView.java
private void scrollIfNeeded(int y) { final int rawDeltaY = y - mMotionY; final int deltaY = rawDeltaY - mMotionCorrection; int incrementalDeltaY = mLastY != Integer.MIN_VALUE ? y - mLastY : deltaY; if (mTouchMode == TOUCH_MODE_SCROLL) { if (PROFILE_SCROLLING) { if (!mScrollProfilingStarted) { Debug.startMethodTracing("AbsListViewScroll"); mScrollProfilingStarted = true; }/*from w ww . j av a2s . c om*/ } // TODO removed strict span in backport (j. m.) //if (mScrollStrictSpan == null) { // // If it's non-null, we're already in a scroll. // mScrollStrictSpan = StrictMode.enterCriticalSpan("AbsListView-scroll"); //} if (y != mLastY) { // We may be here after stopping a fling and continuing to scroll. // If so, we haven't disallowed intercepting touch events yet. // Make sure that we do so in case we're in a parent that can intercept. if (!mDisallowIntercept && Math.abs(rawDeltaY) > mTouchSlop) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } final int motionIndex; if (mMotionPosition >= 0) { motionIndex = mMotionPosition - mFirstPosition; } else { // If we don't have a motion position that we can reliably track, // pick something in the middle to make a best guess at things below. motionIndex = getChildCount() / 2; } int motionViewPrevTop = 0; View motionView = this.getChildAt(motionIndex); if (motionView != null) { motionViewPrevTop = motionView.getTop(); } // No need to do all this work if we're not going to move anyway boolean atEdge = false; if (incrementalDeltaY != 0) { atEdge = trackMotionScroll(deltaY, incrementalDeltaY); } // Check to see if we have bumped into the scroll limit motionView = this.getChildAt(motionIndex); if (motionView != null) { // Check if the top of the motion view is where it is // supposed to be final int motionViewRealTop = motionView.getTop(); if (atEdge) { // Apply overscroll final int scrollY = getScrollY(); int overscroll = -incrementalDeltaY - (motionViewRealTop - motionViewPrevTop); overScrollBy(0, overscroll, 0, scrollY, 0, 0, 0, mOverscrollDistance, true); if (Math.abs(mOverscrollDistance) == Math.abs(scrollY)) { // Don't allow overfling if we're at the edge. if (mVelocityTracker != null) { mVelocityTracker.clear(); } } final int overscrollMode = getOverScrollMode(); if (overscrollMode == OVER_SCROLL_ALWAYS || (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits())) { mDirection = 0; // Reset when entering overscroll. mTouchMode = TOUCH_MODE_OVERSCROLL; if (rawDeltaY > 0) { mEdgeGlowTop.onPull((float) overscroll / getHeight()); if (!mEdgeGlowBottom.isFinished()) { mEdgeGlowBottom.onRelease(); } } else if (rawDeltaY < 0) { mEdgeGlowBottom.onPull((float) overscroll / getHeight()); if (!mEdgeGlowTop.isFinished()) { mEdgeGlowTop.onRelease(); } } invalidate(); } } mMotionY = y; } mLastY = y; } } else if (mTouchMode == TOUCH_MODE_OVERSCROLL) { if (y != mLastY) { final int oldScroll = getScrollY(); final int newScroll = oldScroll - incrementalDeltaY; int newDirection = y > mLastY ? 1 : -1; if (mDirection == 0) { mDirection = newDirection; } int overScrollDistance = -incrementalDeltaY; if ((newScroll < 0 && oldScroll >= 0) || (newScroll > 0 && oldScroll <= 0)) { overScrollDistance = -oldScroll; incrementalDeltaY += overScrollDistance; } else { incrementalDeltaY = 0; } if (overScrollDistance != 0) { final int scrollY = getScrollY(); overScrollBy(0, overScrollDistance, 0, scrollY, 0, 0, 0, mOverscrollDistance, true); final int overscrollMode = getOverScrollMode(); if (overscrollMode == OVER_SCROLL_ALWAYS || (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits())) { if (rawDeltaY > 0) { mEdgeGlowTop.onPull((float) overScrollDistance / getHeight()); if (!mEdgeGlowBottom.isFinished()) { mEdgeGlowBottom.onRelease(); } } else if (rawDeltaY < 0) { mEdgeGlowBottom.onPull((float) overScrollDistance / getHeight()); if (!mEdgeGlowTop.isFinished()) { mEdgeGlowTop.onRelease(); } } invalidate(); } } if (incrementalDeltaY != 0) { // Coming back to 'real' list scrolling if (getScrollY() != 0) { scrollTo(getScrollX(), 0); invalidateParentIfNeededUnhide(); } trackMotionScroll(incrementalDeltaY, incrementalDeltaY); mTouchMode = TOUCH_MODE_SCROLL; // We did not scroll the full amount. Treat this essentially like the // start of a new touch scroll final int motionPosition = findClosestMotionRow(y); mMotionCorrection = 0; View motionView = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = motionView != null ? motionView.getTop() : 0; mMotionY = y; mMotionPosition = motionPosition; } mLastY = y; mDirection = newDirection; } } }
From source file:com.artifex.mupdf.view.ThumbnailViews.java
private void handleDragChange(int delta) { // Time to start stealing events! Once we've stolen them, don't // let anyone steal from us. final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); }/*w w w. j a v a2 s. com*/ final int motionIndex; if (mMotionPosition >= 0) { motionIndex = mMotionPosition - mFirstPosition; } else { // If we don't have a motion position that we can reliably track, // pick something in the middle to make a best guess at things // below. motionIndex = getChildCount() / 2; } int motionViewPrevStart = 0; View motionView = this.getChildAt(motionIndex); if (motionView != null) { motionViewPrevStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); } boolean atEdge = trackMotionScroll(delta); motionView = this.getChildAt(motionIndex); if (motionView != null) { final int motionViewRealStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); if (atEdge) { final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart); updateOverScrollState(delta, overscroll); } } }
From source file:com.kinth.mmspeed.ui.TwoWayView.java
private void handleDragChange(int delta) { // Time to start stealing events! Once we've stolen them, don't // let anyone steal from us. final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); }/*from ww w . j ava 2s . c o m*/ final int motionIndex; if (mMotionPosition >= 0) { motionIndex = mMotionPosition - mFirstPosition; } else { // If we don't have a motion position that we can reliably track, // pick something in the middle to make a best guess at things // below. motionIndex = getChildCount() / 2; } int motionViewPrevStart = 0; View motionView = this.getChildAt(motionIndex); if (motionView != null) { motionViewPrevStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); } boolean atEdge = scrollListItemsBy(delta); motionView = this.getChildAt(motionIndex); if (motionView != null) { final int motionViewRealStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); if (atEdge) { final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart); updateOverScrollState(delta, overscroll); } } }
From source file:com.artifex.mupdflib.TwoWayView.java
private void handleDragChange(int delta) { // Time to start stealing events! Once we've stolen them, don't // let anyone steal from us. final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); }//from ww w . j a v a 2 s . c o m final int motionIndex; if (mMotionPosition >= 0) { motionIndex = mMotionPosition - mFirstPosition; } else { // If we don't have a motion position that we can reliably track, // pick something in the middle to make a best guess at things below. motionIndex = getChildCount() / 2; } int motionViewPrevStart = 0; View motionView = this.getChildAt(motionIndex); if (motionView != null) { motionViewPrevStart = getChildStartEdge(motionView); } boolean atEdge = scrollListItemsBy(delta); motionView = this.getChildAt(motionIndex); if (motionView != null) { final int motionViewRealStart = getChildStartEdge(motionView); if (atEdge) { final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart); updateOverScrollState(delta, overscroll); } } }
From source file:com.goftagram.telegram.messenger.support.widget.RecyclerView.java
@Override public boolean onInterceptTouchEvent(MotionEvent e) { if (mLayoutFrozen) { // When layout is frozen, RV does not intercept the motion event. // A child view e.g. a button may still get the click. return false; }//from ww w. j ava2s. co m if (dispatchOnItemTouchIntercept(e)) { cancelTouch(); return true; } if (mLayout == null) { return false; } final boolean canScrollHorizontally = mLayout.canScrollHorizontally(); final boolean canScrollVertically = mLayout.canScrollVertically(); if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(e); final int action = MotionEventCompat.getActionMasked(e); final int actionIndex = MotionEventCompat.getActionIndex(e); switch (action) { case MotionEvent.ACTION_DOWN: if (mIgnoreMotionEventTillDown) { mIgnoreMotionEventTillDown = false; } mScrollPointerId = MotionEventCompat.getPointerId(e, 0); mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f); mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f); if (mScrollState == SCROLL_STATE_SETTLING) { getParent().requestDisallowInterceptTouchEvent(true); setScrollState(SCROLL_STATE_DRAGGING); } int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE; if (canScrollHorizontally) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL; } if (canScrollVertically) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL; } startNestedScroll(nestedScrollAxis); break; case MotionEventCompat.ACTION_POINTER_DOWN: mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex); mInitialTouchX = mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f); mInitialTouchY = mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f); break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId); if (index < 0) { Log.e(TAG, "Error processing scroll; pointer index for id " + mScrollPointerId + " not found. Did any MotionEvents get skipped?"); return false; } final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f); final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f); if (mScrollState != SCROLL_STATE_DRAGGING) { final int dx = x - mInitialTouchX; final int dy = y - mInitialTouchY; boolean startScroll = false; if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) { mLastTouchX = mInitialTouchX + mTouchSlop * (dx < 0 ? -1 : 1); startScroll = true; } if (canScrollVertically && Math.abs(dy) > mTouchSlop) { mLastTouchY = mInitialTouchY + mTouchSlop * (dy < 0 ? -1 : 1); startScroll = true; } if (startScroll) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } setScrollState(SCROLL_STATE_DRAGGING); } } } break; case MotionEventCompat.ACTION_POINTER_UP: { onPointerUp(e); } break; case MotionEvent.ACTION_UP: { mVelocityTracker.clear(); stopNestedScroll(); } break; case MotionEvent.ACTION_CANCEL: { cancelTouch(); } } return mScrollState == SCROLL_STATE_DRAGGING; }
From source file:com.goftagram.telegram.messenger.support.widget.RecyclerView.java
@Override public boolean onTouchEvent(MotionEvent e) { if (mLayoutFrozen || mIgnoreMotionEventTillDown) { return false; }/*from w w w . ja v a 2s . c o m*/ if (dispatchOnItemTouch(e)) { cancelTouch(); return true; } if (mLayout == null) { return false; } final boolean canScrollHorizontally = mLayout.canScrollHorizontally(); final boolean canScrollVertically = mLayout.canScrollVertically(); if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } boolean eventAddedToVelocityTracker = false; final MotionEvent vtev = MotionEvent.obtain(e); final int action = MotionEventCompat.getActionMasked(e); final int actionIndex = MotionEventCompat.getActionIndex(e); if (action == MotionEvent.ACTION_DOWN) { mNestedOffsets[0] = mNestedOffsets[1] = 0; } vtev.offsetLocation(mNestedOffsets[0], mNestedOffsets[1]); switch (action) { case MotionEvent.ACTION_DOWN: { mScrollPointerId = MotionEventCompat.getPointerId(e, 0); mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f); mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f); int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE; if (canScrollHorizontally) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL; } if (canScrollVertically) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL; } startNestedScroll(nestedScrollAxis); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex); mInitialTouchX = mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f); mInitialTouchY = mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f); } break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId); if (index < 0) { Log.e(TAG, "Error processing scroll; pointer index for id " + mScrollPointerId + " not found. Did any MotionEvents get skipped?"); return false; } final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f); final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f); int dx = mLastTouchX - x; int dy = mLastTouchY - y; if (dispatchNestedPreScroll(dx, dy, mScrollConsumed, mScrollOffset)) { dx -= mScrollConsumed[0]; dy -= mScrollConsumed[1]; vtev.offsetLocation(mScrollOffset[0], mScrollOffset[1]); // Updated the nested offsets mNestedOffsets[0] += mScrollOffset[0]; mNestedOffsets[1] += mScrollOffset[1]; } if (mScrollState != SCROLL_STATE_DRAGGING) { boolean startScroll = false; if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) { if (dx > 0) { dx -= mTouchSlop; } else { dx += mTouchSlop; } startScroll = true; } if (canScrollVertically && Math.abs(dy) > mTouchSlop) { if (dy > 0) { dy -= mTouchSlop; } else { dy += mTouchSlop; } startScroll = true; } if (startScroll) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } setScrollState(SCROLL_STATE_DRAGGING); } } if (mScrollState == SCROLL_STATE_DRAGGING) { mLastTouchX = x - mScrollOffset[0]; mLastTouchY = y - mScrollOffset[1]; if (scrollByInternal(canScrollHorizontally ? dx : 0, canScrollVertically ? dy : 0, vtev)) { getParent().requestDisallowInterceptTouchEvent(true); } } } break; case MotionEventCompat.ACTION_POINTER_UP: { onPointerUp(e); } break; case MotionEvent.ACTION_UP: { mVelocityTracker.addMovement(vtev); eventAddedToVelocityTracker = true; mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity); final float xvel = canScrollHorizontally ? -VelocityTrackerCompat.getXVelocity(mVelocityTracker, mScrollPointerId) : 0; final float yvel = canScrollVertically ? -VelocityTrackerCompat.getYVelocity(mVelocityTracker, mScrollPointerId) : 0; if (!((xvel != 0 || yvel != 0) && fling((int) xvel, (int) yvel))) { setScrollState(SCROLL_STATE_IDLE); } resetTouch(); } break; case MotionEvent.ACTION_CANCEL: { cancelTouch(); } break; } if (!eventAddedToVelocityTracker) { mVelocityTracker.addMovement(vtev); } vtev.recycle(); return true; }