Esempio n. 1
0
    @Override
    public void run() {

      /**
       * Only set mStartTime if this is the first time we're starting, else actually calculate the Y
       * delta
       */
      if (mStartTime == -1) {
        mStartTime = System.currentTimeMillis();
      } else {

        /**
         * We do do all calculations in long to reduce software float calculations. We use 1000 as
         * it gives us good accuracy and small rounding errors
         */
        long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
        normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

        final int deltaY =
            Math.round(
                (mScrollFromY - mScrollToY)
                    * mInterpolator.getInterpolation(normalizedTime / 1000f));
        mCurrentY = mScrollFromY - deltaY;
        setHeaderScroll(mCurrentY);
      }

      // If we're not at the target Y, keep going...
      if (mContinueRunning && mScrollToY != mCurrentY) {
        ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
      } else {
        if (null != mListener) {
          mListener.onSmoothScrollFinished();
        }
      }
    }