/** 保存收藏项 wanglu 泰得利通 */
  protected void saveFaveItem() {

    setMenuItemP();
    favoriteItemDao.addFavoriteItem(checkMenuItem); // 保存收藏列表到数据库
    checkMenuItem.setLocalFavorites(true);
    homeMenuItems.add(checkMenuItem);
    Toast.makeText(this, "收藏" + checkMenuItem.getName() + "成功!", Toast.LENGTH_SHORT).show();
  }
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

      checkMenuItem = menuItem;

      if (isChecked) { // 保存手册列表

        currentMenuLevel = getMenuItemLevel(checkMenuItem); // 获取菜单的级别

        switch (currentMenuLevel) {
          case MenuItem.LEVEL_ONE: // 一级菜单
            checkMenuItem.setLevel(MenuItem.LEVEL_ONE);
            saveFaveItem(); // 保存收藏项
            break;
          case MenuItem.LEVEL_TWO: // 二级菜单
            checkMenuItem.setLevel(MenuItem.LEVEL_TWO);
            saveFaveItem();
            break;
          case MenuItem.LEVEL_THREE: // 三级菜单
            checkMenuItem.setLevel(MenuItem.LEVEL_THREE);
            MenuItem paretMenuItem =
                (MenuItem)
                    CacheUtil.get(
                        MenuItem.MENUITEM_KEY + checkMenuItem.getParentMenuId()); // 拿到父菜单,二级菜单

            if (CacheUtil.get(paretMenuItem.getId()) == null) { // 看缓存中有没有三级子菜单,没有就加载三级子菜单

              if (paretMenuItem.getType() == MenuItem.CUSTOM_MENU) {
                loadMenuItems(paretMenuItem.getId());
              } else if (paretMenuItem.getType() == MenuItem.CHANNEL_MENU) { // 频道
                Toast.makeText(MenuItemSetActivity.this, "该数据有误,不可以收藏", Toast.LENGTH_SHORT).show();
              }

            } else {
              saveFaveItem(); // 保存收藏项
            }

            break;
        }

      } else {
        checkMenuItem.setLocalFavorites(false);
        favoriteItemDao.delFavoriteItem(checkMenuItem.getId());
        homeMenuItems.remove(checkMenuItem);
      }
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      String name = "";
      MenuItem menuItem = (MenuItem) favaItems.get(position);

      name = menuItem.getName();

      ViewHolder viewHolder = null;
      if (convertView == null) {

        convertView = View.inflate(MenuItemSetActivity.this, R.layout.menuset_item_layout, null);
        viewHolder = new ViewHolder();

        viewHolder.title_text = (TextView) convertView.findViewById(R.id.menuset_tv_name);

        SwitchButton switchButton = (SwitchButton) convertView.findViewById(R.id.checkbox);

        viewHolder.switchButton = switchButton;

        // 解决SwitchButton显示bug
        if (convertView.getLayoutParams() != null) {
          convertView.getLayoutParams().height = DisplayUtil.dip2px(MenuItemSetActivity.this, 55);
        } else {
          AbsListView.LayoutParams params =
              new AbsListView.LayoutParams(
                  AbsListView.LayoutParams.MATCH_PARENT,
                  DisplayUtil.dip2px(MenuItemSetActivity.this, 55));
          convertView.setLayoutParams(params);
        }

        convertView.setTag(viewHolder);
      } else {
        viewHolder = (ViewHolder) convertView.getTag();
      }

      viewHolder.title_text.setText(name);
      viewHolder.switchButton.setChecked(menuItem.isLocalFavorites());

      viewHolder.switchButton.setOnCheckedChangeListener(new SwitchOnChangeButton(menuItem));
      return convertView;
    }
  /**
   * wanglu 泰得利通 获取菜单的级别
   *
   * @param menuItem
   * @return
   */
  private int getMenuItemLevel(MenuItem menuItem) {

    String parentId = menuItem.getParentMenuId();
    if (parentId == null) {

      return MenuItem.LEVEL_ONE;
    } else {

      if (MenuItemChannelIndexUtil.getInstance()
          .containsKey(Constants.CacheKey.MAIN_MENUITEM_KEY, parentId)) {

        return MenuItem.LEVEL_TWO;
      } else {

        return MenuItem.LEVEL_THREE;
      }
    }
  }
  /** 设置菜单的位置 wanglu 泰得利通 */
  private void setMenuItemP() {

    switch (currentMenuLevel) {
      case MenuItem.LEVEL_TWO: // 二级菜单
        checkMenuItem.setLevel_two_p(
            MenuItemChannelIndexUtil.getInstance()
                .getMenueChannelIndex(
                    checkMenuItem.getParentMenuId(), checkMenuItem.getId())); // 设置其索引位置
        break;
      case MenuItem.LEVEL_THREE:
        MenuItem paretMenuItem =
            (MenuItem)
                CacheUtil.get(
                    MenuItem.MENUITEM_KEY + checkMenuItem.getParentMenuId()); // 拿到父菜单,二级菜单

        checkMenuItem.setLevel_two_p(
            MenuItemChannelIndexUtil.getInstance()
                .getMenueChannelIndex(
                    paretMenuItem.getParentMenuId(), paretMenuItem.getId())); // 设置二级菜单的位置

        checkMenuItem.setLevel_three_p(
            MenuItemChannelIndexUtil.getInstance()
                .getMenueChannelIndex(paretMenuItem.getId(), checkMenuItem.getId())); // 设置三级菜单的索引位

        break;
    }
  }