コード例 #1
0
  private boolean checkCanRefresh() {
    LayoutManager layoutManager = getLayoutManager();
    Adapter adapter = getAdapter();
    if (adapter != null && layoutManager != null) {

      int firstVisiblePosition = calculateFirstVisiblePosition(layoutManager);
      Log.d(TAG, "firstVisiblePosition" + firstVisiblePosition);
      if (!checkIsLoadMore()
          && firstVisiblePosition == (mRefreshHeader.getVisibleHeaderHeight() == 0 ? 1 : 0)
          && mRefreshHeader.getRefreshState() != REFRESH_STATE_REFRESHING) {

        return true;
      }
    }

    return false;
  }
コード例 #2
0
  @Override
  public boolean onTouchEvent(MotionEvent e) {
    if (mRefreshEnable || mLoadMoreEnable) {
      switch (e.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
          mDownMotionEventY = (int) e.getRawY();
          break;

        case MotionEvent.ACTION_MOVE:
          mCurMotionEventY = (int) e.getRawY();

          if (mLoadMoreEnable && mCurMotionEventY - mDownMotionEventY < -20) {
            mIsUpFlag = true;
          }

          if (mLoadMoreEnable && checkCanLoadMore()) {
            Log.e(TAG, "checkLoadMore");
            showLoadMoreView();
          }

          if (mRefreshEnable && checkCanRefresh()) {
            Log.d(TAG, "canRefresh");
            mRefreshHeader.move(
                (mCurMotionEventY - mDownMotionEventY) / 2, mCurMotionEventY, mDownMotionEventY);
          }

          break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          if (mRefreshHeader != null
              && mRefreshHeader.getRefreshState() != REFRESH_STATE_REFRESHING) {
            mRefreshHeader.upOrCancel(mRefreshDataListener);
          }

          mIsUpFlag = false;
          break;
      }
    }

    return super.onTouchEvent(e);
  }
コード例 #3
0
 public void completeRefresh() {
   if (mRefreshHeader != null) {
     mRefreshHeader.completeRefresh();
   }
 }
コード例 #4
0
 public boolean checkIsPullToRefresh() {
   return mRefreshEnable
       && mRefreshHeader != null
       && mRefreshHeader.getRefreshState() != REFRESH_STATE_IDLE;
 }