Ejemplo 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();
        }
      }
    }
Ejemplo n.º 2
0
  /**
   * Helper method which just calls scrollTo() in the correct scrolling direction.
   *
   * @param value - New Scroll value
   */
  protected final void setHeaderScroll(int value) {
    if (DEBUG) {
      Log.d(LOG_TAG, "setHeaderScroll: " + value);
    }

    // Clamp value to with pull scroll range
    final int maximumPullScroll = getMaximumPullScroll();
    value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

    if (mLayoutVisibilityChangesEnabled) {
      if (value < 0) {
        mHeaderLayout.setVisibility(View.VISIBLE);
      } else if (value > 0) {
        mFooterLayout.setVisibility(View.VISIBLE);
      } else {
        mHeaderLayout.setVisibility(View.INVISIBLE);
        mFooterLayout.setVisibility(View.INVISIBLE);
      }
    }

    if (USE_HW_LAYERS) {
      /**
       * Use a Hardware Layer on the Refreshable View if we've scrolled at all. We don't use them on
       * the Header/Footer Views as they change often, which would negate any HW layer performance
       * boost.
       */
      ViewCompat.setLayerType(
          mRefreshableViewWrapper, value != 0 ? 2 /*
                                                                             * View.
                                                                             * LAYER_TYPE_HARDWARE
                                                                             */ : 0 /* View.LAYER_TYPE_NONE */);
    }

    switch (getPullToRefreshScrollDirection()) {
      case VERTICAL:
        scrollTo(0, value);
        break;
      case HORIZONTAL:
        scrollTo(value, 0);
        break;
    }
  }
Ejemplo n.º 3
0
 public final void setHeaderBackground(Drawable backgroundDrawable) {
   ViewCompat.setBackground(mHeaderLayout, backgroundDrawable);
 }