public void addTabs(TabInfo... tabInfos) {
    if (tabInfos == null || tabInfos.length < 1) {
      return;
    }

    for (TabInfo tabInfo : tabInfos) {
      if (tabInfo == null) {
        break;
      }

      View page = tabInfo.getPage();
      View item = tabInfo.getItem();

      item.setOnClickListener(onSelectorClickListener);
      if (page instanceof Pageable) {
        Pageable pageable = (Pageable) page;
        pageable.onInit(this);
      }

      ViewGroup.LayoutParams itemParams = tabInfo.getItemParams();
      if (itemParams == null) {
        itemBar.addView(item);
      } else {
        itemBar.addView(item, itemParams);
      }
      adapter.add(page);

      tabs.add(new Pair<View, View>(item, page));
    }

    onGlobalLayout();
  }
  public boolean removeTab(int index) {
    if (index < 0 || index >= tabs.size()) {
      return false;
    }

    Pair<View, View> tab = tabs.remove(index);
    if (tab != null) {
      itemBar.removeView(tab.first);
      adapter.remove(adapter.getIndexOfItem(tab.second));
      if (selector != null) {
        selector.remove(index);
      }
      onGlobalLayout();
      return true;
    }
    return false;
  }
 public boolean removeAll() {
   tabs.clear();
   itemBar.removeAllViews();
   adapter.removeAll();
   if (selector != null) {
     selector.removeAll();
   }
   onGlobalLayout();
   return true;
 }
 public int getCurrentTab() {
   int index = -1;
   int size = tabs.size();
   View page = adapter.getItem(pager.getCurrentItem());
   for (int i = 0; i < size; i++) {
     Pair<View, View> tab = tabs.get(i);
     if (tab.second == page) {
       index = i;
       break;
     }
   }
   return index;
 }
  public void addTab(int index, TabInfo tabInfo) {
    if (tabInfo == null) {
      return;
    }

    View page = tabInfo.getPage();
    View item = tabInfo.getItem();

    item.setOnClickListener(onSelectorClickListener);
    if (page instanceof Pageable) {
      Pageable pageable = (Pageable) page;
      pageable.onInit(this);
    }

    if (index < 0 || index >= adapter.getCount()) {
      ViewGroup.LayoutParams itemParams = tabInfo.getItemParams();
      if (itemParams == null) {
        itemBar.addView(item);
      } else {
        itemBar.addView(item, itemParams);
      }
      adapter.add(page);
    } else {
      ViewGroup.LayoutParams itemParams = tabInfo.getItemParams();
      if (itemParams == null) {
        itemBar.addView(item, index);
      } else {
        itemBar.addView(item, index, itemParams);
      }
      adapter.add(index, page);
    }

    tabs.add(new Pair<View, View>(item, page));

    onGlobalLayout();
  }
 @Override
 public void onClick(View v) {
   for (Pair<View, View> pair : tabs) {
     if (pair.first == v) {
       int pageIndex = adapter.getIndexOfItem(pair.second);
       if (pageIndex == pager.getCurrentItem()) {
         if (v instanceof Checkable) {
           ((Checkable) v).setChecked(true);
         }
       } else {
         pager.setCurrentItem(pageIndex, isPageSmoothScroll);
       }
       break;
     }
   }
 }
        @Override
        public void onPageSelected(int position) {
          View page = adapter.getItem(position);

          int tab_size = tabs.size();
          for (int index = 0; index < tab_size; index++) {
            Pair<View, View> tab = tabs.get(index);
            if (page == tab.second) {
              setCurrentTab(index);
              // TODO denan.wang; 2015/2/13;
              if (page instanceof Pageable) {
                ((Pageable) page).onSelected(TabController.this);
              }
              // END
              // TODO denan.wang; 2015/2/13;
              if (listener != null) {
                listener.onTabChanged(TabController.this);
              }
              // END
              return;
            }
          }
          clearItemState();
        }