Example usage for android.text.util Rfc822Token toString

List of usage examples for android.text.util Rfc822Token toString

Introduction

In this page you can find the example usage for android.text.util Rfc822Token toString.

Prototype

public String toString() 

Source Link

Document

Returns the name (with quoting added if necessary), the comment (in parentheses), and the address (in angle brackets).

Usage

From source file:com.xandy.calendar.EventInfoFragment.java

/**
 * Taken from com.google.android.gm.HtmlConversationActivity
 *
 * Send the intent that shows the Contact info corresponding to the email address.
 *//*from   w  w  w  .  jav a  2s . c o  m*/
public void showContactInfo(CalendarEventModel.Attendee attendee, Rect rect) {
    // First perform lookup query to find existing contact
    final ContentResolver resolver = getActivity().getContentResolver();
    final String address = attendee.mEmail;
    final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address));
    final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri);

    if (lookupUri != null) {
        // Found matching contact, trigger QuickContact
        QuickContact.showQuickContact(getActivity(), rect, lookupUri, QuickContact.MODE_MEDIUM, null);
    } else {
        // No matching contact, ask user to create one
        final Uri mailUri = Uri.fromParts("mailto", address, null);
        final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mailUri);

        // Pass along full E-mail string for possible create dialog
        Rfc822Token sender = new Rfc822Token(attendee.mName, attendee.mEmail, null);
        intent.putExtra(Intents.EXTRA_CREATE_DESCRIPTION, sender.toString());

        // Only provide personal name hint if we have one
        final String senderPersonal = attendee.mName;
        if (!TextUtils.isEmpty(senderPersonal)) {
            intent.putExtra(Intents.Insert.NAME, senderPersonal);
        }

        startActivity(intent);
    }
}

From source file:com.android.calendar.EventInfoFragment.java

/**
 * Taken from com.google.android.gm.HtmlConversationActivity
 *
 * Send the intent that shows the Contact info corresponding to the email address.
 *//*  w ww. ja  va  2  s .c  o  m*/
public void showContactInfo(Attendee attendee, Rect rect) {
    // First perform lookup query to find existing contact
    final ContentResolver resolver = getActivity().getContentResolver();
    final String address = attendee.mEmail;
    final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address));
    final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri);

    if (lookupUri != null) {
        // Found matching contact, trigger QuickContact
        QuickContact.showQuickContact(getActivity(), rect, lookupUri, QuickContact.MODE_MEDIUM, null);
    } else {
        // No matching contact, ask user to create one
        final Uri mailUri = Uri.fromParts("mailto", address, null);
        final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mailUri);

        // Pass along full E-mail string for possible create dialog
        Rfc822Token sender = new Rfc822Token(attendee.mName, attendee.mEmail, null);
        intent.putExtra(Intents.EXTRA_CREATE_DESCRIPTION, sender.toString());

        // Only provide personal name hint if we have one
        final String senderPersonal = attendee.mName;
        if (!TextUtils.isEmpty(senderPersonal)) {
            intent.putExtra(Intents.Insert.NAME, senderPersonal);
        }

        startActivity(intent);
    }
}

From source file:com.android.ex.chips.RecipientEditTextView.java

String createAddressText(final RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address))
        display = null;//from w  w  w  .  ja v  a2  s  . c om
    String trimmedDisplayText;
    if (isPhoneQuery() && isPhoneNumber(address))
        trimmedDisplayText = address.trim();
    else {
        if (address != null) {
            // Tokenize out the address in case the address already
            // contained the username as well.
            final Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0)
                address = tokenized[0].getAddress();
        }
        final Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    final int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer.terminateToken(trimmedDisplayText)
                    : trimmedDisplayText;
}

From source file:com.android.mail.compose.ComposeActivity.java

@VisibleForTesting
protected void addCcAddressesToList(List<Rfc822Token[]> addresses, List<Rfc822Token[]> compareToList,
        RecipientEditTextView list) {/*from  www  .  j  a v a  2  s.c  o m*/
    String address;

    if (compareToList == null) {
        for (final Rfc822Token[] tokens : addresses) {
            for (final Rfc822Token token : tokens) {
                address = token.toString();
                list.append(address + END_TOKEN);
            }
        }
    } else {
        HashSet<String> compareTo = convertToHashSet(compareToList);
        for (final Rfc822Token[] tokens : addresses) {
            for (final Rfc822Token token : tokens) {
                address = token.toString();
                // Check if this is a duplicate:
                if (!compareTo.contains(token.getAddress())) {
                    // Get the address here
                    list.append(address + END_TOKEN);
                }
            }
        }
    }
}

From source file:com.tct.mail.compose.ComposeActivity.java

private void addAddressFromData(RecipientEditTextView view, Intent data) {
    //[FEATURE]-Mod-BEGIN by TSCD.chao zhang,04/22/2014,fix email crash during press back key during choosing nothing in Contacts.
    if (data == null) {
        return;/*from  w  w  w  .  ja  va2  s  .com*/
    }
    //[FEATURE]-Mod-END  by TSCD.chao zhang
    Bundle b = data.getExtras();
    Bundle choiceSet = b.getBundle("result");
    Set<String> set = choiceSet.keySet();
    Iterator<String> i = set.iterator();
    //TS: junwei-xu 2016-01-25 EMAIL BUGFIX-1496954 MOD_S
    String itemName, itemAddress;
    Rfc822Token token;
    // TS: zhaotianyong 2015-02-28 EMAIL BUGFIX-926303 ADD_S
    int recipientsCounts = 0;
    // TS: zhaotianyong 2015-02-28 EMAIL BUGFIX-926303 ADD_E
    while (i.hasNext()) {
        // TS: zhaotianyong 2015-02-28 EMAIL BUGFIX-926303 ADD_S
        recipientsCounts++;
        if (recipientsCounts > RECIPIENT_MAX_NUMBER) {
            Utility.showToast(this, this.getString(R.string.not_add_more_recipients, RECIPIENT_MAX_NUMBER));
            return;
        }
        // TS: zhaotianyong 2015-02-28 EMAIL BUGFIX-926303 ADD_E
        String key = i.next();
        String[] emails = choiceSet.getStringArray(key);
        itemName = emails[EMAIL_NAME_INDEX];
        itemAddress = emails[EMAIL_ADDRESS_INDEX];
        //TS: rong-tang 2016-03-28 EMAIL BUGFIX-1863457 MOD_S
        itemName = Rfc822Validator.fixInvalidName(itemName);
        //TS: rong-tang 2016-03-28 EMAIL BUGFIX-1863457 MOD_E
        token = new Rfc822Token(itemName, itemAddress, null);
        addAddressToList(token.toString(), view);
    }
    //TS: junwei-xu 2016-01-25 EMAIL BUGFIX-1496954 MOD_E
}