@Override
  public boolean onMenuItemClick(final MenuItem menuItem) {
    switch (menuItem.getItemId()) {
      case R.id.action_ime_dialpad_toggle:
        final int baseInputType = InputType.TYPE_TEXT_FLAG_MULTI_LINE;
        if ((mRecipientTextView.getInputType() & InputType.TYPE_CLASS_PHONE)
            != InputType.TYPE_CLASS_PHONE) {
          mRecipientTextView.setInputType(baseInputType | InputType.TYPE_CLASS_PHONE);
          menuItem.setIcon(R.drawable.ic_ime_light);
        } else {
          mRecipientTextView.setInputType(baseInputType | InputType.TYPE_CLASS_TEXT);
          menuItem.setIcon(R.drawable.ic_numeric_dialpad);
        }
        ImeUtil.get().showImeKeyboard(getActivity(), mRecipientTextView);
        return true;

      case R.id.action_add_more_participants:
        mHost.onInitiateAddMoreParticipants();
        return true;

      case R.id.action_confirm_participants:
        maybeGetOrCreateConversation();
        return true;

      case R.id.action_delete_text:
        Assert.equals(MODE_PICK_INITIAL_CONTACT, mContactPickingMode);
        mRecipientTextView.setText("");
        return true;
    }
    return false;
  }
 /**
  * {@inheritDoc}
  *
  * <p>Called when the host activity has been created. At this point, the host activity should have
  * set the contact picking mode for us so that we may update our visuals.
  */
 @Override
 public void onActivityCreated(final Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
   Assert.isTrue(mContactPickingMode != MODE_UNDEFINED);
   updateVisualsForContactPickingMode(false /* animate */);
   mHost.invalidateActionBar();
 }
  /**
   * Watches changes in contact chips to determine possible state transitions (e.g. creating the
   * initial conversation, adding more participants or finish the current conversation)
   */
  @Override
  public void onContactChipsChanged(final int oldCount, final int newCount) {
    Assert.isTrue(oldCount != newCount);
    if (mContactPickingMode == MODE_PICK_INITIAL_CONTACT) {
      // Initial picking mode. Start a conversation once a recipient has been picked.
      maybeGetOrCreateConversation();
    } else if (mContactPickingMode == MODE_CHIPS_ONLY) {
      // oldCount == 0 means we are restoring from savedInstanceState to add the existing
      // chips, don't switch to "add more participants" mode in this case.
      if (oldCount > 0 && mRecipientTextView.isFocused()) {
        // Chips only mode. The user may have picked an additional contact or deleted the
        // only existing contact. Either way, switch to picking more participants mode.
        mHost.onInitiateAddMoreParticipants();
      }
    }
    mHost.onParticipantCountChanged(ContactPickerData.getCanAddMoreParticipants(newCount));

    // Refresh our local copy of the selected chips set to keep it up-to-date.
    mSelectedPhoneNumbers = mRecipientTextView.getSelectedDestinations();
    invalidateContactLists();
  }
  @Override
  @RunsOnMainThread
  public void onGetOrCreateConversationSucceeded(
      final ActionMonitor monitor, final Object data, final String conversationId) {
    Assert.isTrue(monitor == mMonitor);
    Assert.isTrue(conversationId != null);

    mRecipientTextView.setInputType(
        InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_CLASS_TEXT);
    mHost.onGetOrCreateNewConversation(conversationId);

    mMonitor = null;
  }