List of usage examples for android.support.v4.view ViewCompat getOverScrollMode
public static int getOverScrollMode(View v)
From source file:android.support.v7.widget.RecyclerViewEx.java
/** * Does not perform bounds checking. Used by internal methods that have already validated input. *//*from w w w . j av a 2s .c o m*/ void scrollByInternal(int x, int y) { int overscrollX = 0, overscrollY = 0; int hresult = 0, vresult = 0; consumePendingUpdateOperations(); if (mAdapter != null) { eatRequestLayout(); mRunningLayoutOrScroll = true; if (x != 0) { hresult = mLayout.scrollHorizontallyBy(x, mRecycler, mState); overscrollX = x - hresult; } if (y != 0) { vresult = mLayout.scrollVerticallyBy(y, mRecycler, mState); overscrollY = y - vresult; } if (supportsChangeAnimations()) { // Fix up shadow views used by changing animations int count = mChildHelper.getChildCount(); for (int i = 0; i < count; i++) { View view = mChildHelper.getChildAt(i); ViewHolder holder = getChildViewHolder(view); if (holder != null && holder.mShadowingHolder != null) { ViewHolder shadowingHolder = holder.mShadowingHolder; View shadowingView = shadowingHolder != null ? shadowingHolder.itemView : null; if (shadowingView != null) { int left = view.getLeft(); int top = view.getTop(); if (left != shadowingView.getLeft() || top != shadowingView.getTop()) { shadowingView.layout(left, top, left + shadowingView.getWidth(), top + shadowingView.getHeight()); } } } } } mRunningLayoutOrScroll = false; resumeRequestLayout(false); } if (!mItemDecorations.isEmpty()) { invalidate(); } if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) { considerReleasingGlowsOnScroll(x, y); pullGlows(overscrollX, overscrollY); } if (hresult != 0 || vresult != 0) { onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these. if (mScrollListener != null) { mScrollListener.onScrolled(this, hresult, vresult); } } if (!awakenScrollBars()) { invalidate(); } }
From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.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 .ja v a 2s . co m*/ 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) { /*if (null!=mLoadListener) { 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.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
@Override public void computeScroll() { if (mScroller.computeScrollOffset()) { int oldX = getScrollX(); int oldY = getScrollY(); int x = mScroller.getCurrX(); int y = mScroller.getCurrY(); if (oldX != x || oldY != y) { final int range = getScrollRange(); final int overscrollMode = ViewCompat.getOverScrollMode(this); final boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0); overScrollByCompat(x - oldX, y - oldY, oldX, oldY, 0, range, 0, 0, false); if (canOverscroll) { ensureGlows();/*w w w .jav a2 s. c om*/ if (y <= 0 && oldY > 0) { mEdgeGlowTop.onAbsorb((int) mScroller.getCurrVelocity()); } else if (y >= range && oldY < range) { mEdgeGlowBottom.onAbsorb((int) mScroller.getCurrVelocity()); } } } } }
From source file:com.fish.nsd.MyNestedScrollView.java
@Override public void computeScroll() { if (mScroller.computeScrollOffset()) { int oldX = getScrollX(); int oldY = getScrollY(); int x = mScroller.getCurrX(); int y = mScroller.getCurrY(); if (oldX != x || oldY != y) { final int range = getScrollRange(); final int overscrollMode = ViewCompat.getOverScrollMode(this); final boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0); overScrollByCompat(x - oldX, y - oldY, oldX, oldY, 0, range, 0, 0, false); if (canOverscroll) { ensureGlows();/* w w w. j av a 2s . com*/ if (y <= 0 && oldY > 0) { onFlingToTop((int) mScroller.getCurrVelocity()); } else if (y >= range && oldY < range) { onFlingToBottom((int) mScroller.getCurrVelocity()); } } } } }
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
@Override public void computeScroll() { if (mTouchMode == TOUCH_MODE_OVERFLING) { handleOverfling();/*from w ww .j a va2 s. c om*/ } else if (mScroller.computeScrollOffset()) { final int overScrollMode = ViewCompat.getOverScrollMode(this); final boolean supportsOverscroll = overScrollMode != ViewCompat.OVER_SCROLL_NEVER; final int y = mScroller.getCurrY(); final int dy = (int) (y - mLastTouchY); // TODO: Figure out why mLastTouchY is being updated here. Consider using a new class // variable since this value does not represent the last place on the screen where a // touch occurred. mLastTouchY = y; // Check if the top of the motion view is where it is // supposed to be final View motionView = supportsOverscroll && getChildCount() > 0 ? getChildAt(0) : null; final int motionViewPrevTop = motionView != null ? motionView.getTop() : 0; final boolean stopped = !trackMotionScroll(dy, false); if (!stopped && !mScroller.isFinished()) { mTouchMode = TOUCH_MODE_IDLE; ViewCompat.postInvalidateOnAnimation(this); } else if (stopped && dy != 0 && supportsOverscroll) { // Check to see if we have bumped into the scroll limit if (motionView != null) { final int motionViewRealTop = motionView.getTop(); // Apply overscroll final int overscroll = -dy - (motionViewRealTop - motionViewPrevTop); overScrollBy(0, overscroll, 0, getScrollY(), 0, 0, 0, mOverscrollDistance, true); } final EdgeEffectCompat edge; if (dy > 0) { edge = mTopEdge; mBottomEdge.finish(); } else { edge = mBottomEdge; mTopEdge.finish(); } edge.onAbsorb(Math.abs((int) mScroller.getCurrVelocity())); if (mScroller.computeScrollOffset()) { mScroller.notifyVerticalEdgeReached(getScrollY(), 0, mOverscrollDistance); } mTouchMode = TOUCH_MODE_OVERFLING; ViewCompat.postInvalidateOnAnimation(this); } else { mTouchMode = TOUCH_MODE_IDLE; } } }
From source file:de.andacaydin.bidirectionalviewpagerlibrary.BiDirectionalViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270);//from ww w .j ava 2s . c o m canvas.translate(-height + getPaddingTop(), mFirstOffset * width); mLeftEdge.setSize(height, width); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:org.telegram.android.support.widget.RecyclerView.java
/** * Does not perform bounds checking. Used by internal methods that have already validated input. * <p>// w ww.jav a 2s . c om * It also reports any unused scroll request to the related EdgeEffect. * * @param x The amount of horizontal scroll request * @param y The amount of vertical scroll request * @param fromMotionEvent If request is originated from a MotionEvent, this should be set to * true and motionX/motionY should be provided, false otherwise. * @param motionX The x coordinate of the MotionEvent which triggered this scroll. Unused if * fromMotionEvent is false. * @param motionY The y coordinate of the MotionEvent which triggered this scroll. Unused if * fromMotionEvent is false. * * @return Whether any scroll was consumed in either direction. */ boolean scrollByInternal(int x, int y, boolean fromMotionEvent, int motionX, int motionY) { int overscrollX = 0, overscrollY = 0; int hresult = 0, vresult = 0; consumePendingUpdateOperations(); if (mAdapter != null) { eatRequestLayout(); onEnterLayoutOrScroll(); if (x != 0) { hresult = mLayout.scrollHorizontallyBy(x, mRecycler, mState); overscrollX = x - hresult; } if (y != 0) { vresult = mLayout.scrollVerticallyBy(y, mRecycler, mState); overscrollY = y - vresult; } if (supportsChangeAnimations()) { // Fix up shadow views used by changing animations int count = mChildHelper.getChildCount(); for (int i = 0; i < count; i++) { View view = mChildHelper.getChildAt(i); ViewHolder holder = getChildViewHolder(view); if (holder != null && holder.mShadowingHolder != null) { ViewHolder shadowingHolder = holder.mShadowingHolder; View shadowingView = shadowingHolder != null ? shadowingHolder.itemView : null; if (shadowingView != null) { int left = view.getLeft(); int top = view.getTop(); if (left != shadowingView.getLeft() || top != shadowingView.getTop()) { shadowingView.layout(left, top, left + shadowingView.getWidth(), top + shadowingView.getHeight()); } } } } } onExitLayoutOrScroll(); resumeRequestLayout(false); } if (!mItemDecorations.isEmpty()) { invalidate(); } if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) { if (fromMotionEvent) { pullGlows(motionX, overscrollX, motionY, overscrollY); } considerReleasingGlowsOnScroll(x, y); } if (hresult != 0 || vresult != 0) { dispatchOnScrolled(hresult, vresult); } if (!awakenScrollBars()) { invalidate(); } return hresult != 0 || vresult != 0; }
From source file:com.goftagram.telegram.messenger.support.widget.RecyclerView.java
/** * Remove an {@link ItemDecoration} from this RecyclerView. * * <p>The given decoration will no longer impact the measurement and drawing of * item views.</p>// ww w . j a v a 2 s. c o m * * @param decor Decoration to remove * @see #addItemDecoration(ItemDecoration) */ public void removeItemDecoration(ItemDecoration decor) { if (mLayout != null) { mLayout.assertNotInLayoutOrScroll("Cannot remove item decoration during a scroll or" + "layout"); } mItemDecorations.remove(decor); if (mItemDecorations.isEmpty()) { setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER); } markItemDecorInsetsDirty(); requestLayout(); }
From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java
@Override public void computeScroll() { int measuredHeight = getMeasuredHeight(); int measuredWidth = getMeasuredHeight(); if (mScroller.computeScrollOffset()) { int oldX = getScrollX(); int oldY = getScrollY(); int x = mScroller.getCurrX(); int y = mScroller.getCurrY(); if (oldX != x || oldY != y) { final int horizontalRange = getHorizontalScrollRange(); final int verticalRange = getVerticalScrollRange(); final int overscrollMode = ViewCompat.getOverScrollMode(this); final boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && (verticalRange > 0 || horizontalRange > 0)); overScrollByCompat(x - oldX, y - oldY, oldX, oldY, horizontalRange, verticalRange, 0, 0, false); if (canOverscroll) { ensureGlows();// www. jav a2 s. c om if (y <= 0 && oldY > 0) { mEdgeGlowTop.onAbsorb((int) mScroller.getCurrVelocity()); } else if (y >= verticalRange && oldY < verticalRange) { mEdgeGlowBottom.onAbsorb((int) mScroller.getCurrVelocity()); } if (x <= 0 && oldX > 0) { mEdgeGlowLeft.onAbsorb((int) mScroller.getCurrVelocity()); } else if (x >= verticalRange && oldX < horizontalRange) { mEdgeGlowRight.onAbsorb((int) mScroller.getCurrVelocity()); } } } } }
From source file:com.chenglong.muscle.ui.LazyViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(270);/*from w w w .j a va 2s . c o m*/ canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(height, getWidth()); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int itemCount = mAdapter != null ? mAdapter.getCount() : 1; canvas.rotate(90); canvas.translate(-getPaddingTop(), -itemCount * (width + mPageMargin) + mPageMargin); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating invalidate(); } }