private void launchMultiplePhonePicker() { Intent intent = new Intent(Intents.ACTION_GET_MULTIPLE_PHONES); intent.addCategory("android.intent.category.DEFAULT"); intent.setType(Phone.CONTENT_TYPE); // We have to wait for the constructing complete. ContactList contacts = mRecipientsEditor .constructContactsFromInput(true); int urisCount = 0; Uri[] uris = new Uri[contacts.size()]; urisCount = 0; for (Contact contact : contacts) { if (Contact.CONTACT_METHOD_TYPE_PHONE == contact .getContactMethodType()) { uris[urisCount++] = contact.getPhoneUri(); } } if (urisCount > 0) { intent.putExtra(Intents.EXTRA_PHONE_URIS, uris); } startActivityForResult(intent, REQUEST_CODE_PICK); }
private void launchMultiplePhonePicker() { Intent intent = new Intent(Intents.ACTION_GET_MULTIPLE_PHONES); intent.addCategory("android.intent.category.DEFAULT"); intent.setType(Phone.CONTENT_TYPE); // We have to wait for the constructing complete. ContactList contacts = mRecipientsEditor.constructContactsFromInput(true); int urisCount = 0; Uri[] uris = new Uri[contacts.size()]; urisCount = 0; for (Contact contact : contacts) { if (Contact.CONTACT_METHOD_TYPE_PHONE == contact.getContactMethodType()) { uris[urisCount++] = contact.getPhoneUri(); } } if (urisCount > 0) { intent.putExtra(Intents.EXTRA_PHONE_URIS, uris); } startActivityForResult(intent, REQUEST_CODE_PICK); }
@Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); intent.setType(Contacts.CONTENT_ITEM_TYPE); intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid().toString()); intent.putExtra(Intents.Insert.IM_PROTOCOL, CommonDataKinds.Im.PROTOCOL_JABBER); intent.putExtra("finishActivityOnSaveCompleted", true); ContactDetailsActivity.this.startActivityForResult(intent, 0); }
@Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); intent.setType(Contacts.CONTENT_ITEM_TYPE); intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid()); intent.putExtra(Intents.Insert.IM_PROTOCOL, CommonDataKinds.Im.PROTOCOL_JABBER); intent.putExtra("finishActivityOnSaveCompleted", true); activity.startActivityForResult(intent, 0); }
/** * Taken from com.google.android.gm.HtmlConversationActivity * * Send the intent that shows the Contact info corresponding to the email * address. */ public void showContactInfo(Attendee attendee, Rect rect) { // First perform lookup query to find existing contact final ContentResolver resolver = getActivity().getContentResolver(); final String address = attendee.mEmail; final Uri dataUri = Uri.withAppendedPath( CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address)); final Uri lookupUri = ContactsContract.Data.getContactLookupUri( resolver, dataUri); if (lookupUri != null) { // Found matching contact, trigger QuickContact QuickContact.showQuickContact(getActivity(), rect, lookupUri, QuickContact.MODE_MEDIUM, null); } else { // No matching contact, ask user to create one final Uri mailUri = Uri.fromParts("mailto", address, null); final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mailUri); // Pass along full E-mail string for possible create dialog Rfc822Token sender = new Rfc822Token(attendee.mName, attendee.mEmail, null); intent.putExtra(Intents.EXTRA_CREATE_DESCRIPTION, sender.toString()); // Only provide personal name hint if we have one final String senderPersonal = attendee.mName; if (!TextUtils.isEmpty(senderPersonal)) { intent.putExtra(Intents.Insert.NAME, senderPersonal); } startActivity(intent); } }
@Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { Uri lookupUri = null; Uri createUri = null; boolean trigger = false; Bundle extras = (cookie != null) ? (Bundle) cookie : new Bundle(); try { switch (token) { case TOKEN_EMAIL_LOOKUP_AND_TRIGGER: trigger = true; createUri = Uri.fromParts("mailto", extras.getString(EXTRA_URI_CONTENT), null); //$FALL-THROUGH$ case TOKEN_EMAIL_LOOKUP: { if (cursor != null && cursor.moveToFirst()) { long contactId = cursor.getLong(EMAIL_ID_COLUMN_INDEX); String lookupKey = cursor.getString(EMAIL_LOOKUP_STRING_COLUMN_INDEX); lookupUri = Contacts.getLookupUri(contactId, lookupKey); } break; } } } finally { if (cursor != null) { cursor.close(); } } contactUri = lookupUri; onContactUriChanged(); if (trigger && lookupUri != null) { // Found contact, so trigger QuickContact QuickContact.showQuickContact( getContext(), ContactBadge.this, lookupUri, QuickContact.MODE_LARGE, null); } else if (createUri != null) { // Prompt user to add this person to contacts final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, createUri); extras.remove(EXTRA_URI_CONTENT); intent.putExtras(extras); getContext().startActivity(intent); } }
private void processPickResult(final Intent data) { // The EXTRA_PHONE_URIS stores the phone's urls that were selected by // user in the // multiple phone picker. final Parcelable[] uris = data .getParcelableArrayExtra(Intents.EXTRA_PHONE_URIS); final int recipientCount = uris != null ? uris.length : 0; final int recipientLimit = MmsConfig.getRecipientLimit(); if (recipientLimit != Integer.MAX_VALUE && recipientCount > recipientLimit) { new AlertDialog.Builder(this) .setMessage( getString(R.string.too_many_recipients, recipientCount, recipientLimit)) .setPositiveButton(android.R.string.ok, null).create() .show(); return; } final Handler handler = new Handler(); final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getText(R.string.pick_too_many_recipients)); progressDialog.setMessage(getText(R.string.adding_recipients)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); final Runnable showProgress = new Runnable() { @Override public void run() { progressDialog.show(); } }; // Only show the progress dialog if we can not finish off parsing the // return data in 1s, // otherwise the dialog could flicker. handler.postDelayed(showProgress, 1000); new Thread(new Runnable() { @Override public void run() { final ContactList list; try { list = ContactList.blockingGetByUris(uris); } finally { handler.removeCallbacks(showProgress); progressDialog.dismiss(); } // TODO: there is already code to update the contact header // widget and recipients // editor if the contacts change. we can re-use that code. final Runnable populateWorker = new Runnable() { @Override public void run() { mRecipientsEditor.populate(list); updateTitle(list); } }; handler.post(populateWorker); } }, "ComoseMessageActivity.processPickResult").start(); }
@Override public Intent getShowOrCreateIntent( String username ) { return new Intent( Intents.SHOW_OR_CREATE_CONTACT, Uri.parse( new StringBuilder( BASE_URI ).append( Uri.encode( username ) ).toString() ) ); }
private void processPickResult(final Intent data) { // The EXTRA_PHONE_URIS stores the phone's urls that were selected by user in the // multiple phone picker. final Parcelable[] uris = data.getParcelableArrayExtra(Intents.EXTRA_PHONE_URIS); final int recipientCount = uris != null ? uris.length : 0; final int recipientLimit = MmsConfig.getRecipientLimit(); if (recipientLimit != Integer.MAX_VALUE && recipientCount > recipientLimit) { new AlertDialog.Builder(this) .setMessage(getString(R.string.too_many_recipients, recipientCount, recipientLimit)) .setPositiveButton(android.R.string.ok, null) .create().show(); return; } final Handler handler = new Handler(); final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getText(R.string.pick_too_many_recipients)); progressDialog.setMessage(getText(R.string.adding_recipients)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); final Runnable showProgress = new Runnable() { @Override public void run() { progressDialog.show(); } }; // Only show the progress dialog if we can not finish off parsing the return data in 1s, // otherwise the dialog could flicker. handler.postDelayed(showProgress, 1000); new Thread(new Runnable() { @Override public void run() { final ContactList list; try { list = ContactList.blockingGetByUris(uris); } finally { handler.removeCallbacks(showProgress); progressDialog.dismiss(); } // TODO: there is already code to update the contact header widget and recipients // editor if the contacts change. we can re-use that code. final Runnable populateWorker = new Runnable() { @Override public void run() { mRecipientsEditor.populate(list); updateTitle(list); } }; handler.post(populateWorker); } }, "ComoseMessageActivity.processPickResult").start(); }