@Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
   if (mAdapter.isGroupHeader(position)) {
     mAdapter.toggleGroup(position);
   } else {
     Intent intent = new Intent(this, CallDetailActivity.class);
     intent.setData(ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id));
     StickyTabs.setTab(intent, getIntent());
     startActivity(intent);
   }
 }
  @Override
  public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn) {
    AdapterView.AdapterContextMenuInfo menuInfo;
    try {
      menuInfo = (AdapterView.AdapterContextMenuInfo) menuInfoIn;
    } catch (ClassCastException e) {
      Log.e(TAG, "bad menuInfoIn", e);
      return;
    }

    Cursor cursor = (Cursor) mAdapter.getItem(menuInfo.position);

    String number = cursor.getString(NUMBER_COLUMN_INDEX);
    Uri numberUri = null;
    boolean isVoicemail = false;
    boolean isSipNumber = false;
    if (number.equals(CallerInfo.UNKNOWN_NUMBER)) {
      number = getString(R.string.unknown);
    } else if (number.equals(CallerInfo.PRIVATE_NUMBER)) {
      number = getString(R.string.private_num);
    } else if (number.equals(CallerInfo.PAYPHONE_NUMBER)) {
      number = getString(R.string.payphone);
    } else if (PhoneNumberUtils.extractNetworkPortion(number).equals(mVoiceMailNumber)) {
      number = getString(R.string.voicemail);
      numberUri = Uri.parse("voicemail:x");
      isVoicemail = true;
    } else if (PhoneNumberUtils.isUriNumber(number)) {
      numberUri = Uri.fromParts("sip", number, null);
      isSipNumber = true;
    } else {
      numberUri = Uri.fromParts("tel", number, null);
    }

    ContactInfo info = mAdapter.getContactInfo(number);
    boolean contactInfoPresent = (info != null && info != ContactInfo.EMPTY);
    if (contactInfoPresent) {
      menu.setHeaderTitle(info.name);
    } else {
      menu.setHeaderTitle(number);
    }

    if (numberUri != null) {
      Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, numberUri);
      menu.add(
              0,
              CONTEXT_MENU_CALL_CONTACT,
              0,
              getResources().getString(R.string.recentCalls_callNumber, number))
          .setIntent(intent);
    }

    if (contactInfoPresent) {
      Intent intent =
          new Intent(
              Intent.ACTION_VIEW, ContentUris.withAppendedId(Contacts.CONTENT_URI, info.personId));
      StickyTabs.setTab(intent, getIntent());
      menu.add(0, 0, 0, R.string.menu_viewContact).setIntent(intent);
    }

    if (numberUri != null && !isVoicemail && !isSipNumber) {
      menu.add(0, 0, 0, R.string.recentCalls_editNumberBeforeCall)
          .setIntent(new Intent(Intent.ACTION_DIAL, numberUri));
      menu.add(0, 0, 0, R.string.menu_sendTextMessage)
          .setIntent(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("sms", number, null)));
    }

    // "Add to contacts" item, if this entry isn't already associated with a contact
    if (!contactInfoPresent && numberUri != null && !isVoicemail && !isSipNumber) {
      // TODO: This item is currently disabled for SIP addresses, because
      // the Insert.PHONE extra only works correctly for PSTN numbers.
      //
      // To fix this for SIP addresses, we need to:
      // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
      //   the current number is a SIP address
      // - update the contacts UI code to handle Insert.SIP_ADDRESS by
      //   updating the SipAddress field
      // and then we can remove the "!isSipNumber" check above.

      Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
      intent.setType(Contacts.CONTENT_ITEM_TYPE);
      intent.putExtra(Insert.PHONE, number);
      menu.add(0, 0, 0, R.string.recentCalls_addToContact).setIntent(intent);
    }
    menu.add(0, CONTEXT_MENU_ITEM_DELETE, 0, R.string.recentCalls_removeFromRecentList);
  }