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:cn.ismartv.recyclerview.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScrollContainer(true);/*from   ww w .  j  av a 2  s  . c  o m*/
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    mPostUpdatesOnAnimation = version >= 16;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER);

    mItemAnimator.setListener(mItemAnimatorListener);
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this));
    // Create the layoutManager if specified.
    if (attrs != null) {
        int defStyleRes = 0;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyle, defStyleRes);
        String layoutManagerName = a.getString(R.styleable.RecyclerView_layoutManager);
        a.recycle();
        createLayoutManager(context, layoutManagerName, attrs, defStyle, defStyleRes);
    }

    mScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:android.support.v7.widget.RecyclerView.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 */// w  w w .  ja v  a  2  s  .  c  o m
void scrollByInternal(int x, int y) {
    int overscrollX = 0, overscrollY = 0;
    consumePendingUpdateOperations();
    if (mAdapter != null) {
        eatRequestLayout();
        if (x != 0) {
            final int hresult = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
            overscrollX = x - hresult;
        }
        if (y != 0) {
            final int vresult = mLayout.scrollVerticallyBy(y, mRecycler, mState);
            overscrollY = y - vresult;
        }
        resumeRequestLayout(false);
    }

    if (!mItemDecorations.isEmpty()) {
        invalidate();
    }
    if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        pullGlows(overscrollX, overscrollY);
    }
    if (mScrollListener != null && (x != 0 || y != 0)) {
        mScrollListener.onScrolled(x, y);
    }
    if (!awakenScrollBars()) {
        invalidate();
    }
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void init(Context ctx, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mUiHandler = new Handler(Looper.getMainLooper(), mMessenger);
    if (!isInEditMode()) {
        mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    }/*from  w w w  .  j  a v a  2s . c  om*/

    final Resources res = getResources();
    final Resources.Theme theme = ctx.getTheme();

    mTickFormats = getResources().getStringArray(R.array.tlcDefTickLabelFormats);
    mTickLabels = getResources().getStringArray(R.array.tlcDefTickLabelValues);

    final DisplayMetrics dp = getResources().getDisplayMetrics();
    mSize8 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8, dp);
    mSize12 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, dp);
    mSize20 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, dp);

    final ViewConfiguration vc = ViewConfiguration.get(ctx);
    mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
    mTouchSlop = vc.getScaledTouchSlop() / 2;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mScroller = new OverScroller(ctx);

    int graphBgColor = ContextCompat.getColor(ctx, R.color.tlcDefGraphBackgroundColor);
    int footerBgColor = ContextCompat.getColor(ctx, R.color.tlcDefFooterBackgroundColor);

    mDefFooterBarHeight = mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight);
    mShowFooter = res.getBoolean(R.bool.tlcDefShowFooter);
    mGraphMode = res.getInteger(R.integer.tlcDefGraphMode);
    mPlaySelectionSoundEffect = res.getBoolean(R.bool.tlcDefPlaySelectionSoundEffect);
    mSelectionSoundEffectSource = res.getInteger(R.integer.tlcDefSelectionSoundEffectSource);
    mAnimateCursorTransition = res.getBoolean(R.bool.tlcDefAnimateCursorTransition);
    mFollowCursorPosition = res.getBoolean(R.bool.tlcDefFollowCursorPosition);
    mAlwaysEnsureSelection = res.getBoolean(R.bool.tlcDefAlwaysEnsureSelection);

    mGraphAreaBgPaint = new Paint();
    mGraphAreaBgPaint.setColor(graphBgColor);
    mFooterAreaBgPaint = new Paint();
    mFooterAreaBgPaint.setColor(footerBgColor);
    mTickLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mTickLabelFgPaint.setFakeBoldText(true);
    mTickLabelFgPaint.setColor(MaterialPaletteHelper.isDarkColor(footerBgColor) ? Color.LTGRAY : Color.DKGRAY);

    mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth);
    mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace);

    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.tlcTimelineChartView, defStyleAttr,
            defStyleRes);
    try {
        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.tlcTimelineChartView_tlcGraphBackground) {
                graphBgColor = a.getColor(attr, graphBgColor);
                mGraphAreaBgPaint.setColor(graphBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcShowFooter) {
                mShowFooter = a.getBoolean(attr, mShowFooter);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBackground) {
                footerBgColor = a.getColor(attr, footerBgColor);
                mFooterAreaBgPaint.setColor(footerBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBarHeight) {
                mFooterBarHeight = a.getDimension(attr, mFooterBarHeight);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcGraphMode) {
                mGraphMode = a.getInt(attr, mGraphMode);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAnimateCursorTransition) {
                mAnimateCursorTransition = a.getBoolean(attr, mAnimateCursorTransition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFollowCursorPosition) {
                mFollowCursorPosition = a.getBoolean(attr, mFollowCursorPosition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAlwaysEnsureSelection) {
                mAlwaysEnsureSelection = a.getBoolean(attr, mAlwaysEnsureSelection);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemWidth) {
                mBarItemWidth = a.getDimension(attr, mBarItemWidth);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemSpace) {
                mBarItemSpace = a.getDimension(attr, mBarItemSpace);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcPlaySelectionSoundEffect) {
                mPlaySelectionSoundEffect = a.getBoolean(attr, mPlaySelectionSoundEffect);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcSelectionSoundEffectSource) {
                mSelectionSoundEffectSource = a.getInt(attr, mSelectionSoundEffectSource);
            }
        }
    } finally {
        a.recycle();
    }

    // SurfaceView requires a background
    if (getBackground() == null) {
        setBackgroundColor(ContextCompat.getColor(ctx, android.R.color.transparent));
    }

    // Minimize the impact of create dynamic layouts by assume that in most case
    // we will have a day formatter
    mTickHasDayFormat = true;

    // Initialize stuff
    setupBackgroundHandler();
    setupTickLabels();
    if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        setupEdgeEffects();
    }
    setupAnimators();
    setupSoundEffects();

    // Initialize the drawing refs (this will be update when we have
    // the real size of the canvas)
    computeBoundAreas();

    // Create a fake data for the edit mode
    if (isInEditMode()) {
        setupViewInEditMode();
    }
}

