/**
   * Updates the View State when the mode has been set. This does not do any checking that the mode
   * is different to current state so always updates.
   */
  protected void updateUIForMode() {
    // Remove Header, and then add Header Loading View again if needed
    if (this == mHeaderLayout.getParent()) {
      removeView(mHeaderLayout);
    }
    if (mMode.canPullDown()) {
      LinearLayout.LayoutParams llp =
          new LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      llp.setMargins(mMargin, 0, mMargin, 0);
      addViewInternal(mHeaderLayout, 0, llp);
    }

    // Remove Footer, and then add Footer Loading View again if needed
    if (this == mFooterLayout.getParent()) {
      removeView(mFooterLayout);
    }
    if (mMode.canPullUp()) {
      LinearLayout.LayoutParams llp =
          new LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      llp.setMargins(mMargin, 0, mMargin, 0);
      addViewInternal(mFooterLayout, 0, llp);
    }

    // Hide Loading Views
    refreshLoadingViewsHeight();

    // If we're not using Mode.BOTH, set mCurrentMode to mMode, otherwise
    // set it to pull down
    mCurrentMode = (mMode != Mode.BOTH) ? mMode : Mode.PULL_DOWN_TO_REFRESH;
  }
  /**
   * Set the drawable used in the loading layout.
   *
   * @param drawable - Drawable to display
   * @param mode - Controls which Header/Footer Views will be updated. <code>Mode.BOTH</code> will
   *     update all available, other values will update the relevant View.
   */
  public void setLoadingDrawable(Drawable drawable, Mode mode) {
    if (null != mHeaderLayout && mode.canPullDown()) {
      mHeaderLayout.setLoadingDrawable(drawable);
    }
    if (null != mFooterLayout && mode.canPullUp()) {
      mFooterLayout.setLoadingDrawable(drawable);
    }

    // The Loading Height may have changed, so refresh
    refreshLoadingViewsHeight();
  }
  /**
   * Set the Last Updated Text. This displayed under the main label when Pulling
   *
   * @param label - Label to set
   */
  public void setLastUpdatedLabel(CharSequence label) {
    if (null != mHeaderLayout) {
      mHeaderLayout.setSubHeaderText(label);
    }
    if (null != mFooterLayout) {
      mFooterLayout.setSubHeaderText(label);
    }

    // Refresh Height as it may have changed
    refreshLoadingViewsHeight();
  }