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

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

Introduction

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

Prototype

int OVER_SCROLL_NEVER

To view the source code for android.support.v4.view ViewCompat OVER_SCROLL_NEVER.

Click Source Link

Document

Never allow a user to over-scroll this view.

Usage

From source file:com.aliasapps.seq.scroller.TwoWayView.java

@Override
@TargetApi(9)/*w w  w  .  ja v  a  2 s .  c  o m*/
public void setOverScrollMode(int mode) {
    if (Build.VERSION.SDK_INT < 9) {
        return;
    }

    if (mode != ViewCompat.OVER_SCROLL_NEVER) {
        if (mStartEdge == null) {
            Context context = getContext();

            mStartEdge = new EdgeEffectCompat(context);
            mEndEdge = new EdgeEffectCompat(context);
        }
    } else {
        mStartEdge = null;
        mEndEdge = null;
    }

    super.setOverScrollMode(mode);
}

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;/*from  w  ww.  java2  s . c  o 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  av  a2s. co  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:android.support.v7.widget.RecyclerViewEx.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 *//*from  www . j  a v  a  2  s  . 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:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

@Override
public void computeScroll() {
    if (mTouchMode == TOUCH_MODE_OVERFLING) {
        handleOverfling();/*from   w ww  .j a v a2 s . c o  m*/
    } 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:org.telegram.android.support.widget.RecyclerView.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 * <p>//  w w w  . j  ava  2 s. c  o m
 * 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>//from w w w. j a  v a2 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.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

private void ensureGlows() {
    if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        if (mEdgeGlowTop == null) {
            Context context = getContext();
            mEdgeGlowTop = new EdgeEffectCompat(context);
            mEdgeGlowBottom = new EdgeEffectCompat(context);
        }//from w ww . ja  va 2 s . co  m
    } else {
        mEdgeGlowTop = null;
        mEdgeGlowBottom = null;
    }
}

From source file:org.nekC.android.support.widget.RecyclerView.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 * <p>//from   w  w  w  .j a va  2s  . co m
 * 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 ev The originating MotionEvent, or null if not from a touch event.
 *
 * @return Whether any scroll was consumed in either direction.
 */
boolean scrollByInternal(int x, int y, MotionEvent ev) {
    int unconsumedX = 0, unconsumedY = 0;
    int consumedX = 0, consumedY = 0;

    consumePendingUpdateOperations();
    if (mAdapter != null) {
        eatRequestLayout();
        onEnterLayoutOrScroll();
        if (x != 0) {
            consumedX = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
            unconsumedX = x - consumedX;
        }
        if (y != 0) {
            consumedY = mLayout.scrollVerticallyBy(y, mRecycler, mState);
            unconsumedY = y - consumedY;
        }
        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 (dispatchNestedScroll(consumedX, consumedY, unconsumedX, unconsumedY, mScrollOffset)) {
        // Update the last touch co-ords, taking any scroll offset into account
        mLastTouchX -= mScrollOffset[0];
        mLastTouchY -= mScrollOffset[1];
        ev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
        mNestedOffsets[0] += mScrollOffset[0];
        mNestedOffsets[1] += mScrollOffset[1];
    } else if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        if (ev != null) {
            pullGlows(ev.getX(), unconsumedX, ev.getY(), unconsumedY);
        }
        considerReleasingGlowsOnScroll(x, y);
    }
    if (consumedX != 0 || consumedY != 0) {
        dispatchOnScrolled(consumedX, consumedY);
    }
    if (!awakenScrollBars()) {
        invalidate();
    }
    return consumedX != 0 || consumedY != 0;
}

From source file:com.goftagram.telegram.messenger.support.widget.RecyclerView.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 * <p>/*from   w  w  w .j  a  v a  2 s  . c  o m*/
 * 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 ev The originating MotionEvent, or null if not from a touch event.
 *
 * @return Whether any scroll was consumed in either direction.
 */
boolean scrollByInternal(int x, int y, MotionEvent ev) {
    int unconsumedX = 0, unconsumedY = 0;
    int consumedX = 0, consumedY = 0;

    consumePendingUpdateOperations();
    if (mAdapter != null) {
        eatRequestLayout();
        onEnterLayoutOrScroll();
        if (x != 0) {
            consumedX = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
            unconsumedX = x - consumedX;
        }
        if (y != 0) {
            consumedY = mLayout.scrollVerticallyBy(y, mRecycler, mState);
            unconsumedY = y - consumedY;
        }
        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 (dispatchNestedScroll(consumedX, consumedY, unconsumedX, unconsumedY, mScrollOffset)) {
        // Update the last touch co-ords, taking any scroll offset into account
        mLastTouchX -= mScrollOffset[0];
        mLastTouchY -= mScrollOffset[1];
        if (ev != null) {
            ev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
        }
        mNestedOffsets[0] += mScrollOffset[0];
        mNestedOffsets[1] += mScrollOffset[1];
    } else if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        if (ev != null) {
            pullGlows(ev.getX(), unconsumedX, ev.getY(), unconsumedY);
        }
        considerReleasingGlowsOnScroll(x, y);
    }
    if (consumedX != 0 || consumedY != 0) {
        dispatchOnScrolled(consumedX, consumedY);
    }
    if (!awakenScrollBars()) {
        invalidate();
    }
    return consumedX != 0 || consumedY != 0;
}