コード例 #1
0
  @Override
  public void setCheckable(boolean checkable) {
    if (!checkable && mRadioButton == null && mCheckBox == null) {
      return;
    }

    // Depending on whether its exclusive check or not, the checkbox or
    // radio button will be the one in use (and the other will be
    // otherCompoundButton)
    final CompoundButton compoundButton;
    final CompoundButton otherCompoundButton;

    if (mItemData.isExclusiveCheckable()) {
      if (mRadioButton == null) {
        insertRadioButton();
      }
      compoundButton = mRadioButton;
      otherCompoundButton = mCheckBox;
    } else {
      if (mCheckBox == null) {
        insertCheckBox();
      }
      compoundButton = mCheckBox;
      otherCompoundButton = mRadioButton;
    }

    if (checkable) {
      compoundButton.setChecked(mItemData.isChecked());

      final int newVisibility = checkable ? View.VISIBLE : View.GONE;
      if (compoundButton.getVisibility() != newVisibility) {
        compoundButton.setVisibility(newVisibility);
      }

      // Make sure the other compound button isn't visible
      if (otherCompoundButton != null && otherCompoundButton.getVisibility() != View.GONE) {
        otherCompoundButton.setVisibility(View.GONE);
      }
    } else {
      if (mCheckBox != null) {
        mCheckBox.setVisibility(View.GONE);
      }
      if (mRadioButton != null) {
        mRadioButton.setVisibility(View.GONE);
      }
    }
  }
コード例 #2
0
  public boolean bindNativeOverflow(
      android.view.Menu menu,
      android.view.MenuItem.OnMenuItemClickListener listener,
      HashMap<android.view.MenuItem, MenuItemImpl> map) {
    final List<MenuItemImpl> nonActionItems = getNonActionItems();
    if (nonActionItems == null || nonActionItems.size() == 0) {
      return false;
    }

    boolean visible = false;
    menu.clear();
    for (MenuItemImpl nonActionItem : nonActionItems) {
      if (!nonActionItem.isVisible()) {
        continue;
      }
      visible = true;

      android.view.MenuItem nativeItem;
      if (nonActionItem.hasSubMenu()) {
        android.view.SubMenu nativeSub =
            menu.addSubMenu(
                nonActionItem.getGroupId(),
                nonActionItem.getItemId(),
                nonActionItem.getOrder(),
                nonActionItem.getTitle());

        SubMenuBuilder subMenu = (SubMenuBuilder) nonActionItem.getSubMenu();
        for (MenuItemImpl subItem : subMenu.getVisibleItems()) {
          android.view.MenuItem nativeSubItem =
              nativeSub.add(
                  subItem.getGroupId(),
                  subItem.getItemId(),
                  subItem.getOrder(),
                  subItem.getTitle());

          nativeSubItem.setIcon(subItem.getIcon());
          nativeSubItem.setOnMenuItemClickListener(listener);
          nativeSubItem.setEnabled(subItem.isEnabled());
          nativeSubItem.setIntent(subItem.getIntent());
          nativeSubItem.setNumericShortcut(subItem.getNumericShortcut());
          nativeSubItem.setAlphabeticShortcut(subItem.getAlphabeticShortcut());
          nativeSubItem.setTitleCondensed(subItem.getTitleCondensed());
          nativeSubItem.setCheckable(subItem.isCheckable());
          nativeSubItem.setChecked(subItem.isChecked());

          if (subItem.isExclusiveCheckable()) {
            nativeSub.setGroupCheckable(subItem.getGroupId(), true, true);
          }

          map.put(nativeSubItem, subItem);
        }

        nativeItem = nativeSub.getItem();
      } else {
        nativeItem =
            menu.add(
                nonActionItem.getGroupId(),
                nonActionItem.getItemId(),
                nonActionItem.getOrder(),
                nonActionItem.getTitle());
      }
      nativeItem.setIcon(nonActionItem.getIcon());
      nativeItem.setOnMenuItemClickListener(listener);
      nativeItem.setEnabled(nonActionItem.isEnabled());
      nativeItem.setIntent(nonActionItem.getIntent());
      nativeItem.setNumericShortcut(nonActionItem.getNumericShortcut());
      nativeItem.setAlphabeticShortcut(nonActionItem.getAlphabeticShortcut());
      nativeItem.setTitleCondensed(nonActionItem.getTitleCondensed());
      nativeItem.setCheckable(nonActionItem.isCheckable());
      nativeItem.setChecked(nonActionItem.isChecked());

      if (nonActionItem.isExclusiveCheckable()) {
        menu.setGroupCheckable(nonActionItem.getGroupId(), true, true);
      }

      map.put(nativeItem, nonActionItem);
    }
    return visible;
  }