예제 #1
1
 // Returns the distance that over the scroll limit.
 public int startScroll(int distance, int min, int max) {
   int currPosition = mScroller.getCurrX();
   int finalPosition = mScroller.isFinished() ? currPosition : mScroller.getFinalX();
   int newPosition = Utils.clamp(finalPosition + distance, min, max);
   if (newPosition != currPosition) {
     mScroller.startScroll(currPosition, 0, newPosition - currPosition, 0, 0);
   }
   return finalPosition + distance - newPosition;
 }
예제 #2
0
  /** Animates the stack scroll */
  void animateScroll(float curScroll, float newScroll, final Runnable postRunnable) {
    // Finish any current scrolling animations
    Log.d(TAG, "animateScroll: ");
    if (mScrollAnimator != null && mScrollAnimator.isRunning()) {
      setStackScroll(mFinalAnimatedScroll);
      mScroller.startScroll(0, progressToScrollRange(mFinalAnimatedScroll), 0, 0, 0);
    }
    stopScroller();
    stopBoundScrollAnimation();

    mFinalAnimatedScroll = newScroll;
    mScrollAnimator = ObjectAnimator.ofFloat(this, "stackScroll", curScroll, newScroll);
    mScrollAnimator.setDuration(mConfig.taskStackScrollDuration);
    mScrollAnimator.setInterpolator(mConfig.linearOutSlowInInterpolator);
    mScrollAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            setStackScroll((Float) animation.getAnimatedValue());
          }
        });
    mScrollAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            if (postRunnable != null) {
              postRunnable.run();
            }
            mScrollAnimator.removeAllListeners();
          }
        });
    mScrollAnimator.start();
  }
예제 #3
0
 public static void startScroll(
     Object paramObject,
     int paramInt1,
     int paramInt2,
     int paramInt3,
     int paramInt4,
     int paramInt5) {
   ((OverScroller) paramObject).startScroll(paramInt1, paramInt2, paramInt3, paramInt4, paramInt5);
 }
  public void fling(int velocityX) {
    if (getChildCount() > 0) {
      int width = getWidth() - getPaddingRight() - getPaddingLeft();
      int right = getChildAt(0).getWidth();

      if (DEBUG) {
        Log.d(TAG, "fling -> velocityX = " + velocityX);
        Log.d(TAG, "fling -> getScrollX() = " + getScrollX());
      }
      mScroller.fling(
          getScrollX(),
          getScrollY(),
          velocityX,
          0,
          0,
          Math.max(0, right - width),
          0,
          0,
          width / 2,
          0);

      int finalX = mScroller.getFinalX();
      int overX = 0;
      if (finalX <= 0 || finalX >= scrollPositionOfMostRecent()) {
        overX = width / 2;
      }

      finalX = getScrollXFromFinalX(finalX);
      if (DEBUG) {
        Log.d(TAG, "fling -> finalX = " + finalX);
      }
      mScroller.startScroll(
          getScrollX(), getScrollY(), finalX - getScrollX(), 0, getScrollTime(finalX));
      final boolean movingRight = velocityX > 0;

      postInvalidateOnAnimation();
    }
  }
예제 #5
0
 public void setPosition(int position) {
   mScroller.startScroll(position, 0, 0, 0, 0);
   // This forces the scroller to reach the final position.
   mScroller.abortAnimation();
 }
 @Override
 protected void _startUsingDistance(int initialX, int distance) {
   mScroller.startScroll(initialX, 0, distance, 0, mAnimationDuration);
 }
 /**
  * Start scrolling by providing a starting point and the distance to travel. The scroll will use
  * the default value of 250 milliseconds for the duration.
  *
  * @param startX Starting horizontal scroll offset in pixels. Positive numbers will scroll the
  *     content to the left.
  * @param startY Starting vertical scroll offset in pixels. Positive numbers will scroll the
  *     content up.
  * @param dx Horizontal distance to travel. Positive numbers will scroll the content to the left.
  * @param dy Vertical distance to travel. Positive numbers will scroll the content up.
  */
 public void startScroll(int startX, int startY, int dx, int dy) {
   startScroll(startX, startY, dx, dy, DEFAULT_DURATION);
 }