Exemplo n.º 1
0
 private void updateHeaderHeight(float delta) {
   mHeaderView.setVisiableHeight((int) delta + mHeaderView.getVisiableHeight());
   if (mEnablePullRefresh && !mPullRefreshing) { // 未处于刷新状态,更新箭头
     if (mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
       mHeaderView.setState(NewListViewHeader.STATE_READY);
     } else {
       mHeaderView.setState(NewListViewHeader.STATE_NORMAL);
     }
   }
   setSelection(0); // scroll to top each time
 }
Exemplo n.º 2
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (mLastY == -1) {
      mLastY = ev.getRawY();
    }

    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mLastY = ev.getRawY();
        break;
      case MotionEvent.ACTION_MOVE:
        final float deltaY = ev.getRawY() - mLastY;
        mLastY = ev.getRawY();
        if (getFirstVisiblePosition() == 0 && (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {
          // the first item is showing, header has shown or pull down.
          updateHeaderHeight(deltaY / OFFSET_RADIO);
          invokeOnScrolling();
        } else if (getLastVisiblePosition() == mTotalItemCount - 1
            && (mFooterView.getBottomMargin() > 0 || deltaY < 0)) {
          // last item, already pulled up or want to pull up.
          updateFooterHeight(-deltaY / OFFSET_RADIO);
        }
        break;
      default:
        mLastY = -1; // reset
        if (getFirstVisiblePosition() == 0) {
          // invoke refresh
          if (mEnablePullRefresh && mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
            mPullRefreshing = true;
            mHeaderView.setState(NewListViewHeader.STATE_REFRESHING);
            if (mListViewListener != null) {
              mListViewListener.onRefresh();
            }
          }
          resetHeaderHeight();
        } else if (getLastVisiblePosition() == mTotalItemCount - 1) {
          // invoke load more.
          if (mEnablePullLoad && mFooterView.getBottomMargin() > PULL_LOAD_MORE_DELTA) {
            startLoadMore();
          }
          resetFooterHeight();
        }
        break;
    }
    return super.onTouchEvent(ev);
  }