Search in sources :

Example 1 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class Contacts method markAsContacted.

/**
     * Mark contacts with the provided email addresses as contacted.
     *
     * @param addresses Array of {@link Address} objects describing the
     *        contacts to be marked as contacted.
     */
public void markAsContacted(final Address[] addresses) {
    //TODO: Optimize! Potentially a lot of database queries
    for (final Address address : addresses) {
        final Cursor c = getContactByAddress(address.getAddress());
        if (c != null) {
            if (c.getCount() > 0) {
                c.moveToFirst();
                final long personId = c.getLong(CONTACT_ID_INDEX);
                ContactsContract.Contacts.markAsContacted(mContentResolver, personId);
            }
            c.close();
        }
    }
}
Also used : Address(com.fsck.k9.mail.Address) Cursor(android.database.Cursor)

Example 2 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class RecipientPresenter method hasContactPicker.

/**
     * Does the device actually have a Contacts application suitable for
     * picking a contact. As hard as it is to believe, some vendors ship
     * without it.
     *
     * @return True, if the device supports picking contacts. False, otherwise.
     */
private boolean hasContactPicker() {
    if (hasContactPicker == null) {
        Contacts contacts = Contacts.getInstance(context);
        PackageManager packageManager = context.getPackageManager();
        List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(contacts.contactPickerIntent(), 0);
        hasContactPicker = !resolveInfoList.isEmpty();
    }
    return hasContactPicker;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Contacts(com.fsck.k9.helper.Contacts) PackageManager(android.content.pm.PackageManager)

Example 3 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class NotificationContentCreator method getMessageSender.

private String getMessageSender(Account account, Message message) {
    boolean isSelf = false;
    final Contacts contacts = K9.showContactName() ? Contacts.getInstance(context) : null;
    final Address[] fromAddresses = message.getFrom();
    if (fromAddresses != null) {
        isSelf = account.isAnIdentity(fromAddresses);
        if (!isSelf && fromAddresses.length > 0) {
            return MessageHelper.toFriendly(fromAddresses[0], contacts).toString();
        }
    }
    if (isSelf) {
        // show To: if the message was sent from me
        Address[] recipients = message.getRecipients(Message.RecipientType.TO);
        if (recipients != null && recipients.length > 0) {
            return context.getString(R.string.message_to_fmt, MessageHelper.toFriendly(recipients[0], contacts).toString());
        }
    }
    return null;
}
Also used : Contacts(com.fsck.k9.helper.Contacts) Address(com.fsck.k9.mail.Address)

Example 4 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class RecipientLoader method fillContactDataFromLookupKey.

private void fillContactDataFromLookupKey(Uri lookupKeyUri, List<Recipient> recipients, Map<String, Recipient> recipientMap) {
    // We shouldn't try to access the contacts if we don't have the necessary permission
    if (!hasContactPermission())
        return;
    // We could use the contact id from the URI directly, but getting it from the lookup key is safer
    Uri contactContentUri = Contacts.lookupContact(contentResolver, lookupKeyUri);
    if (contactContentUri == null) {
        return;
    }
    String contactIdStr = getContactIdFromContactUri(contactContentUri);
    Cursor cursor = contentResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, PROJECTION, ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?", new String[] { contactIdStr }, null);
    if (cursor == null) {
        return;
    }
    fillContactDataFromCursor(cursor, recipients, recipientMap);
}
Also used : EmptyCursor(com.fsck.k9.helper.EmptyCursor) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 5 with Contacts

use of com.fsck.k9.helper.Contacts in project k-9 by k9mail.

the class RecipientLoader method fillContactDataFromAddresses.

private void fillContactDataFromAddresses(Address[] addresses, List<Recipient> recipients, Map<String, Recipient> recipientMap) {
    for (Address address : addresses) {
        if (isSupportedEmailAddress(address.getAddress())) {
            // TODO actually query contacts - not sure if this is possible in a single query tho :(
            Recipient recipient = new Recipient(address);
            recipients.add(recipient);
            recipientMap.put(address.getAddress(), recipient);
        }
    }
}
Also used : Address(com.fsck.k9.mail.Address) Recipient(com.fsck.k9.view.RecipientSelectView.Recipient)

Aggregations

Address (com.fsck.k9.mail.Address)13 Contacts (com.fsck.k9.helper.Contacts)8 RobolectricTest (com.fsck.k9.RobolectricTest)6 Test (org.junit.Test)6 Uri (android.net.Uri)3 Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Message (android.os.Message)1 Parcelable (android.os.Parcelable)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextWatcher (android.text.TextWatcher)1 TypedValue (android.util.TypedValue)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1