List of usage examples for android.support.v4.view ViewCompat getOverScrollMode
public static int getOverScrollMode(View v)
From source file:com.dishes.views.stageredggridview.StaggeredGridView.java
/** * /*from w ww . j av a2 s . c om*/ * @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; }
From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java
@Override public void computeScroll() { // Log.d("TAG", "----------------scroller-----------" + mScroller.computeScrollOffset()); // Log.d("qz", "----------------scroller-----------" + mScroller.computeScrollOffset()+",first="+getFirstVisiblePosition()+",last="+getLastPosition()); // LogUtil.d("TAG---------------onTouch finish-----------" + mScroller.isFinished()); int firstVisibleItem = getFirstVisiblePosition(); int lastVisibleItem = getLastPosition(); if (mScroller.isFinished()) { if (mFlingListener != null) { if (isOnTouch) return; if (mIsFling) { // LogUtil.d("---------------------" + getLastPosition()); if (mOnExposeChanged != null) { if (lastVisibleItem != -1) { mOnExposeChanged.exposeChanged(lastVisibleItem); }/* w ww .j a v a2 s . c om*/ } mIsFling = false; } mFlingListener.endFling(); } } else { if (mFlingListener != null) { mFlingListener.onFling(); } } //? if (mOnScrollListener != null) { mOnScrollListener.onScroll(firstVisibleItem, lastVisibleItem); } if (mScroller.computeScrollOffset()) { final int y = mScroller.getCurrY(); final int dy = (int) (y - mLastTouchY); mLastTouchY = y; final boolean stopped = !trackMotionScroll(dy, false); if (!stopped && !mScroller.isFinished()) { postInvalidate(); } else { if (stopped) { final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode != ViewCompat.OVER_SCROLL_NEVER) { final EdgeEffectCompat edge; if (dy > 0) { edge = mTopEdge; } else { edge = mBottomEdge; } edge.onAbsorb(Math.abs((int) mScroller.getCurrVelocity())); postInvalidate(); } mScroller.abortAnimation(); } mTouchMode = TOUCH_MODE_IDLE; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); // Log.d("TAG", "----------------scroller1111111-----------" + mScroller.computeScrollOffset()); } } }
From source file:com.android.backups.BackupStaggeredGridView.java
@Override public void computeScroll() { if (mScroller.computeScrollOffset()) { final int y = mScroller.getCurrY(); final int dy = (int) (y - mLastTouchY); mLastTouchY = y;//w w w .j a v a 2 s .co m final boolean stopped = !trackMotionScroll(dy, false); if (!stopped && !mScroller.isFinished()) { invokeOnItemScrollListener(); postInvalidate(); } else { if (stopped) { final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode != ViewCompat.OVER_SCROLL_NEVER) { final EdgeEffectCompat edge; if (dy > 0) { edge = mTopEdge; } else { edge = mBottomEdge; } edge.onAbsorb(Math.abs((int) mScroller.getCurrVelocity())); postInvalidate(); } mScroller.abortAnimation(); } mTouchMode = TOUCH_MODE_IDLE; setTouchMode(mTouchMode); } } }
From source file:android.support.v7.widget.RecyclerViewEx.java
/** * Remove an {@link android.support.v7.widget.RecyclerViewEx.ItemDecoration} from this RecyclerViewEx. * * <p>The given decoration will no longer impact the measurement and drawing of * item views.</p>/*from ww w . j a v a2 s . c o m*/ * * @param decor Decoration to remove * @see #addItemDecoration(android.support.v7.widget.RecyclerViewEx.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.jzh.stuapp.view.MyViewPager.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) { invalidate(); } }
From source file:com.ruesga.timelinechart.TimelineChartView.java
private void onOverScroll() { final boolean needOverScroll; synchronized (mLock) { needOverScroll = mData.size() >= Math.floor(mMaxBarItemsInScreen / 2); }//from w w w .ja v a2 s .com final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && needOverScroll)) { boolean needsInvalidate = false; if (mCurrentOffset > mMaxOffset) { mEdgeEffectLeft.onPull(mCurrentOffset - mMaxOffset); needsInvalidate = true; } if (mCurrentOffset < 0) { mEdgeEffectRight.onPull(mCurrentOffset); needsInvalidate = true; } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } } }
From source file:com.yimeng.babymom.view.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 av a2s .c om*/ canvas.translate(-height + getPaddingTop(), 0); mLeftEdge.setSize(getWidth(), height); 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(width, height); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating invalidate(); } }
From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.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 ww w . j a v a2s .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(); } }
From source file:com.ruesga.timelinechart.TimelineChartView.java
/** {@inheritDoc} */ @Override/*from w ww .j a v a2s . c o m*/ public void computeScroll() { super.computeScroll(); // Ignore any scroll while performing scrolling animation if (mState == STATE_ZOOMING) { return; } // Determine whether we still scrolling and needs a viewport refresh final boolean scrolling = mScroller.computeScrollOffset(); if (scrolling) { float x = mScroller.getCurrX(); if (x > mMaxOffset || x < 0) { return; } mCurrentOffset = x; ViewCompat.postInvalidateOnAnimation(this); } else if (mState > STATE_MOVING) { boolean needsInvalidate = false; final boolean needOverScroll; synchronized (mLock) { needOverScroll = mData.size() >= Math.floor(mMaxBarItemsInScreen / 2); } final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (needOverScroll && overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS)) { float x = mScroller.getCurrX(); if (x >= mMaxOffset && mEdgeEffectLeft.isFinished() && !mEdgeEffectLeftActive) { mEdgeEffectLeft.onAbsorb((int) mScroller.getCurrVelocity()); mEdgeEffectLeftActive = true; needsInvalidate = true; } if (x <= 0 && mEdgeEffectRight.isFinished() && !mEdgeEffectRightActive) { mEdgeEffectRight.onAbsorb((int) mScroller.getCurrVelocity()); mEdgeEffectRightActive = true; needsInvalidate = true; } } if (!needsInvalidate) { // Reset state mState = STATE_IDLE; mLastTimestamp = -1; } else { ViewCompat.postInvalidateOnAnimation(this); } } long timestamp = computeTimestampFromOffset(mCurrentOffset); // If we are not centered in a item, perform an scroll if (mAlwaysEnsureSelection && mState == STATE_IDLE) { timestamp = computeNearestTimestampFromOffset(mCurrentOffset); smoothScrollTo(timestamp); } if (mCurrentTimestamp != timestamp) { // Don't perform selection operations while we are just scrolling if (mState != STATE_SCROLLING) { boolean fromUser = mCurrentTimestamp != -2; mCurrentTimestamp = timestamp; if (fromUser) { performSelectionSoundEffect(); } // Notify any valid item, but only notify invalid items if // we are not panning/scrolling if (mCurrentTimestamp >= 0 || !scrolling) { Message.obtain(mUiHandler, MSG_ON_SELECTION_ITEM_CHANGED, fromUser).sendToTarget(); } } } }
From source file:app.umitems.greenclock.widget.sgv.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 a v a 2s . c o m 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) { int overhang; final boolean up; mPopulating = true; if (deltaY > 0) { overhang = fillUp(mFirstPosition - 1, allowOverhang); up = true; } else { overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang); if (overhang < 0) { // Overhang when filling down indicates how many pixels past the bottom of the // screen has been filled in. If this value is negative, it should be set to // 0 so that we don't allow over scrolling. overhang = 0; } 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) { final EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge; edge.onPull((float) Math.abs(deltaY) / getHeight()); ViewCompat.postInvalidateOnAnimation(this); } } } awakenScrollBars(0 /* show immediately */, true /* invalidate */); return deltaY == 0 || movedBy != 0; }