Ejemplo n.º 1
0
 /** 结束下拉刷新 */
 public void endRefreshing(boolean state) {
   if (mCurrentRefreshStatus == RefreshStatus.REFRESHING) {
     mCurrentRefreshStatus = RefreshStatus.IDLE;
     hiddenRefreshHeaderView();
     handleRefreshStatusChanged();
     mRefreshViewHolder.onEndRefreshing(state);
   }
 }
Ejemplo n.º 2
0
 /** 切换到正在刷新状态,会调用delegate的onBGARefreshLayoutBeginRefreshing方法 */
 public void beginRefreshing() {
   if (mCurrentRefreshStatus != RefreshStatus.REFRESHING && mDelegate != null) {
     mCurrentRefreshStatus = RefreshStatus.REFRESHING;
     changeRefreshHeaderViewToZero();
     handleRefreshStatusChanged();
     mDelegate.onBGARefreshLayoutBeginRefreshing(this);
   }
 }
Ejemplo n.º 3
0
  /**
   * 处理手指抬起事件
   *
   * @return true表示自己消耗掉该事件,false表示不消耗该事件
   */
  private boolean handleActionUpOrCancel(MotionEvent event) {
    boolean isReturnTrue = false;
    // 如果当前头部刷新控件没有完全隐藏,则需要返回true,自己消耗ACTION_UP事件
    if ((mCustomHeaderView == null || (mCustomHeaderView != null && !mIsCustomHeaderViewScrollable))
        && mWholeHeaderView.getPaddingTop() != mMinWholeHeaderViewPaddingTop) {
      isReturnTrue = true;
    }

    if (mCurrentRefreshStatus == RefreshStatus.PULL_DOWN
        || mCurrentRefreshStatus == RefreshStatus.IDLE) {
      // 处于下拉刷新状态,松手时隐藏下拉刷新控件
      if (mCustomHeaderView == null
          || (mCustomHeaderView != null
              && mWholeHeaderView.getPaddingTop() < 0
              && mWholeHeaderView.getPaddingTop() > mMinWholeHeaderViewPaddingTop)) {
        hiddenRefreshHeaderView();
      }
      mCurrentRefreshStatus = RefreshStatus.IDLE;
      handleRefreshStatusChanged();
    } else if (mCurrentRefreshStatus == RefreshStatus.RELEASE_REFRESH) {
      // 处于松开进入刷新状态,松手时完全显示下拉刷新控件,进入正在刷新状态
      beginRefreshing();
    }

    if (mRefreshDownY == -1) {
      mRefreshDownY = (int) event.getY();
    }
    int diffY = (int) event.getY() - mRefreshDownY;
    if (shouldHandleLoadingMore() && diffY <= 0) {
      // 处理上拉加载更多,需要返回true,自己消耗ACTION_UP事件
      isReturnTrue = true;
      beginLoadingMore();
    }

    mWholeHeaderDownY = -1;
    mRefreshDownY = -1;
    return isReturnTrue;
  }
Ejemplo n.º 4
0
  /**
   * 处理手指滑动事件
   *
   * @param event
   * @return true表示自己消耗掉该事件,false表示不消耗该事件
   */
  private boolean handleActionMove(MotionEvent event) {
    if (mCurrentRefreshStatus == RefreshStatus.REFRESHING || mIsLoadingMore) {
      return false;
    }

    if ((mCustomHeaderView == null || !mIsCustomHeaderViewScrollable) && mRefreshDownY == -1) {
      mRefreshDownY = (int) event.getY();
    }
    if (mCustomHeaderView != null
        && mIsCustomHeaderViewScrollable
        && isCustomHeaderViewCompleteVisible()
        && mRefreshDownY == -1) {
      mRefreshDownY = (int) event.getY();
    }

    int refreshDiffY = (int) event.getY() - mRefreshDownY;
    refreshDiffY = (int) (refreshDiffY / mRefreshViewHolder.getPaddingTopScale());

    // 如果是向下拉,并且当前可见的第一个条目的索引等于0,才处理整个头部控件的padding
    if (refreshDiffY > 0 && shouldHandleRefresh() && isCustomHeaderViewCompleteVisible()) {
      int paddingTop = mMinWholeHeaderViewPaddingTop + refreshDiffY;
      if (paddingTop > 0 && mCurrentRefreshStatus != RefreshStatus.RELEASE_REFRESH) {
        // 下拉刷新控件完全显示,并且当前状态没有处于释放开始刷新状态
        mCurrentRefreshStatus = RefreshStatus.RELEASE_REFRESH;
        handleRefreshStatusChanged();

        mRefreshViewHolder.handleScale(1.0f, refreshDiffY);
      } else if (paddingTop < 0) {
        // 下拉刷新控件没有完全显示,并且当前状态没有处于下拉刷新状态
        if (mCurrentRefreshStatus != RefreshStatus.PULL_DOWN) {
          boolean isPreRefreshStatusNotIdle = mCurrentRefreshStatus != RefreshStatus.IDLE;
          mCurrentRefreshStatus = RefreshStatus.PULL_DOWN;
          if (isPreRefreshStatusNotIdle) {
            handleRefreshStatusChanged();
          }
        }
        float scale = 1 - paddingTop * 1.0f / mMinWholeHeaderViewPaddingTop;
        /**
         * 往下滑 paddingTop mMinWholeHeaderViewPaddingTop 到 0 scale 0 到 1 往上滑 paddingTop 0 到
         * mMinWholeHeaderViewPaddingTop scale 1 到 0
         */
        mRefreshViewHolder.handleScale(scale, refreshDiffY);
      }
      paddingTop = Math.min(paddingTop, mMaxWholeHeaderViewPaddingTop);
      mWholeHeaderView.setPadding(0, paddingTop, 0, 0);

      if (mRefreshViewHolder.canChangeToRefreshingStatus()) {
        mWholeHeaderDownY = -1;
        mRefreshDownY = -1;

        beginRefreshing();
      }

      return true;
    }

    if (mCustomHeaderView != null && mIsCustomHeaderViewScrollable) {
      if (mWholeHeaderDownY == -1) {
        mWholeHeaderDownY = (int) event.getY();

        if (mCustomHeaderView != null) {
          mWholeHeaderViewDownPaddingTop = mWholeHeaderView.getPaddingTop();
        }
      }

      int wholeHeaderDiffY = (int) event.getY() - mWholeHeaderDownY;
      if ((mPullDownRefreshEnable && !isWholeHeaderViewCompleteInvisible())
          || (wholeHeaderDiffY > 0 && shouldInterceptToMoveCustomHeaderViewDown())
          || (wholeHeaderDiffY < 0 && shouldInterceptToMoveCustomHeaderViewUp())) {

        int paddingTop = mWholeHeaderViewDownPaddingTop + wholeHeaderDiffY;
        if (paddingTop < mMinWholeHeaderViewPaddingTop - mCustomHeaderView.getMeasuredHeight()) {
          paddingTop = mMinWholeHeaderViewPaddingTop - mCustomHeaderView.getMeasuredHeight();
        }
        mWholeHeaderView.setPadding(0, paddingTop, 0, 0);

        return true;
      }
    }

    return false;
  }