List of usage examples for android.support.v4.view ViewCompat OVER_SCROLL_IF_CONTENT_SCROLLS
int OVER_SCROLL_IF_CONTENT_SCROLLS
To view the source code for android.support.v4.view ViewCompat OVER_SCROLL_IF_CONTENT_SCROLLS.
Click Source Link
From source file:com.fish.nsd.MyNestedScrollView.java
@Override public boolean onTouchEvent(MotionEvent ev) { initVelocityTrackerIfNotExists();//from ww w .ja v a2 s . c o m MotionEvent vtev = MotionEvent.obtain(ev); final int actionMasked = MotionEventCompat.getActionMasked(ev); if (actionMasked == MotionEvent.ACTION_DOWN) { mNestedYOffset = 0; } vtev.offsetLocation(0, mNestedYOffset); switch (actionMasked) { case MotionEvent.ACTION_DOWN: { if (getChildCount() == 0) { return false; } if ((mIsBeingDragged = !mScroller.isFinished())) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mLastMotionY = (int) ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; } case MotionEvent.ACTION_MOVE: final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (activePointerIndex == -1) { Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); break; } final int y = (int) MotionEventCompat.getY(ev, activePointerIndex); int deltaY = mLastMotionY - y; if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) { deltaY -= mScrollConsumed[1]; vtev.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } mIsBeingDragged = true; if (deltaY > 0) { deltaY -= mTouchSlop; } else { deltaY += mTouchSlop; } } if (mIsBeingDragged) { // Scroll to follow the motion event mLastMotionY = y - mScrollOffset[1]; final int oldY = getScrollY(); final int range = getScrollRange(); final int overscrollMode = ViewCompat.getOverScrollMode(this); boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0); // Calling overScrollByCompat will call onOverScrolled, which // calls onScrollChanged if applicable. if (overScrollByCompat(0, deltaY, 0, getScrollY(), 0, range, 0, 0, true) && !hasNestedScrollingParent()) { // Break our velocity if we hit a scroll barrier. mVelocityTracker.clear(); } final int scrolledDeltaY = getScrollY() - oldY; final int unconsumedY = deltaY - scrolledDeltaY; boolean consumedMove = false; if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) { mLastMotionY -= mScrollOffset[1]; vtev.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; if (mScrollOffset[1] > 0) { consumedMove = true; } } if (canOverscroll && !consumedMove) { ensureGlows(); final int pulledToY = oldY + deltaY; if (pulledToY < 0) { if (glowTopEnable) { mEdgeGlowTop.onPull((float) deltaY / getHeight(), MotionEventCompat.getX(ev, activePointerIndex) / getWidth()); if (!mEdgeGlowBottom.isFinished()) { mEdgeGlowBottom.onRelease(); } } else { //??child??parent? MyNestedScrollView parent = (MyNestedScrollView) getParent().getParent(); parent.mEdgeGlowTop.onPull((float) deltaY / parent.getHeight(), MotionEventCompat.getX(ev, activePointerIndex) / parent.getWidth()); if (parent.mEdgeGlowTop != null && (!parent.mEdgeGlowTop.isFinished())) { ViewCompat.postInvalidateOnAnimation(parent); } } } else if (pulledToY > range) { mEdgeGlowBottom.onPull((float) deltaY / getHeight(), 1.f - MotionEventCompat.getX(ev, activePointerIndex) / getWidth()); if (!mEdgeGlowTop.isFinished()) { mEdgeGlowTop.onRelease(); } } if (mEdgeGlowTop != null && (!mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished())) { ViewCompat.postInvalidateOnAnimation(this); } } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); if ((Math.abs(initialVelocity) > mMinimumVelocity)) { flingWithNestedDispatch(-initialVelocity); } else if (mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) { ViewCompat.postInvalidateOnAnimation(this); } } mActivePointerId = INVALID_POINTER; endDrag(); break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged && getChildCount() > 0) { if (mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) { ViewCompat.postInvalidateOnAnimation(this); } } mActivePointerId = INVALID_POINTER; endDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionY = (int) MotionEventCompat.getY(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionY = (int) MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (mVelocityTracker != null) { mVelocityTracker.addMovement(vtev); } vtev.recycle(); return true; }
From source file:xyz.hanks.nestedwebview.SSScrollView.java
@Override public boolean onTouchEvent(MotionEvent ev) { initVelocityTrackerIfNotExists();// w ww. j a v a2 s . c o m MotionEvent vtev = MotionEvent.obtain(ev); final int actionMasked = MotionEventCompat.getActionMasked(ev); if (actionMasked == MotionEvent.ACTION_DOWN) { mNestedYOffset = 0; } vtev.offsetLocation(0, mNestedYOffset); switch (actionMasked) { case MotionEvent.ACTION_DOWN: { if (getChildCount() == 0) { return false; } if ((mIsBeingDragged = !mScroller.isFinished())) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mLastMotionY = (int) ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; } case MotionEvent.ACTION_MOVE: final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (activePointerIndex == -1) { Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); break; } final int y = (int) MotionEventCompat.getY(ev, activePointerIndex); int deltaY = mLastMotionY - y; if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) { deltaY -= mScrollConsumed[1]; vtev.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } mIsBeingDragged = true; if (deltaY > 0) { deltaY -= mTouchSlop; } else { deltaY += mTouchSlop; } } if (mIsBeingDragged) { // Scroll to follow the motion event mLastMotionY = y - mScrollOffset[1]; final int oldY = getScrollY(); final int range = getScrollRange(); final int overscrollMode = ViewCompat.getOverScrollMode(this); boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0); // Calling overScrollByCompat will call onOverScrolled, which // calls onScrollChanged if applicable. if (overScrollByCompat(0, deltaY, 0, getScrollY(), 0, range, 0, 0, true) && !hasNestedScrollingParent()) { // Break our velocity if we hit getDirection scroll barrier. mVelocityTracker.clear(); } final int scrolledDeltaY = getScrollY() - oldY; final int unconsumedY = deltaY - scrolledDeltaY; if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) { mLastMotionY -= mScrollOffset[1]; vtev.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } else if (canOverscroll) { ensureGlows(); final int pulledToY = oldY + deltaY; if (pulledToY < 0) { mEdgeGlowTop.onPull((float) deltaY / getHeight(), MotionEventCompat.getX(ev, activePointerIndex) / getWidth()); if (!mEdgeGlowBottom.isFinished()) { mEdgeGlowBottom.onRelease(); } } else if (pulledToY > range) { mEdgeGlowBottom.onPull((float) deltaY / getHeight(), 1.f - MotionEventCompat.getX(ev, activePointerIndex) / getWidth()); if (!mEdgeGlowTop.isFinished()) { mEdgeGlowTop.onRelease(); } } if (mEdgeGlowTop != null && (!mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished())) { ViewCompat.postInvalidateOnAnimation(this); } } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); if ((Math.abs(initialVelocity) > mMinimumVelocity)) { flingWithNestedDispatch(-initialVelocity); } else if (mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) { ViewCompat.postInvalidateOnAnimation(this); } } mActivePointerId = INVALID_POINTER; endDrag(); break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged && getChildCount() > 0) { if (mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) { ViewCompat.postInvalidateOnAnimation(this); } } mActivePointerId = INVALID_POINTER; endDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionY = (int) MotionEventCompat.getY(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionY = (int) MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (mVelocityTracker != null) { mVelocityTracker.addMovement(vtev); } vtev.recycle(); return true; }
From source file:com.android.backups.StaggeredGridViewByJaumo.java
/** * @param deltaY/*from w w w . j a va2 s . c o m*/ * Pixels that content should move by * @return true if the movement completed, false if it was stopped * prematurely. */ private boolean trackMotionScroll(int deltaY, boolean allowOverScroll) { final boolean contentFits = contentFits(); final int allowOverhang = Math.abs(deltaY); final int overScrolledBy; int movedBy; // If grid is not initialized / populated, don't handle scrolling if (mItemBottoms == null) { return false; } if (!contentFits) { final int overhang; final boolean up; mPopulating = true; if (deltaY > 0) { overhang = fillUp(mFirstPosition - 1, allowOverhang) + getItemMargin(0); up = true; } else { overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin; up = false; } movedBy = Math.min(overhang, allowOverhang); if (movedBy < 0) { movedBy = 0; } if (movedBy == 0) { if (up) { mGetToTop = true; } else { mGetToTop = false; } } else { mGetToTop = false; } if (mLoadListener != null && !loadlock && deltaY < 0 && (mFirstPosition + getChildCount()) > (mAdapter.getCount() * 0.75)) { mLoadListener.onLoadmore(); loadlock = true; } boolean canJump = deltaY > 0 && (mFirstPosition / Math.max(1, mColCount)) > 2; if (mJumpToTopListener != null && canJump != mCanJumpToTop) { mJumpToTopListener.onJumpToTopStateChanged(canJump); mCanJumpToTop = canJump; } int scrollDirection = deltaY > 0 ? ScrollDirection.UP : ScrollDirection.DOWN; if (Math.abs(deltaY) > 10 && mChangedScrollDirectionListener != null && scrollDirection != mScrollDirection) { long time = new Date().getTime(); if (mScrollDirectionChangeDate < time - 1000) { mChangedScrollDirectionListener.onScrollDirectionChanged(scrollDirection); mScrollDirection = scrollDirection; mScrollDirectionChangeDate = time; } } offsetChildren(up ? movedBy : -movedBy); if (getChildCount() > MAX_CHILD_COUNT) { recycleOffscreenViews(); } mPopulating = false; mScrollBottom = false; if (up) { mScrollY -= movedBy; } else { mScrollY += movedBy; if (movedBy == 0) { mScrollBottom = true; } } overScrolledBy = allowOverhang - overhang; } else { overScrolledBy = allowOverhang; movedBy = 0; } if (allowOverScroll) { final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits)) { if (overScrolledBy > 0) { EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge; edge.onPull((float) Math.abs(deltaY) / getHeight()); invalidate(); } } } if (mSelectorPosition != INVALID_POSITION) { final int childIndex = mSelectorPosition - mFirstPosition; if (childIndex >= 0 && childIndex < getChildCount()) { positionSelector(INVALID_POSITION, getChildAt(childIndex)); } } else { mSelectorRect.setEmpty(); } invokeOnItemScrollListener(); return deltaY == 0 || movedBy != 0; }
From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java
/** * @param deltaY Pixels that content should move by * @return true if the movement completed, false if it was stopped prematurely. *//*from w ww .j av a2 s.c om*/ private boolean trackMotionScroll(int deltaY, boolean allowOverScroll) { final boolean contentFits = contentFits(); final int allowOverhang = Math.abs(deltaY); final int overScrolledBy; int movedBy; if (!contentFits) { final int overhang; final boolean up; mPopulating = true; if (deltaY > 0) { overhang = fillUp(mFirstPosition - 1, allowOverhang) + mItemMargin; up = true; } else { overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin; up = false; } movedBy = Math.min(overhang, allowOverhang); if (movedBy < 0) { movedBy = 0; } if (movedBy == 0) { if (up) { mGetToTop = true; lazyload = false; } else { mGetToTop = false; lazyload = true; if (mLoadListener != null && getLastPosition() == -1) { // ?Item //LogUtil.d("---count---------- = " + getLastPosition()); mLoadListener.onLoadmore(); } /*if (!loadlock) { mLoadListener.onLoadmore(); loadlock = true; }*/ } } else { mGetToTop = false; lazyload = true; } offsetChildren(up ? movedBy : -movedBy); if (getChildCount() > MAX_CHILD_COUNT) { recycleOffscreenViews(); } mPopulating = false; overScrolledBy = allowOverhang - overhang; } else { overScrolledBy = allowOverhang; movedBy = 0; } if (allowOverScroll) { final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits)) { if (overScrolledBy > 0) { EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge; edge.onPull((float) Math.abs(deltaY) / getHeight()); invalidate(); } } } if (mSelectorPosition != INVALID_POSITION) { final int childIndex = mSelectorPosition - mFirstPosition; if (childIndex >= 0 && childIndex < getChildCount()) { positionSelector(INVALID_POSITION, getChildAt(childIndex)); } } else { mSelectorRect.setEmpty(); } return deltaY == 0 || movedBy != 0; }
From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java
@Override public boolean onTouchEvent(MotionEvent ev) { initVelocityTrackerIfNotExists();/*ww w .j a v a 2 s.co m*/ MotionEvent vtev = MotionEvent.obtain(ev); final int actionMasked = MotionEventCompat.getActionMasked(ev); if (actionMasked == MotionEvent.ACTION_DOWN) { mNestedYOffset = 0; mNestedXOffset = 0; } vtev.offsetLocation(mNestedXOffset, mNestedYOffset); switch (actionMasked) { case MotionEvent.ACTION_DOWN: { if (getChildCount() == 0) { return false; } if ((mIsBeingDragged = !mScroller.isFinished())) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mLastMotionX = (int) ev.getX(); mLastMotionY = (int) ev.getY(); mIsBeingDragged = false; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; } case MotionEvent.ACTION_MOVE: final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (activePointerIndex == -1) { Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); break; } final int x = (int) MotionEventCompat.getX(ev, activePointerIndex); int deltaX = mLastMotionX - x; final int y = (int) MotionEventCompat.getY(ev, activePointerIndex); int deltaY = mLastMotionY - y; if (dispatchNestedPreScroll(deltaX, deltaY, mScrollConsumed, mScrollOffset)) { deltaX -= mScrollConsumed[0]; deltaY -= mScrollConsumed[1]; vtev.offsetLocation(mScrollOffset[0], mScrollOffset[1]); mNestedXOffset += mScrollOffset[0]; mNestedYOffset += mScrollOffset[1]; } if (!mIsBeingDragged) { if (Math.abs(deltaY) > mTouchSlop) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } mIsBeingDragged = true; if (deltaY > 0) { deltaY -= mTouchSlop; } else { deltaY += mTouchSlop; } scrollDirection = DIRECTION_VERTICAL; } else if (Math.abs(deltaX) > mTouchSlop) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } mIsBeingDragged = true; if (deltaX > 0) { deltaX -= mTouchSlop; } else { deltaX += mTouchSlop; } scrollDirection = DIRECTION_HORIZONTAL; } else { scrollDirection = DIRECTION_INVALIDATE; } } if (mIsBeingDragged && scrollDirection != DIRECTION_INVALIDATE) { if (scrollDirection == DIRECTION_VERTICAL) { // Scroll to follow the motion event mLastMotionY = y - mScrollOffset[1]; final int oldY = getScrollY(); final int horizontalRange = getHorizontalScrollRange(); final int verticalRange = getVerticalScrollRange(); final int overscrollMode = ViewCompat.getOverScrollMode(this); boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && verticalRange > 0); // Calling overScrollByCompat will call onOverScrolled, which // calls onScrollChanged if applicable. if (overScrollByCompat(0, deltaY, getScrollX(), getScrollY(), horizontalRange, verticalRange, 0, 0, true) && !hasNestedScrollingParent()) { // Break our velocity if we hit a scroll barrier. mVelocityTracker.clear(); } final int scrolledDeltaY = getScrollY() - oldY; final int unconsumedY = deltaY - scrolledDeltaY; if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) { mLastMotionY -= mScrollOffset[1]; vtev.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; } else if (canOverscroll) { ensureGlows(); final int pulledToY = oldY + deltaY; if (pulledToY < 0) { mEdgeGlowTop.onPull((float) deltaY / getHeight(), MotionEventCompat.getX(ev, activePointerIndex) / getWidth()); if (!mEdgeGlowBottom.isFinished()) { mEdgeGlowBottom.onRelease(); } } else if (pulledToY > verticalRange) { mEdgeGlowBottom.onPull((float) deltaY / getHeight(), 1.f - MotionEventCompat.getX(ev, activePointerIndex) / getWidth()); if (!mEdgeGlowTop.isFinished()) { mEdgeGlowTop.onRelease(); } } if (mEdgeGlowTop != null && (!mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished())) { ViewCompat.postInvalidateOnAnimation(this); } } } else if (scrollDirection == DIRECTION_HORIZONTAL) { // Scroll to follow the motion event mLastMotionX = x - mScrollOffset[0]; final int oldX = getScrollX(); final int horizontalRange = getHorizontalScrollRange(); final int verticalRange = getVerticalScrollRange(); final int overscrollMode = ViewCompat.getOverScrollMode(this); boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && horizontalRange > 0); // Calling overScrollByCompat will call onOverScrolled, which // calls onScrollChanged if applicable. if (overScrollByCompat(deltaX, 0, getScrollX(), getScrollY(), horizontalRange, verticalRange, 0, 0, true) && !hasNestedScrollingParent()) { // Break our velocity if we hit a scroll barrier. mVelocityTracker.clear(); } final int scrolledDeltaX = getScrollX() - oldX; final int unconsumedX = deltaX - scrolledDeltaX; if (dispatchNestedScroll(scrolledDeltaX, 0, unconsumedX, 0, mScrollOffset)) { mLastMotionX -= mScrollOffset[0]; vtev.offsetLocation(mScrollOffset[0], 0); mNestedXOffset += mScrollOffset[0]; } else if (canOverscroll) { ensureGlows(); final int pulledToX = oldX + deltaX; if (pulledToX < 0) { mEdgeGlowLeft.onPull((float) deltaX / getWidth(), MotionEventCompat.getX(ev, activePointerIndex) / getHeight()); if (!mEdgeGlowRight.isFinished()) { mEdgeGlowRight.onRelease(); } } else if (pulledToX > horizontalRange) { mEdgeGlowRight.onPull((float) deltaX / getWidth(), 1.f - MotionEventCompat.getX(ev, activePointerIndex) / getHeight()); if (!mEdgeGlowLeft.isFinished()) { mEdgeGlowLeft.onRelease(); } } if (mEdgeGlowLeft != null && (!mEdgeGlowLeft.isFinished() || !mEdgeGlowRight.isFinished())) { ViewCompat.postInvalidateOnAnimation(this); } } } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int verticalInitialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); int horizontalInitialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); if (scrollDirection == DIRECTION_VERTICAL) { if ((Math.abs(verticalInitialVelocity) > mMinimumVelocity)) { flingWithNestedDispatchVertical(-verticalInitialVelocity); } } else if (scrollDirection == DIRECTION_HORIZONTAL) { if ((Math.abs(horizontalInitialVelocity) > mMinimumVelocity)) { flingWithNestedDispatchHorizontal(-horizontalInitialVelocity); } } mActivePointerId = INVALID_POINTER; endDrag(); } break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged && getChildCount() > 0) { mActivePointerId = INVALID_POINTER; endDrag(); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = (int) MotionEventCompat.getX(ev, index); mLastMotionY = (int) MotionEventCompat.getY(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionX = (int) MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); mLastMotionY = (int) MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (mVelocityTracker != null) { mVelocityTracker.addMovement(vtev); } vtev.recycle(); return true; }
From source file:com.hxqc.mall.core.views.CustomScrollView.java
boolean overScrollByCompat(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final int overScrollMode = ViewCompat.getOverScrollMode(this); final boolean canScrollHorizontal = computeHorizontalScrollRange() > computeHorizontalScrollExtent(); final boolean canScrollVertical = computeVerticalScrollRange() > computeVerticalScrollExtent(); final boolean overScrollHorizontal = overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); final boolean overScrollVertical = overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); int newScrollX = scrollX + deltaX; if (!overScrollHorizontal) { maxOverScrollX = 0;//w ww . ja v a2 s . c o m } int newScrollY = scrollY + deltaY; if (!overScrollVertical) { maxOverScrollY = 0; } // Clamp values if at the limits and record final int left = -maxOverScrollX; final int right = maxOverScrollX + scrollRangeX; final int top = -maxOverScrollY; final int bottom = maxOverScrollY + scrollRangeY; boolean clampedX = false; if (newScrollX > right) { newScrollX = right; clampedX = true; } else if (newScrollX < left) { newScrollX = left; clampedX = true; } boolean clampedY = false; if (newScrollY > bottom) { newScrollY = bottom; clampedY = true; } else if (newScrollY < top) { newScrollY = top; clampedY = true; } onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); return clampedX || clampedY; }
From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
boolean overScrollByCompat(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { final int overScrollMode = ViewCompat.getOverScrollMode(this); final boolean canScrollHorizontal = computeHorizontalScrollRange() > computeHorizontalScrollExtent(); final boolean canScrollVertical = computeVerticalScrollRange() > computeVerticalScrollExtent(); final boolean overScrollHorizontal = overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); final boolean overScrollVertical = overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); int newScrollX = scrollX + deltaX; if (!overScrollHorizontal) { maxOverScrollX = 0;//ww w . j a v a 2 s .c o m } int newScrollY = scrollY + deltaY; if (!overScrollVertical) { maxOverScrollY = 0; } // Clamp values if at the limits and record final int left = -maxOverScrollX; final int right = maxOverScrollX + scrollRangeX; final int top = -maxOverScrollY; final int bottom = maxOverScrollY + scrollRangeY; boolean clampedX = false; if (newScrollX > right) { newScrollX = right; clampedX = true; } else if (newScrollX < left) { newScrollX = left; clampedX = true; } boolean clampedY = false; if (newScrollY > bottom) { newScrollY = bottom; clampedY = true; } else if (newScrollY < top) { newScrollY = top; clampedY = true; } if (clampedY) { mScroller.springBack(newScrollX, newScrollY, 0, 0, 0, getScrollRange()); } onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); return clampedX || clampedY; }
From source file:com.android.backups.BackupStaggeredGridView.java
/** * @param deltaY Pixels that content should move by * @return true if the movement completed, false if it was stopped prematurely. *///from w w w . j a v a2s. c om private boolean trackMotionScroll(int deltaY, boolean allowOverScroll) { final boolean contentFits = contentFits(); final int allowOverhang = Math.abs(deltaY); final int overScrolledBy; int movedBy; if (!contentFits) { final int overhang; final boolean up; mPopulating = true; if (deltaY > 0) { overhang = fillUp(mFirstPosition - 1, allowOverhang) + mItemMargin; up = true; } else { overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin; up = false; } movedBy = Math.min(overhang, allowOverhang); if (movedBy < 0) { movedBy = 0; } if (movedBy == 0) { if (up) { mGetToTop = true; lazyload = false; } else { mGetToTop = false; lazyload = true; if (!loadlock) { mLoadListener.onLoadmore(); loadlock = true; } } } else { mGetToTop = false; lazyload = true; } offsetChildren(up ? movedBy : -movedBy); if (getChildCount() > MAX_CHILD_COUNT) { recycleOffscreenViews(); } mPopulating = false; overScrolledBy = allowOverhang - overhang; } else { overScrolledBy = allowOverhang; movedBy = 0; } if (allowOverScroll) { final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits)) { if (overScrolledBy > 0) { EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge; edge.onPull((float) Math.abs(deltaY) / getHeight()); invalidate(); } } } if (mSelectorPosition != INVALID_POSITION) { final int childIndex = mSelectorPosition - mFirstPosition; if (childIndex >= 0 && childIndex < getChildCount()) { positionSelector(INVALID_POSITION, getChildAt(childIndex)); } } else { mSelectorRect.setEmpty(); } invokeOnItemScrollListener(); return deltaY == 0 || movedBy != 0; }
From source file:com.origamilabs.library.views.StaggeredGridView.java
/** @param deltaY * Pixels that content should move by * @return true if the movement completed, false if it was stopped * prematurely. *//*from ww w. j a va 2 s . c om*/ private boolean trackMotionScroll(int deltaY, boolean allowOverScroll) { final boolean contentFits = contentFits(); final int allowOverhang = Math.abs(deltaY); final int overScrolledBy; final int movedBy; if (!contentFits) { final int overhang; final boolean up; mPopulating = true; if (deltaY > 0) { overhang = fillUp(mFirstPosition - 1, allowOverhang); up = true; } else { overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang); up = false; } movedBy = Math.min(overhang, allowOverhang); offsetChildren(up ? movedBy : -movedBy); recycleOffscreenViews(); mPopulating = false; overScrolledBy = allowOverhang - overhang; } else { overScrolledBy = allowOverhang; movedBy = 0; } if (allowOverScroll) { final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits)) { if (overScrolledBy > 0) { EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge; edge.onPull((float) Math.abs(deltaY) / getHeight()); invalidate(); } } } if (mSelectorPosition != INVALID_POSITION) { final int childIndex = mSelectorPosition - mFirstPosition; if (childIndex >= 0 && childIndex < getChildCount()) { positionSelector(INVALID_POSITION, getChildAt(childIndex)); } } else { mSelectorRect.setEmpty(); } invokeOnItemScrollListener(); // scrollbar if (!awakenScrollBars()) { invalidate(); } return deltaY == 0 || movedBy != 0; }
From source file:com.dishes.views.stageredggridview.StaggeredGridView.java
/** * // ww w. j a v a 2 s . c o m * @param deltaY * Pixels that content should move by * @return true if the movement completed, false if it was stopped * prematurely. */ private boolean trackMotionScroll(int deltaY, boolean allowOverScroll) { final boolean contentFits = contentFits(); final int allowOverhang = Math.abs(deltaY); final int overScrolledBy; final int movedBy; if (!contentFits) { final int overhang; final boolean up; mPopulating = true; if (deltaY > 0) { overhang = fillUp(mFirstPosition - 1, allowOverhang) + mItemTopMargin; up = true; } else { overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemBottomMargin; up = false; } movedBy = Math.min(overhang, allowOverhang); offsetChildren(up ? movedBy : -movedBy); recycleOffscreenViews(); mPopulating = false; overScrolledBy = allowOverhang - overhang; } else { overScrolledBy = allowOverhang; movedBy = 0; } if (allowOverScroll) { final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits)) { if (overScrolledBy > 0) { EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge; edge.onPull((float) Math.abs(deltaY) / getHeight()); invalidate(); } } } if (mSelectorPosition != INVALID_POSITION) { final int childIndex = mSelectorPosition - mFirstPosition; if (childIndex >= 0 && childIndex < getChildCount()) { positionSelector(INVALID_POSITION, getChildAt(childIndex)); } } else { mSelectorRect.setEmpty(); } invokeOnItemScrollListener(); // scrollbar if (!awakenScrollBars()) { invalidate(); } return deltaY == 0 || movedBy != 0; }