From source file:cn.iterlog.myapplication.widget.overscroll.StaggeredGridView.java

public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        final int y = mScroller.getCurrY();
        final int dy = (int) (y - mLastTouchY);
        mLastTouchY = y;/*from w ww.j  a  v a 2 s  . c  o m*/
        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;
        }
    }
}

From source file:com.b44t.messenger.support.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScrollContainer(true);//ww w  .j  a va2s  . c  o m
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    mPostUpdatesOnAnimation = version >= 16;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER);

    mItemAnimator.setListener(mItemAnimatorListener);
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this));
    // Create the layoutManager if specified.

    // Re-set whether nested scrolling is enabled so that it is set on all API levels
    setNestedScrollingEnabled(true);
}

From source file:chan.android.app.bitwise.util.StaggeredGridView.java

@Override
public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        final int y = mScroller.getCurrY();
        final int dy = (int) (y - mLastTouchY);
        mLastTouchY = y;//from   w w  w .j  a  v  a 2 s .co m
        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;
        }
    }
}

From source file:android.support.v71.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    LogUtil.e("---------------RecyclerView  --------------------- ");
    //   //ww w .j  a v  a 2 s  . c o m
    setScrollContainer(true);
    //  touch ?
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    //TODO  > 16  ? 
    mPostUpdatesOnAnimation = version >= 16;

    // ?  ? ??
    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();

    // ?   ?
    setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER);

    // ?
    mItemAnimator.setListener(mItemAnimatorListener);
    // ? adapter Manager
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    // ,  RecycleView ??  accessibility
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    // ?  AccessibilityManager ? ?,  ? ??,  ?  app ?
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new android.support.v71.widget.RecyclerViewAccessibilityDelegate(this));
    // Create the layoutManager if specified.
    if (attrs != null) {
        int defStyleRes = 0;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyle, defStyleRes);
        //xml ?  LayoutManager
        String layoutManagerName = a.getString(R.styleable.RecyclerView_layoutManager);
        a.recycle();
        createLayoutManager(context, layoutManagerName, attrs, defStyle, defStyleRes);
    }

    // 
    mScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:com.app.afteryou.ui.staggered.StaggeredGridView.java

public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        final int y = mScroller.getCurrY();
        final int dy = (int) (y - mLastTouchY);
        mLastTouchY = y;/*w ww  .j a va2  s. c  o  m*/
        final boolean stopped = !trackMotionScroll(dy, false);
        if (!stopped && !mScroller.isFinished()) {
            invokeOnItemScrollListener();
            ViewCompat.postInvalidateOnAnimation(this);
        } 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()));
                    ViewCompat.postInvalidateOnAnimation(this);
                }
                mScroller.abortAnimation();
            }
            setTouchMode(TOUCH_MODE_IDLE);
        }
    }
}

From source file:mrfu.blurstaggered.lib.view.StaggeredGridView.java

@Override
public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        final int y = mScroller.getCurrY();
        final int dy = (int) (y - mLastTouchY);
        mLastTouchY = y;//from  w  w w  .  j  a  v a  2 s .co m
        final boolean stopped = !trackMotionScroll(dy, false);

        if (!stopped && !mScroller.isFinished()) {
            //TODO MrFu
            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(TOUCH_MODE_IDLE);
        }
    }
}

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);
                    }// ww  w.jav a 2  s .com
                }
                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());
        }
    }
}