Java Code Examples for android.view.View#OVER_SCROLL_ALWAYS

The following examples show how to use android.view.View#OVER_SCROLL_ALWAYS . 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: ReactScrollViewHelper.java    From react-native-GPay with MIT License 5 votes vote down vote up
public static int parseOverScrollMode(String jsOverScrollMode) {
  if (jsOverScrollMode == null || jsOverScrollMode.equals(AUTO)) {
    return View.OVER_SCROLL_IF_CONTENT_SCROLLS;
  } else if (jsOverScrollMode.equals(OVER_SCROLL_ALWAYS)) {
    return View.OVER_SCROLL_ALWAYS;
  } else if (jsOverScrollMode.equals(OVER_SCROLL_NEVER)) {
    return View.OVER_SCROLL_NEVER;
  } else {
    throw new JSApplicationIllegalArgumentException("wrong overScrollMode: " + jsOverScrollMode);
  }
}
 
Example 2
Source File: NestedScrollView.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        int oldX = getScrollX();
        int oldY = getScrollY();
        int x = mScroller.getCurrX();
        int y = mScroller.getCurrY();
        if (oldX != x || oldY != y) {
            final int range = getScrollRange();
            final int overscrollMode = getOverScrollMode();
            final boolean canOverscroll = overscrollMode == View.OVER_SCROLL_ALWAYS
                    || (overscrollMode == View.OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0);

            overScrollByCompat(x - oldX, y - oldY, oldX, oldY, 0, range,
                    0, 0, false);

            if (canOverscroll) {
                ensureGlows();
                if (y <= 0 && oldY > 0) {
                    mEdgeGlowTop.onAbsorb((int) mScroller.getCurrVelocity());
                } else if (y >= range && oldY < range ) {
                    mEdgeGlowBottom.onAbsorb((int) mScroller.getCurrVelocity());
                }
            }
        } else if (!isFling){
            //回弹过程中有可能会相同,也需要刷新
            //Log.i("you", "postInvalidate...");
            postInvalidate();
        }
    }
}
 
Example 3
Source File: OverScrollGlow.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Pull leftover touch scroll distance into one of the edge glows as appropriate.
 *
 * @param x Current X scroll offset
 * @param y Current Y scroll offset
 * @param oldX Old X scroll offset
 * @param oldY Old Y scroll offset
 * @param maxX Maximum range for horizontal scrolling
 * @param maxY Maximum range for vertical scrolling
 */
public void pullGlow(int x, int y, int oldX, int oldY, int maxX, int maxY) {
    // Only show overscroll bars if there was no movement in any direction
    // as a result of scrolling.
    if (oldX == mHostView.getScrollX() && oldY == mHostView.getScrollY()) {
        // Don't show left/right glows if we fit the whole content.
        // Also don't show if there was vertical movement.
        if (maxX > 0) {
            final int pulledToX = oldX + mOverScrollDeltaX;
            if (pulledToX < 0) {
                mEdgeGlowLeft.onPull((float) mOverScrollDeltaX / mHostView.getWidth());
                if (!mEdgeGlowRight.isFinished()) {
                    mEdgeGlowRight.onRelease();
                }
            } else if (pulledToX > maxX) {
                mEdgeGlowRight.onPull((float) mOverScrollDeltaX / mHostView.getWidth());
                if (!mEdgeGlowLeft.isFinished()) {
                    mEdgeGlowLeft.onRelease();
                }
            }
            mOverScrollDeltaX = 0;
        }

        if (maxY > 0 || mHostView.getOverScrollMode() == View.OVER_SCROLL_ALWAYS) {
            final int pulledToY = oldY + mOverScrollDeltaY;
            if (pulledToY < 0) {
                mEdgeGlowTop.onPull((float) mOverScrollDeltaY / mHostView.getHeight());
                if (!mEdgeGlowBottom.isFinished()) {
                    mEdgeGlowBottom.onRelease();
                }
            } else if (pulledToY > maxY) {
                mEdgeGlowBottom.onPull((float) mOverScrollDeltaY / mHostView.getHeight());
                if (!mEdgeGlowTop.isFinished()) {
                    mEdgeGlowTop.onRelease();
                }
            }
            mOverScrollDeltaY = 0;
        }
    }
}
 
