Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2c6998e authored by blong's avatar blong Committed by Xiaojing Zhang
Browse files

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
parent 5cc4fb87
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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"
+86 −0
Original line number Diff line number Diff line
@@ -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;