Example usage for android.support.v4.widget EdgeEffectCompat onPull

List of usage examples for android.support.v4.widget EdgeEffectCompat onPull

Introduction

In this page you can find the example usage for android.support.v4.widget EdgeEffectCompat onPull.

Prototype

public boolean onPull(float deltaDistance) 

Source Link

Document

A view should call this when content is pulled away from an edge by the user.

Usage

From source file:com.android.photos.views.GalleryThumbnailView.java

/**
 *
 * @param deltaX Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 *//*w ww  . jav  a 2  s  . co  m*/
private boolean trackMotionScroll(int deltaX, boolean allowOverScroll) {
    final boolean contentFits = contentFits();
    final int allowOverhang = Math.abs(deltaX);

    final int overScrolledBy;
    final int movedBy;
    if (!contentFits) {
        final int overhang;
        final boolean up;
        mPopulating = true;
        if (deltaX > 0) {
            overhang = fillLeft(mFirstPosition - 1, allowOverhang);
            up = true;
        } else {
            overhang = fillRight(mFirstPosition + getChildCount(), allowOverhang);
            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 = deltaX > 0 ? mLeftEdge : mRightEdge;
                edge.onPull((float) Math.abs(deltaX) / getWidth());
                ViewCompat.postInvalidateOnAnimation(this);
            }
        }
    }

    return deltaX == 0 || movedBy != 0;
}

From source file:cn.ieclipse.af.view.StaggeredGridView.java

/**
 *
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 *//*  ww  w.  j av 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;
    final int movedBy;
    if (!contentFits) {
        final int overhang;
        final boolean up;
        mPopulating = true;
        if (deltaY > 0) {
            overhang = fillUp(mFirstPosition - 1, allowOverhang);
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin;
            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());
                ViewCompat.postInvalidateOnAnimation(this);
            }
        }
    }

    return deltaY == 0 || movedBy != 0;
}

From source file:com.irontec.jaigiro.widgets.StaggeredGridView.java

/**
 * /*from  w  ww  .  j  a  v a 2 s .co  m*/
 * @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);
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin;
            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());
                ViewCompat.postInvalidateOnAnimation(this);
            }
        }
    }

    invokeOnItemScrollListener();

    return deltaY == 0 || movedBy != 0;
}

From source file:com.rajul.staggeredgridview.StaggeredGridView.java

/**
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped
 *         prematurely.//from  ww  w. j a  v a 2 s.co  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) {
        final int overhang;
        final boolean up;
        mPopulating = true;
        if (deltaY > 0) {
            overhang = fillUp(mFirstPosition - 1, allowOverhang);
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin;
            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());
                ViewCompat.postInvalidateOnAnimation(this);
            }
        }
    }

    invokeOnItemScrollListener();
    // TODO
    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:tanglie.mystaggeredgridview.StaggeredGridView.java

/**
 *
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 *///from   w w  w  .j av  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;
    final 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;
            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) {
                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.mcxiaoke.minicat.ui.widget.StaggeredGridView.java

/**
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 *///from  www  .j  a v a2 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) {
        final int overhang;
        final boolean up;
        mPopulating = true;
        if (deltaY > 0) {
            overhang = fillUp(mFirstPosition - 1, allowOverhang);
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin;
            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();
    }

    return deltaY == 0 || movedBy != 0;
}

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

/**
 *
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 *///from   w w w.java2 s.c  om
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) + mItemMargin;
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin;
            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();
    }

    return deltaY == 0 || movedBy != 0;
}

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

/**
 * //  w ww .j  a  va 2s. co  m
 * @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) + mItemMargin;
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin;
            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());
                ViewCompat.postInvalidateOnAnimation(this);
            }
        }
    }

    if (mSelectorPosition != INVALID_POSITION) {
        final int childIndex = mSelectorPosition - mFirstPosition;
        if (childIndex >= 0 && childIndex < getChildCount()) {
            positionSelector(INVALID_POSITION, getChildAt(childIndex));
        }
    } else {
        mSelectorRect.setEmpty();
    }
    invokeOnItemScrollListener();
    return deltaY == 0 || movedBy != 0;
}

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

/**
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 */// ww  w  . ja  va2s  . co  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) {
                    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.cjj.staggeredgridview.StaggeredGridView.java

/**
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 *///from ww w  .  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;
    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 && mLoadListener != null) {
                    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;
}