@SuppressWarnings("MagicConstant")
  private IcsLinearLayout findOrInitializeLayout(final View convertView) {
    IcsLinearLayout layout;

    if (convertView == null || !(convertView instanceof IcsLinearLayout)) {
      layout = new IcsLinearLayout(context, null);
      if (listView.isDebugging()) layout.setBackgroundColor(Color.parseColor("#83F27B"));

      layout.setShowDividers(IcsLinearLayout.SHOW_DIVIDER_MIDDLE);
      layout.setDividerDrawable(
          context.getResources().getDrawable(R.drawable.item_divider_horizontal));

      layout.setLayoutParams(
          new AbsListView.LayoutParams(
              AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT));
    } else layout = (IcsLinearLayout) convertView;

    // Clear all layout children before starting
    for (int j = 0; j < layout.getChildCount(); j++) {
      IcsLinearLayout tempChild = (IcsLinearLayout) layout.getChildAt(j);
      linearLayoutPool.put(tempChild);
      for (int k = 0; k < tempChild.getChildCount(); k++) viewPool.put(tempChild.getChildAt(k));
      tempChild.removeAllViews();
    }
    layout.removeAllViews();

    return layout;
  }
 public void updateTab(int position) {
   ((TabView) mTabLayout.getChildAt(position)).update();
   if (mTabSpinner != null) {
     ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged();
   }
   if (mAllowCollapse) {
     requestLayout();
   }
 }
 public void setTabSelected(int position) {
   mSelectedTabIndex = position;
   final int tabCount = mTabLayout.getChildCount();
   for (int i = 0; i < tabCount; i++) {
     final View child = mTabLayout.getChildAt(i);
     final boolean isSelected = i == position;
     child.setSelected(isSelected);
     if (isSelected) {
       animateToTab(position);
     }
   }
 }
 private void animateToTab(final int position) {
   final View tabView = mTabLayout.getChildAt(position);
   if (mTabSelector != null) {
     removeCallbacks(mTabSelector);
   }
   mTabSelector =
       new Runnable() {
         public void run() {
           final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;
           smoothScrollTo(scrollPos, 0);
           mTabSelector = null;
         }
       };
   post(mTabSelector);
 }
 private void animateToIcon(final int position) {
   final View iconView = mIconsLayout.getChildAt(position);
   if (mIconSelector != null) {
     removeCallbacks(mIconSelector);
   }
   mIconSelector =
       new Runnable() {
         public void run() {
           final int scrollPos = iconView.getLeft() - (getWidth() - iconView.getWidth()) / 2;
           smoothScrollTo(scrollPos, 0);
           mIconSelector = null;
         }
       };
   post(mIconSelector);
 }
  @Override
  public void setCurrentItem(int item) {
    if (mViewPager == null) {
      throw new IllegalStateException("ViewPager has not been bound.");
    }
    mSelectedTabIndex = item;
    mViewPager.setCurrentItem(item);

    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
      final View child = mTabLayout.getChildAt(i);
      final boolean isSelected = (i == item);
      child.setSelected(isSelected);
      if (isSelected) {
        animateToTab(item);
      }
    }
  }