@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); } }
public void onClick(View view) { String number = (String) view.getTag(); if (!TextUtils.isEmpty(number)) { // Here, "number" can either be a PSTN phone number or a // SIP address. So turn it into either a tel: URI or a // sip: URI, as appropriate. Uri callUri; if (PhoneNumberUtils.isUriNumber(number)) { callUri = Uri.fromParts("sip", number, null); } else { callUri = Uri.fromParts("tel", number, null); } StickyTabs.saveTab(RecentCallsListActivity.this, getIntent()); startActivity(new Intent(Intent.ACTION_CALL_PRIVILEGED, callUri)); } }
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case CONTEXT_MENU_ITEM_DELETE: { // Convert the menu info to the proper type AdapterView.AdapterContextMenuInfo menuInfo; try { menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG, "bad menuInfoIn", e); return false; } Cursor cursor = (Cursor) mAdapter.getItem(menuInfo.position); int groupSize = 1; if (mAdapter.isGroupHeader(menuInfo.position)) { groupSize = mAdapter.getGroupSize(menuInfo.position); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < groupSize; i++) { if (i != 0) { sb.append(","); cursor.moveToNext(); } long id = cursor.getLong(ID_COLUMN_INDEX); sb.append(id); } getContentResolver().delete(Calls.CONTENT_URI, Calls._ID + " IN (" + sb + ")", null); return true; } case CONTEXT_MENU_CALL_CONTACT: { StickyTabs.saveTab(this, getIntent()); startActivity(item.getIntent()); return true; } default: { return super.onContextItemSelected(item); } } }
private void callEntry(int position) { if (position < 0) { // In touch mode you may often not have something selected, so // just call the first entry to make sure that [send] [send] calls the // most recent entry. position = 0; } final Cursor cursor = (Cursor) mAdapter.getItem(position); if (cursor != null) { String number = cursor.getString(NUMBER_COLUMN_INDEX); if (TextUtils.isEmpty(number) || number.equals(CallerInfo.UNKNOWN_NUMBER) || number.equals(CallerInfo.PRIVATE_NUMBER) || number.equals(CallerInfo.PAYPHONE_NUMBER)) { // This number can't be called, do nothing return; } Intent intent; // If "number" is really a SIP address, construct a sip: URI. if (PhoneNumberUtils.isUriNumber(number)) { intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts("sip", number, null)); } else { // We're calling a regular PSTN phone number. // Construct a tel: URI, but do some other possible cleanup first. int callType = cursor.getInt(CALL_TYPE_COLUMN_INDEX); if (!number.startsWith("+") && (callType == Calls.INCOMING_TYPE || callType == Calls.MISSED_TYPE)) { // If the caller-id matches a contact with a better qualified number, use it number = getBetterNumberFromContacts(number); } intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts("tel", number, null)); } StickyTabs.saveTab(this, getIntent()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); startActivity(intent); } }
public void onClick(DialogInterface dialog, int which) { if (mPhoneItemList.size() > which && which >= 0) { PhoneItem phoneItem = mPhoneItemList.get(which); long id = phoneItem.id; String phone = phoneItem.phoneNumber; if (mMakePrimary) { ContentValues values = new ContentValues(1); values.put(Data.IS_SUPER_PRIMARY, 1); mContext .getContentResolver() .update(ContentUris.withAppendedId(Data.CONTENT_URI, id), values, null, null); } if (mSendSms) { ContactsUtils.initiateSms(mContext, phone); } else { StickyTabs.saveTab(mContext, mStickyTab); ContactsUtils.initiateCall(mContext, phone); } } else { dialog.dismiss(); } }
@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); }