コード例 #1
0
  @Override
  protected void setRefreshingInternal(boolean doScroll) {

    // If we're not showing the Refreshing view, or the list is empty, then
    // the header/footer views won't show so we use the
    // normal method
    ListAdapter adapter = mRefreshableView.getAdapter();
    if (!getShowViewWhileRefreshing() || null == adapter || adapter.isEmpty()) {
      super.setRefreshingInternal(doScroll);
      return;
    }

    super.setRefreshingInternal(false);

    final LoadingLayout originalLoadingLayout, listViewLoadingLayout;
    final int selection, scrollToY;

    switch (getCurrentMode()) {
      case PULL_UP_TO_REFRESH:
        originalLoadingLayout = getFooterLayout();
        listViewLoadingLayout = mFooterLoadingView;
        selection = mRefreshableView.getCount() - 1;
        scrollToY = getScrollY() - getHeaderHeight();
        break;
      case PULL_DOWN_TO_REFRESH:
      default:
        originalLoadingLayout = getHeaderLayout();
        listViewLoadingLayout = mHeaderLoadingView;
        selection = 0;
        scrollToY = getScrollY() + getHeaderHeight();
        break;
    }

    if (doScroll) {
      // We scroll slightly so that the ListView's header/footer is at the
      // same Y position as our normal header/footer
      setHeaderScroll(scrollToY);
    }

    // Hide our original Loading View
    originalLoadingLayout.setVisibility(View.INVISIBLE);

    // Show the ListView Loading View and set it to refresh
    listViewLoadingLayout.setVisibility(View.VISIBLE);
    listViewLoadingLayout.refreshing();

    if (doScroll) {
      // Make sure the ListView is scrolled to show the loading
      // header/footer
      mRefreshableView.setSelection(selection);

      // Smooth scroll as normal
      smoothScrollTo(0);
    }
  }
コード例 #2
0
  @Override
  protected void onReset() {
    /** If the extras are not enabled, just call up to super and return. */
    if (!mListViewExtrasEnabled) {
      super.onReset();
      return;
    }

    final LoadingLayout originalLoadingLayout, listViewLoadingLayout;
    final int scrollToHeight, selection;
    final boolean scrollLvToEdge;

    switch (getCurrentMode()) {
      case MANUAL_REFRESH_ONLY:
      case PULL_FROM_END:
        originalLoadingLayout = getFooterLayout();
        listViewLoadingLayout = mFooterLoadingView;
        selection = mRefreshableView.getCount() - 1;
        scrollToHeight = getFooterSize();
        scrollLvToEdge = Math.abs(mRefreshableView.getLastVisiblePosition() - selection) <= 1;
        break;
      case PULL_FROM_START:
      default:
        originalLoadingLayout = getHeaderLayout();
        listViewLoadingLayout = mHeaderLoadingView;
        scrollToHeight = -getHeaderSize();
        selection = 0;
        scrollLvToEdge = Math.abs(mRefreshableView.getFirstVisiblePosition() - selection) <= 1;
        break;
    }

    // If the ListView header loading layout is showing, then we need to
    // flip so that the original one is showing instead
    if (listViewLoadingLayout.getVisibility() == View.VISIBLE) {

      // Set our Original View to Visible
      originalLoadingLayout.showInvisibleViews();

      // Hide the ListView Header/Footer
      listViewLoadingLayout.setVisibility(View.GONE);

      /**
       * Scroll so the View is at the same Y as the ListView header/footer, but only scroll if:
       * we've pulled to refresh, it's positioned correctly
       */
      if (scrollLvToEdge && getState() != State.MANUAL_REFRESHING) {
        mRefreshableView.setSelection(selection);
        setHeaderScroll(scrollToHeight);
      }
    }

    // Finally, call up to super
    super.onReset();
  }
コード例 #3
0
  @Override
  protected void resetHeader() {

    // If we're not showing the Refreshing view, or the list is empty, then
    // the header/footer views won't show so we use the
    // normal method
    ListAdapter adapter = mRefreshableView.getAdapter();
    if (!getShowViewWhileRefreshing() || null == adapter || adapter.isEmpty()) {
      super.resetHeader();
      return;
    }

    LoadingLayout originalLoadingLayout;
    LoadingLayout listViewLoadingLayout;

    int scrollToHeight = getHeaderHeight();
    int selection;
    boolean scroll;

    switch (getCurrentMode()) {
      case PULL_UP_TO_REFRESH:
        originalLoadingLayout = getFooterLayout();
        listViewLoadingLayout = mFooterLoadingView;
        selection = mRefreshableView.getCount() - 1;
        scroll = mRefreshableView.getLastVisiblePosition() == selection;
        break;
      case PULL_DOWN_TO_REFRESH:
      default:
        originalLoadingLayout = getHeaderLayout();
        listViewLoadingLayout = mHeaderLoadingView;
        scrollToHeight *= -1;
        selection = 0;
        scroll = mRefreshableView.getFirstVisiblePosition() == selection;
        break;
    }

    // Set our Original View to Visible
    originalLoadingLayout.setVisibility(View.VISIBLE);

    /**
     * Scroll so the View is at the same Y as the ListView header/footer, but only scroll if we've
     * pulled to refresh and it's positioned correctly
     */
    if (scroll && getState() != MANUAL_REFRESHING) {
      mRefreshableView.setSelection(selection);
      setHeaderScroll(scrollToHeight);
    }

    // Hide the ListView Header/Footer
    listViewLoadingLayout.setVisibility(View.GONE);

    super.resetHeader();
  }
