private String[] getContactsForCheckedGroupsSelectionArgs() {
   if (mLocalGroups != null) {
     String[] selectionArgs = new String[mLocalGroups.size()];
     int i = 0;
     for (Group group : mLocalGroups) {
       selectionArgs[i++] = String.valueOf(group.getId());
     }
     return selectionArgs;
   }
   return null;
 }
  private void checkGroup(Group group, boolean check) {
    group.setChecked(check);
    if (group.isLocal()) {
      if (group.isChecked()) {
        mLocalGroups.add(group);
      } else {
        mLocalGroups.remove(group);
      }
      return;
    }
    ArrayList<PhoneNumber> phoneNumbers = group.getPhoneNumbers();

    if (phoneNumbers != null) {
      for (PhoneNumber phoneNumber : phoneNumbers) {
        if (phoneNumber.isDefault()) {
          selectPhoneNumber(phoneNumber, check);
          updateGroupCheckStateForNumber(phoneNumber, group);
        }
      }
    }
  }
  private void updateGroupCheckStateForNumber(PhoneNumber phoneNumber, Group excludedGroup) {
    ArrayList<Group> phoneGroups = phoneNumber.getGroups();
    if (phoneGroups == null) {
      return;
    }

    if (phoneNumber.isChecked() && phoneNumber.isDefault()) {
      for (Group group : phoneGroups) {
        if (group == excludedGroup || group.isLocal()) {
          continue;
        }
        boolean checked = true;
        for (PhoneNumber number : group.getPhoneNumbers()) {
          if (number.isDefault() && !number.isChecked()) {
            checked = false;
            break;
          }
        }
        group.setChecked(checked);
      }
    } else if (!phoneNumber.isChecked()) {
      for (Group group : phoneGroups) {
        if (group != excludedGroup) {
          group.setChecked(false);
        }
      }
    }
  }