private void addTabToGroup(TiUITabGroup tg, TabProxy tab) {
    TiTabActivity tta = weakActivity.get();
    if (tta == null) {
      if (DBG) {
        Log.w(LCAT, "Could not add tab because tab activity no longer exists");
      }
    }
    Drawable icon =
        TiDrawableReference.fromObject(getTiContext(), tab.getProperty(TiC.PROPERTY_ICON))
            .getDrawable();
    String tag = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TAG));
    String title = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TITLE));
    if (title == null) {
      title = "";
    }
    tab.setTabGroup(this);
    final WindowProxy vp = (WindowProxy) tab.getProperty(TiC.PROPERTY_WINDOW);
    vp.setTabGroupProxy(this);
    vp.setTabProxy(tab);
    if (tag != null && vp != null) {
      TabSpec tspec = tg.newTab(tag);
      if (icon == null) {
        tspec.setIndicator(title);
      } else {
        tspec.setIndicator(title, icon);
      }

      Intent intent = new Intent(tta, TiActivity.class);
      vp.fillIntentForTab(intent);

      tspec.setContent(intent);

      tg.addTab(tspec);
    }
  }
  private void handleAddTab(TabProxy tab) {
    String tag = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TAG));
    if (tag == null) {
      String title = TiConvert.toString(tab.getProperty(TiC.PROPERTY_TITLE));
      if (title == null) {
        String icon = TiConvert.toString(tab.getProperty(TiC.PROPERTY_ICON));
        if (icon == null) {
          tag = tab.toString();
        } else {
          tag = icon;
        }
      } else {
        tag = title;
      }

      tab.setProperty(TiC.PROPERTY_TAG, tag, false); // store in proxy
    }

    if (tabs.size() == 0) {
      initialActiveTab = tab;
    }
    tabs.add(tab);

    if (peekView() != null) {
      TiUITabGroup tg = (TiUITabGroup) peekView();
      addTabToGroup(tg, tab);
    }
  }
  private int indexForId(String id) {
    int index = -1;

    int i = 0;
    for (TabProxy t : tabs) {
      String tag = (String) t.getProperty(TiC.PROPERTY_TAG);
      if (tag.equals(id)) {
        index = i;
        break;
      }
      i += 1;
    }
    return index;
  }