Example usage for android.support.v4.view ViewCompat OVER_SCROLL_IF_CONTENT_SCROLLS

List of usage examples for android.support.v4.view ViewCompat OVER_SCROLL_IF_CONTENT_SCROLLS

Introduction

In this page you can find the example usage for android.support.v4.view ViewCompat OVER_SCROLL_IF_CONTENT_SCROLLS.

Prototype

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

Document

Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll.

Usage

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  v a 2 s.com
            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);
    }// w w  w.  jav  a 2s  .c om
    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   www .ja  v  a  2  s .co  m
            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);/* www  . j  av a 2 s  .com*/
            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  ava 2s .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.
 *//* w  w w . j ava 2  s  . 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;
}

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.
 *//*w  ww . j a v  a  2 s.  c o 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();//from  w ww . j  av  a 2  s  .  c  o  m
                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  .ja v  a2  s .  c o  m
                if (y <= 0 && oldY > 0) {
                    onFlingToTop((int) mScroller.getCurrVelocity());

                } else if (y >= range && oldY < range) {
                    onFlingToBottom((int) mScroller.getCurrVelocity());
                }
            }
        }
    }
}

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  a v a2  s.  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);
    }
}