Example 4
Source File: OverScrollGlow.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Absorb leftover fling velocity into one of the edge glows as appropriate.
 *
 * @param x Current X scroll offset
 * @param y Current Y scroll offset
 * @param oldX Old X scroll offset
 * @param oldY Old Y scroll offset
 * @param rangeX Maximum range for horizontal scrolling
 * @param rangeY Maximum range for vertical scrolling
 * @param currentFlingVelocity Current fling velocity
 */
public void absorbGlow(int x, int y, int oldX, int oldY, int rangeX, int rangeY,
        float currentFlingVelocity) {
    if (rangeY > 0 || mHostView.getOverScrollMode() == View.OVER_SCROLL_ALWAYS) {
        if (y < 0 && oldY >= 0) {
            mEdgeGlowTop.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowBottom.isFinished()) {
                mEdgeGlowBottom.onRelease();
            }
        } else if (y > rangeY && oldY <= rangeY) {
            mEdgeGlowBottom.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowTop.isFinished()) {
                mEdgeGlowTop.onRelease();
            }
        }
    }

    if (rangeX > 0) {
        if (x < 0 && oldX >= 0) {
            mEdgeGlowLeft.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowRight.isFinished()) {
                mEdgeGlowRight.onRelease();
            }
        } else if (x > rangeX && oldX <= rangeX) {
            mEdgeGlowRight.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowLeft.isFinished()) {
                mEdgeGlowLeft.onRelease();
            }
        }
    }
}
 
Example 5
Source File: OverScrollGlow.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Pull leftover touch scroll distance into one of the edge glows as appropriate.
 *
 * @param x Current X scroll offset
 * @param y Current Y scroll offset
 * @param oldX Old X scroll offset
 * @param oldY Old Y scroll offset
 * @param maxX Maximum range for horizontal scrolling
 * @param maxY Maximum range for vertical scrolling
 */
public void pullGlow(int x, int y, int oldX, int oldY, int maxX, int maxY) {
    // Only show overscroll bars if there was no movement in any direction
    // as a result of scrolling.
    if (oldX == mHostView.getScrollX() && oldY == mHostView.getScrollY()) {
        // Don't show left/right glows if we fit the whole content.
        // Also don't show if there was vertical movement.
        if (maxX > 0) {
            final int pulledToX = oldX + mOverScrollDeltaX;
            if (pulledToX < 0) {
                mEdgeGlowLeft.onPull((float) mOverScrollDeltaX / mHostView.getWidth());
                if (!mEdgeGlowRight.isFinished()) {
                    mEdgeGlowRight.onRelease();
                }
            } else if (pulledToX > maxX) {
                mEdgeGlowRight.onPull((float) mOverScrollDeltaX / mHostView.getWidth());
                if (!mEdgeGlowLeft.isFinished()) {
                    mEdgeGlowLeft.onRelease();
                }
            }
            mOverScrollDeltaX = 0;
        }

        if (maxY > 0 || mHostView.getOverScrollMode() == View.OVER_SCROLL_ALWAYS) {
            final int pulledToY = oldY + mOverScrollDeltaY;
            if (pulledToY < 0) {
                mEdgeGlowTop.onPull((float) mOverScrollDeltaY / mHostView.getHeight());
                if (!mEdgeGlowBottom.isFinished()) {
                    mEdgeGlowBottom.onRelease();
                }
            } else if (pulledToY > maxY) {
                mEdgeGlowBottom.onPull((float) mOverScrollDeltaY / mHostView.getHeight());
                if (!mEdgeGlowTop.isFinished()) {
                    mEdgeGlowTop.onRelease();
                }
            }
            mOverScrollDeltaY = 0;
        }
    }
}
 
Example 6
Source File: OverScrollGlow.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Absorb leftover fling velocity into one of the edge glows as appropriate.
 *
 * @param x Current X scroll offset
 * @param y Current Y scroll offset
 * @param oldX Old X scroll offset
 * @param oldY Old Y scroll offset
 * @param rangeX Maximum range for horizontal scrolling
 * @param rangeY Maximum range for vertical scrolling
 * @param currentFlingVelocity Current fling velocity
 */
