summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblong <blong@codeaurora.org>2014-08-01 13:45:37 +0800
committerXiaojing Zhang <zhangx@codeaurora.org>2014-11-04 20:32:01 -0800
commitd2c6998e6006f3c2ba7bda267da314c8ac257273 (patch)
tree7eff22b07b120dccec85a788d968fcdb89525264
parent5cc4fb87deb256864014c316406a411e69e42dea (diff)
downloadpackages_apps_Contacts-d2c6998e6006f3c2ba7bda267da314c8ac257273.tar.gz
packages_apps_Contacts-d2c6998e6006f3c2ba7bda267da314c8ac257273.tar.bz2
packages_apps_Contacts-d2c6998e6006f3c2ba7bda267da314c8ac257273.zip
Add the feature of send contact by sms
- Add one menu in contact detaile view for user to send the contact info via SMS. Change-Id: I7920e7851a05d54b74c13f0d2e2be41fb0e0a1b8
-rw-r--r--res/menu/quickcontact.xml3
-rw-r--r--src/com/android/contacts/quickcontact/QuickContactActivity.java86
2 files changed, 89 insertions, 0 deletions
diff --git a/res/menu/quickcontact.xml b/res/menu/quickcontact.xml
index 13caa5962..c10a489cc 100644
--- a/res/menu/quickcontact.xml
+++ b/res/menu/quickcontact.xml
@@ -29,6 +29,9 @@
android:id="@+id/menu_share"
android:title="@string/menu_share"
android:alphabeticShortcut="s" />
+ <item
+ android:id="@+id/menu_send_via_sms"
+ android:title="@string/menu_sendViaSMS" />
<item
android:id="@+id/menu_create_contact_shortcut"
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index e5574d90f..7a123b5f2 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -24,6 +24,7 @@ import android.app.Fragment;
import android.app.LoaderManager.LoaderCallbacks;
import android.app.SearchManager;
import android.content.ActivityNotFoundException;
+import android.content.ContentValues;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
@@ -59,6 +60,7 @@ import android.provider.ContactsContract.CommonDataKinds.Organization;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Relation;
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
+import android.provider.ContactsContract.CommonDataKinds.Organization;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.CommonDataKinds.Website;
import android.provider.ContactsContract.Contacts;
@@ -2086,6 +2088,83 @@ public class QuickContactActivity extends ContactsActivity {
final List<ResolveInfo> receivers = getPackageManager()
.queryBroadcastReceivers(createShortcutIntent, 0);
return receivers != null && receivers.size() > 0;
+
+ private void sendContactViaSMS() {
+ // Get name string
+ String name = mContactData.getDisplayName();
+ String phone = null;
+ String email = null;
+ String postal = null;
+ String organization = null;
+ String sipAddress = null;
+
+ Log.d(TAG, "Contact name: " + name);
+
+ for (RawContact raw: mContactData.getRawContacts()) {
+ for (DataItem dataItem : raw.getDataItems()) {
+ final ContentValues entryValues = dataItem.getContentValues();
+ final String mimeType = dataItem.getMimeType();
+
+ Log.d(TAG, " entryValues:" + entryValues);
+
+ if (mimeType == null) continue;
+
+ if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) { // Get phone string
+ if (phone == null) {
+ phone = entryValues.getAsString(Phone.NUMBER);
+ } else {
+ phone = phone + ", " + entryValues.getAsString(Phone.NUMBER);
+ }
+ } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType)) { // Get email string
+ if (email == null) {
+ email = entryValues.getAsString(Email.ADDRESS);
+ } else {
+ email = email + ", " + entryValues.getAsString(Email.ADDRESS);
+ }
+ } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType)) {
+ if (postal == null) {
+ postal = entryValues.getAsString(StructuredPostal.FORMATTED_ADDRESS);
+ } else {
+ postal = postal + ", " + entryValues.getAsString(
+ StructuredPostal.FORMATTED_ADDRESS);
+ }
+ } else if (Organization.CONTENT_ITEM_TYPE.equals(mimeType)) {
+ if (organization == null) {
+ organization = entryValues.getAsString(Organization.COMPANY);
+ } else {
+ organization = organization + ", " + entryValues
+ .getAsString(Organization.COMPANY);
+ }
+ } else if (SipAddress.CONTENT_ITEM_TYPE.equals(mimeType)) {
+ if (sipAddress == null) {
+ sipAddress = entryValues.getAsString(SipAddress.SIP_ADDRESS);
+ } else {
+ sipAddress = sipAddress + ", " + entryValues
+ .getAsString(SipAddress.SIP_ADDRESS);
+ }
+ }
+ }
+ }
+
+ if (TextUtils.isEmpty(name)) {
+ name = getResources().getString(R.string.missing_name);
+ }
+
+ name = getString(R.string.nameLabelsGroup) + ":" + name + "\r\n";
+ phone = (phone == null) ? "" : getString(R.string.phoneLabelsGroup)
+ + ":" + phone + "\r\n";
+ email = (email == null )? "" : getString(R.string.emailLabelsGroup)
+ + ":" + email + "\r\n";
+ postal = (postal == null) ? "" : getString(R.string.postalLabelsGroup)
+ + ":" + postal + "\r\n";
+ organization = (organization == null) ? "" : getString(R.string.organizationLabelsGroup)
+ + ":" + organization + "\r\n";
+ sipAddress = (sipAddress == null) ? "" : getString(R.string.label_sip_address) + ":"
+ + sipAddress + "\r\n";
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.putExtra("sms_body", name + phone + email + postal + organization + sipAddress);
+ intent.setType("vnd.android-dir/mms-sms");
+ startActivity(intent);
}
@Override
@@ -2186,6 +2265,13 @@ public class QuickContactActivity extends ContactsActivity {
case R.id.menu_share:
shareContact();
return true;
+ case R.id.menu_send_via_sms: {
+ if (mContactData == null) {
+ return false;
+ }
+ sendContactViaSMS();
+ return true;
+ }
case R.id.menu_create_contact_shortcut:
createLauncherShortcutWithContact();
return true;