Make Contacts share concacts using vCard.
Bug: 2144645
diff --git a/res/values/config.xml b/res/values/config.xml
index 93d19e9..8449319 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -34,6 +34,9 @@
<!-- Flag indicating whether Contacts app is allowed to export contacts to SDCard -->
<bool name="config_allow_export_to_sdcard">true</bool>
+ <!-- Flag indicating whether Contacts app is allowed to share contacts with devices outside -->
+ <bool name="config_allow_share_visible_contacts">true</bool>
+
<!-- If true, enable vibration (haptic feedback) for dialer key presses.
The pattern is set on a per-platform basis using config_virtualKeyVibePattern.
TODO: If enough users are annoyed by this, we might eventually
diff --git a/res/values/ids.xml b/res/values/ids.xml
index ceb10f8..b8d90c5 100644
--- a/res/values/ids.xml
+++ b/res/values/ids.xml
@@ -36,6 +36,7 @@
<item type="id" name="dialog_readonly_contact_hide_confirmation"/>
<item type="id" name="dialog_multiple_contact_delete_confirmation"/>
<item type="id" name="dialog_readonly_contact_delete_confirmation"/>
+ <item type="id" name="dialog_share_confirmation" />
<!-- For ExportVCard -->
<item type="id" name="dialog_export_confirmation"/>
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 7d19bf4..9dae6c8 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -108,6 +108,7 @@
import android.widget.ResourceCursorAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;
+import android.widget.Toast;
import android.widget.AbsListView.OnScrollListener;
import java.lang.ref.WeakReference;
@@ -429,6 +430,10 @@
private ContactPhotoLoader mPhotoLoader;
+ final String[] sLookupProjection = new String[] {
+ Contacts.LOOKUP_KEY
+ };
+
static {
sContactsIdMatcher = new UriMatcher(UriMatcher.NO_MATCH);
sContactsIdMatcher.addURI(ContactsContract.AUTHORITY, "contacts/#", CONTACTS_ID);
@@ -1166,6 +1171,19 @@
.setPositiveButton(android.R.string.ok,
new DeleteClickListener()).create();
}
+ case R.id.dialog_share_confirmation: {
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.confirm_share_visible_contacts_title)
+ .setMessage(getString(R.string.confirm_share_visible_contacts_message))
+ .setPositiveButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ doShareVisibleContacts();
+ }
+ }
+ }).create();
+ }
}
return super.onCreateDialog(id);
}
@@ -1206,6 +1224,9 @@
if (res.getBoolean(R.bool.config_allow_export_to_sdcard)) {
adapter.add(R.string.export_to_sdcard);
}
+ if (res.getBoolean(R.bool.config_allow_share_visible_contacts)) {
+ adapter.add(R.string.share_visible_contacts);
+ }
final DialogInterface.OnClickListener clickListener =
new DialogInterface.OnClickListener() {
@@ -1225,6 +1246,10 @@
context.startActivity(exportIntent);
break;
}
+ case R.string.share_visible_contacts: {
+ showDialog(R.id.dialog_share_confirmation);
+ break;
+ }
default: {
Log.e(TAG, "Unexpected resource: " +
getResources().getResourceEntryName(resId));
@@ -1240,6 +1265,31 @@
.show();
}
+ private void doShareVisibleContacts() {
+ final Cursor cursor = getContentResolver().query(Contacts.CONTENT_URI,
+ sLookupProjection, getContactSelection(), null, null);
+ try {
+ if (!cursor.moveToFirst()) {
+ Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ ArrayList<Uri> uriList = new ArrayList<Uri>();
+ for (;!cursor.isAfterLast(); cursor.moveToNext()) {
+ uriList.add(Uri.withAppendedPath(
+ Contacts.CONTENT_VCARD_URI,
+ cursor.getString(0)));
+ }
+
+ final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
+ intent.setType(Contacts.CONTENT_VCARD_TYPE);
+ intent.putExtra(Intent.EXTRA_STREAM, uriList);
+ startActivity(intent);
+ } finally {
+ cursor.close();
+ }
+ }
+
private void handleImportRequest(int resId) {
// There's three possibilities:
// - more than one accounts -> ask the user