public void absorbGlow(int x, int y, int oldX, int oldY, int rangeX, int rangeY,
        float currentFlingVelocity) {
    if (rangeY > 0 || mHostView.getOverScrollMode() == View.OVER_SCROLL_ALWAYS) {
        if (y < 0 && oldY >= 0) {
            mEdgeGlowTop.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowBottom.isFinished()) {
                mEdgeGlowBottom.onRelease();
            }
        } else if (y > rangeY && oldY <= rangeY) {
            mEdgeGlowBottom.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowTop.isFinished()) {
                mEdgeGlowTop.onRelease();
            }
        }
    }

    if (rangeX > 0) {
        if (x < 0 && oldX >= 0) {
            mEdgeGlowLeft.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowRight.isFinished()) {
                mEdgeGlowRight.onRelease();
            }
        } else if (x > rangeX && oldX <= rangeX) {
            mEdgeGlowRight.onAbsorb((int) currentFlingVelocity);
            if (!mEdgeGlowLeft.isFinished()) {
                mEdgeGlowLeft.onRelease();
            }
        }
    }
}
 
Example 7
Source File: NestedScrollView.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
/**
 * 滑动功能核心代码
 * @param deltaX
 * @param deltaY
 * @param scrollX
 * @param scrollY
 * @param scrollRangeX
 * @param scrollRangeY
 * @param maxOverScrollX
 * @param maxOverScrollY
 * @param isTouchEvent
 * @return
 */
boolean overScrollByCompat(int deltaX, int deltaY,
                           int scrollX, int scrollY,
                           int scrollRangeX, int scrollRangeY,
                           int maxOverScrollX, int maxOverScrollY,
                           boolean isTouchEvent) {
    final int overScrollMode = getOverScrollMode();
    final boolean canScrollHorizontal =
            computeHorizontalScrollRange() > computeHorizontalScrollExtent();
    final boolean canScrollVertical =
            computeVerticalScrollRange() > computeVerticalScrollExtent();
    final boolean overScrollHorizontal = overScrollMode == View.OVER_SCROLL_ALWAYS
            || (overScrollMode == View.OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal);
    final boolean overScrollVertical = overScrollMode == View.OVER_SCROLL_ALWAYS
            || (overScrollMode == View.OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical);

    int newScrollX = scrollX + deltaX;
    if (!overScrollHorizontal) {
        maxOverScrollX = 0;
    }

    //此处修改原码
    if (scrollY < 0 && deltaY < 0) {//偏移往下滑动
        deltaY /= PULLDOWN_SCROLL;
    }

    int newScrollY = scrollY + deltaY;
    if (!overScrollVertical) {
        maxOverScrollY = 0;
    }

    // Clamp values if at the limits and record
    final int left = -maxOverScrollX;
    final int right = maxOverScrollX + scrollRangeX;
    //此处修改原码
    int top;
    if (isFling) {
        top = - maxOverScrollY;
    } else {
        top = -getPulldownScroll();
    }

    final int bottom = maxOverScrollY + scrollRangeY;

    boolean clampedX = false;
    if (newScrollX > right) {
        newScrollX = right;
        clampedX = true;
    } else if (newScrollX < left) {
        newScrollX = left;
        clampedX = true;
    }

    boolean clampedY = false;
    if (newScrollY > bottom) {//滑动越出界限
        newScrollY = bottom;
        clampedY = true;
    } else if (newScrollY < top) {
        newScrollY = top;
        clampedY = true;
    }

    if (clampedY && isFling) {//这里isFling时才回弹
        //Log.i("you", top + "  " + bottom + "  "+deltaY+" "+newScrollY+" "+getScrollRange());
        mScroller.springBack(newScrollX, newScrollY, 0, 0, 0, getScrollRange());
    }
    onOverScrolled(newScrollX, newScrollY, clampedX, clampedY);
    return clampedX || clampedY;
}