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

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

Introduction

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

Prototype

public static int getOverScrollMode(View v) 

Source Link

Document

Returns the over-scroll mode for this view.

Usage

From source file:android.improving.utils.views.cardsview.OrientedViewPager.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 (mOrientation == Orientation.VERTICAL) {
            if (!mTopLeftEdge.isFinished()) {
                final int restoreCount = canvas.save();
                final int height = getHeight();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();

                canvas.translate(getPaddingLeft(), mFirstOffset * height);
                mTopLeftEdge.setSize(width, height);
                needsInvalidate |= mTopLeftEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            }//from  w ww .  j  av a 2s.c om
            if (!mRightBottomEdge.isFinished()) {
                final int restoreCount = canvas.save();
                final int height = getHeight();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();

                canvas.rotate(180);
                canvas.translate(-width - getPaddingLeft(), -(mLastOffset + 1) * height);
                mRightBottomEdge.setSize(width, height);
                needsInvalidate |= mRightBottomEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            }
        } else {
            if (!mTopLeftEdge.isFinished()) {
                final int restoreCount = canvas.save();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();
                final int width = getWidth();

                canvas.rotate(270);
                canvas.translate(-height + getPaddingTop(), mFirstOffset * width);
                mTopLeftEdge.setSize(height, width);
                needsInvalidate |= mTopLeftEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            }
            if (!mRightBottomEdge.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);
                mRightBottomEdge.setSize(height, width);
                needsInvalidate |= mRightBottomEdge.draw(canvas);
                canvas.restoreToCount(restoreCount);
            }
        }
    } else {
        mTopLeftEdge.finish();
        mRightBottomEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

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

private void updateOverScrollState(int delta, int overscroll) {
    overScrollByInternal((mIsVertical ? 0 : overscroll), (mIsVertical ? overscroll : 0),
            (mIsVertical ? 0 : mOverScroll), (mIsVertical ? mOverScroll : 0), 0, 0,
            (mIsVertical ? 0 : mOverscrollDistance), (mIsVertical ? mOverscrollDistance : 0), true);

    if (Math.abs(mOverscrollDistance) == Math.abs(mOverScroll)) {
        // Break fling velocity if we impacted an edge
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();/*from  www  . ja v a  2  s .  c  om*/
        }
    }

    final int overscrollMode = ViewCompat.getOverScrollMode(this);
    if (overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits())) {
        mTouchMode = TOUCH_MODE_OVERSCROLL;

        float pull = (float) overscroll / (mIsVertical ? getHeight() : getWidth());
        if (delta > 0) {
            mStartEdge.onPull(pull);

            if (!mEndEdge.isFinished()) {
                mEndEdge.onRelease();
            }
        } else if (delta < 0) {
            mEndEdge.onPull(pull);

            if (!mStartEdge.isFinished()) {
                mStartEdge.onRelease();
            }
        }

        if (delta != 0) {
            ViewCompat.postInvalidateOnAnimation(this);
        }
    }
}

From source file:com.artifex.mupdflib.TwoWayView.java

private void updateOverScrollState(int delta, int overscroll) {
    overScrollByInternal((mIsVertical ? 0 : overscroll), (mIsVertical ? overscroll : 0),
            (mIsVertical ? 0 : mOverScroll), (mIsVertical ? mOverScroll : 0), 0, 0,
            (mIsVertical ? 0 : mOverscrollDistance), (mIsVertical ? mOverscrollDistance : 0), true);

    if (Math.abs(mOverscrollDistance) == Math.abs(mOverScroll)) {
        // Break fling velocity if we impacted an edge
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();/*from  w ww  .j a v  a  2 s .co  m*/
        }
    }

    final int overscrollMode = ViewCompat.getOverScrollMode(this);
    if (overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits())) {
        mTouchMode = TOUCH_MODE_OVERSCROLL;

        float pull = (float) overscroll / getSize();
        if (delta > 0) {
            mStartEdge.onPull(pull);

            if (!mEndEdge.isFinished()) {
                mEndEdge.onRelease();
            }
        } else if (delta < 0) {
            mEndEdge.onPull(pull);

            if (!mStartEdge.isFinished()) {
                mStartEdge.onRelease();
            }
        }

        if (delta != 0) {
            ViewCompat.postInvalidateOnAnimation(this);
        }
    }
}

From source file:dev.dworks.libs.widget.ViewPager.java

private void drawHorizontally(Canvas 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);// ww  w. j  a  va  2  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);
    }
}

From source file:dev.dworks.libs.widget.ViewPager.java

