/**
   * 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() {
    // We need to use the correct LayoutParam values, based on scroll
    // direction
    final LinearLayout.LayoutParams lp = getLoadingLayoutLayoutParams();

    // Remove Header, and then add Header Loading View again if needed
    if (this == mHeaderLayout.getParent()) {
      removeView(mHeaderLayout);
    }
    if (mMode.showHeaderLoadingLayout()) {
      addViewInternal(mHeaderLayout, 0, lp);
    }

    // Remove Footer, and then add Footer Loading View again if needed
    if (this == mFooterLayout.getParent()) {
      removeView(mFooterLayout);
    }
    if (mMode.showFooterLoadingLayout()) {
      addViewInternal(mFooterLayout, lp);
    }

    // Hide Loading Views
    refreshLoadingViewsSize();

    // If we're not using Mode.BOTH, set mCurrentMode to mMode, otherwise
    // set it to pull down
    mCurrentMode = (mMode != Mode.BOTH) ? mMode : Mode.PULL_FROM_START;
  }
  private void addRefreshableView(Context context, T refreshableView) {
    mRefreshableViewWrapper = new FrameLayout(context);
    mRefreshableViewWrapper.addView(
        refreshableView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    addViewInternal(
        mRefreshableViewWrapper,
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  }