コード例 #4
0
  @Override
  protected void handleStyledAttributes(TypedArray a) {
    super.handleStyledAttributes(a);

    mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true);

    if (mListViewExtrasEnabled) {
      final FrameLayout.LayoutParams lp =
          new FrameLayout.LayoutParams(
              FrameLayout.LayoutParams.MATCH_PARENT,
              FrameLayout.LayoutParams.WRAP_CONTENT,
              Gravity.CENTER_HORIZONTAL);

      // Create Loading Views ready for use later
      FrameLayout frame = new FrameLayout(getContext());
      mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a);
      mHeaderLoadingView.setVisibility(View.GONE);
      frame.addView(mHeaderLoadingView, lp);
      mRefreshableView.addHeaderView(frame, null, false);

      mLvFooterLoadingFrame = new FrameLayout(getContext());
      mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a);
      mFooterLoadingView.setVisibility(View.GONE);
      mLvFooterLoadingFrame.addView(mFooterLoadingView, lp);

      /**
       * If the value for Scrolling While Refreshing hasn't been explicitly set via XML, enable
       * Scrolling While Refreshing.
       */
      if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) {
        setScrollingWhileRefreshingEnabled(true);
      }
    }
  }
コード例 #5
0
  public void setReleaseLabel(String releaseLabel, Mode mode) {
    super.setReleaseLabel(releaseLabel, mode);

    if (null != mHeaderLoadingView && mode.canPullDown()) {
      mHeaderLoadingView.setReleaseLabel(releaseLabel);
    }
    if (null != mFooterLoadingView && mode.canPullUp()) {
      mFooterLoadingView.setReleaseLabel(releaseLabel);
    }
  }
コード例 #6
0
  public void setRefreshingLabel(String refreshingLabel) {
    super.setRefreshingLabel(refreshingLabel);

    if (null != mHeaderLoadingView) {
      mHeaderLoadingView.setRefreshingLabel(refreshingLabel);
    }
    if (null != mFooterLoadingView) {
      mFooterLoadingView.setRefreshingLabel(refreshingLabel);
    }
  }
コード例 #7
0
  public void setPullLabel(String pullLabel) {
    super.setPullLabel(pullLabel);

    if (null != mHeaderLoadingView) {
      mHeaderLoadingView.setPullLabel(pullLabel);
    }
    if (null != mFooterLoadingView) {
      mFooterLoadingView.setPullLabel(pullLabel);
    }
  }
コード例 #8
0
  @Override
  protected void onRefreshing(final boolean doScroll) {
    /**
     * If we're not showing the Refreshing view, or the list is empty, the the header/footer views
     * won't show so we use the normal method.
     */
    ListAdapter adapter = mRefreshableView.getAdapter();
    if (!mListViewExtrasEnabled
        || !getShowViewWhileRefreshing()
        || null == adapter
        || adapter.isEmpty()) {
      super.onRefreshing(doScroll);
      return;
    }

    super.onRefreshing(false);

    final LoadingLayout origLoadingView, listViewLoadingView, oppositeListViewLoadingView;
    final int selection, scrollToY;

    switch (getCurrentMode()) {
      case MANUAL_REFRESH_ONLY:
      case PULL_FROM_END:
        origLoadingView = getFooterLayout();
        listViewLoadingView = mFooterLoadingView;
        oppositeListViewLoadingView = mHeaderLoadingView;
        selection = mRefreshableView.getCount() - 1;
        scrollToY = getScrollY() - getFooterSize();
        break;
      case PULL_FROM_START:
      default:
        origLoadingView = getHeaderLayout();
        listViewLoadingView = mHeaderLoadingView;
        oppositeListViewLoadingView = mFooterLoadingView;
        selection = 0;
        scrollToY = getScrollY() + getHeaderSize();
        break;
    }

    // Hide our original Loading View
    origLoadingView.reset();
    origLoadingView.hideAllViews();

    // Make sure the opposite end is hidden too
    oppositeListViewLoadingView.setVisibility(View.GONE);

    // Show the ListView Loading View and set it to refresh.
    listViewLoadingView.setVisibility(View.VISIBLE);
    listViewLoadingView.refreshing();

    if (doScroll) {
      // We need to disable the automatic visibility changes for now
      disableLoadingLayoutVisibilityChanges();

      // We scroll slightly so that the ListView's header/footer is at the
      // same Y position as our normal header/footer
      setHeaderScroll(scrollToY);

      // Make sure the ListView is scrolled to show the loading
      // header/footer
      mRefreshableView.setSelection(selection);

      // Smooth scroll as normal
      smoothScrollTo(0);
    }
  }