Java Code Examples for android.widget.Scroller#fling()

The following examples show how to use android.widget.Scroller#fling() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GravitySnapHelper.java    From GravitySnapHelper with Apache License 2.0 6 votes vote down vote up
@Override
@NonNull
public int[] calculateScrollDistance(int velocityX, int velocityY) {
    if (recyclerView == null
            || (verticalHelper == null && horizontalHelper == null)
            || (maxFlingDistance == FLING_DISTANCE_DISABLE
            && maxFlingSizeFraction == FLING_SIZE_FRACTION_DISABLE)) {
        return super.calculateScrollDistance(velocityX, velocityY);
    }
    final int[] out = new int[2];
    Scroller scroller = new Scroller(recyclerView.getContext(),
            new DecelerateInterpolator());
    int maxDistance = getFlingDistance();
    scroller.fling(0, 0, velocityX, velocityY,
            -maxDistance, maxDistance,
            -maxDistance, maxDistance);
    out[0] = scroller.getFinalX();
    out[1] = scroller.getFinalY();
    return out;
}
 
Example 2
Source File: GravitySnapHelper.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public int[] calculateScrollDistance(int velocityX, int velocityY) {
    if (recyclerView == null
            || (verticalHelper == null && horizontalHelper == null)
            || (maxFlingDistance == FLING_DISTANCE_DISABLE
            && maxFlingSizeFraction == FLING_SIZE_FRACTION_DISABLE)) {
        return super.calculateScrollDistance(velocityX, velocityY);
    }
    final int[] out = new int[2];
    Scroller scroller = new Scroller(recyclerView.getContext(),
            new DecelerateInterpolator());
    int maxDistance = getFlingDistance();
    scroller.fling(0, 0, velocityX, velocityY,
            -maxDistance, maxDistance,
            -maxDistance, maxDistance);
    out[0] = scroller.getFinalX();
    out[1] = scroller.getFinalY();
    return out;
}
 
Example 3
Source File: TouchImageView.java    From ploggy with GNU General Public License v3.0 5 votes vote down vote up
Fling(int velocityX, int velocityY) {
    setState(FLING);
    scroller = new Scroller(context);
    matrix.getValues(m);

    int startX = (int) m[Matrix.MTRANS_X];
    int startY = (int) m[Matrix.MTRANS_Y];
    int minX, maxX, minY, maxY;

    if (getImageWidth() > viewWidth) {
        minX = viewWidth - (int) getImageWidth();
        maxX = 0;

    } else {
        minX = maxX = startX;
    }

    if (getImageHeight() > viewHeight) {
        minY = viewHeight - (int) getImageHeight();
        maxY = 0;

    } else {
        minY = maxY = startY;
    }

    scroller.fling(startX, startY, velocityX, velocityY, minX,
            maxX, minY, maxY);
    currX = startX;
    currY = startY;
}