Exemplo n.º 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);
    }
  }