private void drawVertically(Canvas 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 (!mTopEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();

            //canvas.rotate(270);
            //canvas.translate(-height + getPaddingTop(), mFirstOffset * width);
            mTopEdge.setSize(width, height);
            needsInvalidate |= mTopEdge.draw(canvas);
            //canvas.restoreToCount(restoreCount);
        }//from  w w  w.j  a v a  2  s . c  o m
        if (!mBottomEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();

            //FIXME
            //canvas.rotate(90);
            //canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width);
            //canvas.rotate(180);
            //canvas.translate(-(mLastOffset + 1) * height, -getPaddingRight());

            mBottomEdge.setSize(width, height);
            needsInvalidate |= mBottomEdge.draw(canvas);
            //canvas.restoreToCount(restoreCount);
        }
    } else {
        mTopEdge.finish();
        mBottomEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

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

@Override
public void computeScroll() {
    if (!mScroller.computeScrollOffset()) {
        return;//from w  ww .  ja  v a2 s.c om
    }

    final int pos;
    if (mIsVertical) {
        pos = mScroller.getCurrY();
    } else {
        pos = mScroller.getCurrX();
    }

    final int diff = (int) (pos - mLastTouchPos);
    mLastTouchPos = pos;

    final boolean stopped = scrollListItemsBy(diff);

    if (!stopped && !mScroller.isFinished()) {
        ViewCompat.postInvalidateOnAnimation(this);
    } else {
        if (stopped) {
            final int overScrollMode = ViewCompat.getOverScrollMode(this);
            if (overScrollMode != ViewCompat.OVER_SCROLL_NEVER) {
                final EdgeEffectCompat edge = (diff > 0 ? mStartEdge : mEndEdge);

                boolean needsInvalidate = edge.onAbsorb(Math.abs((int) getCurrVelocity()));

                if (needsInvalidate) {
                    ViewCompat.postInvalidateOnAnimation(this);
                }
            }

            mScroller.abortAnimation();
        }

        mTouchMode = TOUCH_MODE_REST;
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
    }
}

From source file:com.artifex.mupdf.view.ThumbnailViews.java

@Override
public void computeScroll() {
    if (!mScroller.computeScrollOffset()) {
        return;/*ww  w. j a  v  a 2 s. co m*/
    }

    final int pos;
    if (mIsVertical) {
        pos = mScroller.getCurrY();
    } else {
        pos = mScroller.getCurrX();
    }

    final int diff = (int) (pos - mLastTouchPos);
    mLastTouchPos = pos;

    final boolean stopped = trackMotionScroll(diff);

    if (!stopped && !mScroller.isFinished()) {
        ViewCompat.postInvalidateOnAnimation(this);
    } else {
        if (stopped) {
            final int overScrollMode = ViewCompat.getOverScrollMode(this);
            if (overScrollMode != ViewCompat.OVER_SCROLL_NEVER) {
                final EdgeEffectCompat edge = (diff > 0 ? mStartEdge : mEndEdge);

                boolean needsInvalidate = edge.onAbsorb(Math.abs((int) getCurrVelocity()));

                if (needsInvalidate) {
                    ViewCompat.postInvalidateOnAnimation(this);
                }
            }

            mScroller.abortAnimation();
        }

        mTouchMode = TOUCH_MODE_REST;
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
    }
}

From source file:com.artifex.mupdflib.TwoWayView.java

@Override
public void computeScroll() {
    if (!mScroller.computeScrollOffset()) {
        return;//from  w w w.ja va2  s . c om
    }

    final int pos;
    if (mIsVertical) {
        pos = mScroller.getCurrY();
    } else {
        pos = mScroller.getCurrX();
    }

    final int diff = (int) (pos - mLastTouchPos);
    mLastTouchPos = pos;

    final boolean stopped = scrollListItemsBy(diff);

    if (!stopped && !mScroller.isFinished()) {
        ViewCompat.postInvalidateOnAnimation(this);
    } else {
        if (stopped) {
            final int overScrollMode = ViewCompat.getOverScrollMode(this);
            if (overScrollMode != ViewCompat.OVER_SCROLL_NEVER) {
                final EdgeEffectCompat edge = (diff > 0 ? mStartEdge : mEndEdge);

                boolean needsInvalidate = edge.onAbsorb(Math.abs((int) getCurrVelocity()));

                if (needsInvalidate) {
                    ViewCompat.postInvalidateOnAnimation(this);
                }
            }

            finishSmoothScrolling();
        }

        mTouchMode = TOUCH_MODE_REST;
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
    }
}