Search in sources :

Example 6 with Contact

use of com.android.contacts.common.model.Contact in project android_packages_apps_Dialer by LineageOS.

the class CallerInfoUtils method sendViewNotification.

/**
 * Send a notification using a {@link ContactLoader} to inform the sync adapter that we are
 * viewing a particular contact, so that it can download the high-res photo.
 */
public static void sendViewNotification(Context context, Uri contactUri) {
    final ContactLoader loader = new ContactLoader(context, contactUri, true);
    loader.registerListener(0, new OnLoadCompleteListener<Contact>() {

        @Override
        public void onLoadComplete(Loader<Contact> loader, Contact contact) {
            try {
                loader.reset();
            } catch (RuntimeException e) {
                LogUtil.e("CallerInfoUtils.onLoadComplete", "Error resetting loader", e);
            }
        }
    });
    loader.startLoading();
}
Also used : ContactLoader(com.android.contacts.common.model.ContactLoader) Contact(com.android.contacts.common.model.Contact)

Example 7 with Contact

use of com.android.contacts.common.model.Contact in project android_packages_apps_Dialer by LineageOS.

the class IntentProvider method getAddContactIntentProvider.

/**
 * Retrieves an add contact intent for the given contact and phone call details.
 */
public static IntentProvider getAddContactIntentProvider(final Uri lookupUri, final CharSequence name, final CharSequence number, final int numberType, final boolean isNewContact) {
    return new IntentProvider() {

        @Override
        public Intent getClickIntent(Context context) {
            Contact contactToSave = null;
            if (lookupUri != null) {
                contactToSave = ContactLoader.parseEncodedContactEntity(lookupUri);
            }
            if (contactToSave != null) {
                // Populate the intent with contact information stored in the lookup URI.
                // Note: This code mirrors code in Contacts/QuickContactsActivity.
                final Intent intent;
                if (isNewContact) {
                    intent = IntentUtil.getNewContactIntent();
                } else {
                    intent = IntentUtil.getAddToExistingContactIntent();
                }
                ArrayList<ContentValues> values = contactToSave.getContentValues();
                // or better (e.g. structured name, nickname)
                if (contactToSave.getDisplayNameSource() >= ContactsContract.DisplayNameSources.NICKNAME) {
                    intent.putExtra(ContactsContract.Intents.Insert.NAME, contactToSave.getDisplayName());
                } else if (contactToSave.getDisplayNameSource() == ContactsContract.DisplayNameSources.ORGANIZATION) {
                    // This is probably an organization. Instead of copying the organization
                    // name into a name entry, copy it into the organization entry. This
                    // way we will still consider the contact an organization.
                    final ContentValues organization = new ContentValues();
                    organization.put(ContactsContract.CommonDataKinds.Organization.COMPANY, contactToSave.getDisplayName());
                    organization.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
                    values.add(organization);
                }
                // properly
                for (ContentValues value : values) {
                    value.remove(ContactsContract.Data.LAST_TIME_USED);
                    value.remove(ContactsContract.Data.TIMES_USED);
                }
                intent.putExtra(ContactsContract.Intents.Insert.DATA, values);
                return intent;
            } else {
                // If no lookup uri is provided, rely on the available phone number and name.
                if (isNewContact) {
                    return IntentUtil.getNewContactIntent(name, number, numberType);
                } else {
                    return IntentUtil.getAddToExistingContactIntent(name, number, numberType);
                }
            }
        }
    };
}
Also used : Context(android.content.Context) ContentValues(android.content.ContentValues) Intent(android.content.Intent) DialerContact(com.android.dialer.dialercontact.DialerContact) Contact(com.android.contacts.common.model.Contact)

Aggregations

Contact (com.android.contacts.common.model.Contact)7 ContactLoader (com.android.contacts.common.model.ContactLoader)4 Intent (android.content.Intent)3 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 OnLoadCompleteListener (android.content.Loader.OnLoadCompleteListener)1 Uri (android.net.Uri)1 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)1 DialerContact (com.android.dialer.dialercontact.DialerContact)1