Esempio n. 1
0
  /**
   * Checks if the edge glow should be used enabled. The glow is not enabled unless there are more
   * views than can fit on the screen at one time.
   */
  private boolean isEdgeGlowEnabled() {
    if (mAdapter == null || mAdapter.isEmpty()) return false;

    // If the maxx is more then zero then the user can scroll, so the edge
    // effects should be shown
    return mMaxX > 0;
  }
Esempio n. 2
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int newHeight = 0;
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    if (heightMode != MeasureSpec.EXACTLY) {
      ListAdapter listAdapter = getAdapter();
      if (listAdapter != null && !listAdapter.isEmpty()) {
        int listPosition = 0;
        for (listPosition = 0;
            listPosition < listAdapter.getCount() && listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE;
            listPosition++) {
          View listItem = listAdapter.getView(listPosition, null, this);
          // now it will not throw a NPE if listItem is a ViewGroup instance
          if (listItem instanceof ViewGroup) {
            listItem.setLayoutParams(
                new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
          }
          listItem.measure(widthMeasureSpec, heightMeasureSpec);
          newHeight += listItem.getMeasuredHeight();
        }
        newHeight += getDividerHeight() * listPosition;
      }
      if ((heightMode == MeasureSpec.AT_MOST) && (newHeight > heightSize)) {
        if (newHeight > heightSize) {
          newHeight = heightSize;
        }
      }
    } else {
      newHeight = getMeasuredHeight();
    }
    setMeasuredDimension(getMeasuredWidth(), newHeight);
  }
Esempio n. 3
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);
    }
  }
Esempio n. 4
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();
  }
  @Override
  protected void resetHeader() {

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

    LoadingLayout originalLoadingLayout;
    LoadingLayout listViewLoadingLayout;

    int scrollToHeight = getHeaderHeight();
    final boolean doScroll;

    switch (getCurrentMode()) {
      case MODE_PULL_UP_TO_REFRESH:
        originalLoadingLayout = getFooterLayout();
        listViewLoadingLayout = mFooterLoadingView;
        doScroll = isReadyForPullUp();
        break;
      case MODE_PULL_DOWN_TO_REFRESH:
      default:
        originalLoadingLayout = getHeaderLayout();
        listViewLoadingLayout = mHeaderLoadingView;
        scrollToHeight *= -1;
        doScroll = isReadyForPullDown();
        break;
    }

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

    // Scroll so our View is at the same Y as the ListView header/footer,
    // but only scroll if the ListView is at the top/bottom
    if (doScroll) {
      setHeaderScroll(scrollToHeight);
    }

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

    super.resetHeader();
  }
  @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();
        //				smoothScrollTo(0);
        smoothScrollTo(getFooterSize());
        break;
      case PULL_FROM_START:
      default:
        origLoadingView = getHeaderLayout();
        listViewLoadingView = mHeaderLoadingView;
        oppositeListViewLoadingView = mFooterLoadingView;
        selection = 0;
        scrollToY = (int) (getScrollY() + getHeaderSize() * LoadingLayout.SCALE_REFRESHING);
        smoothScrollTo((int) (-getHeaderSize() * LoadingLayout.SCALE_REFRESHING));
        break;
    }
    oppositeListViewLoadingView.setVisibility(View.GONE);
  }
 @Override
 public boolean isEmpty() {
   return mAdapter == null || mAdapter.isEmpty();
 }
Esempio n. 8
0
 @Override
 public boolean isEmpty() {
   return wrapped.isEmpty();
 }
Esempio n. 9
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);
    }
  }
 @Override
 public boolean isEmpty() {
   return mBaseAdapter.isEmpty();
 }
Esempio n. 11
0
 @Override
 public boolean isEmpty() {
   return (mAdapter == null || mAdapter.isEmpty()) && getHeadersCount() == 0;
 }