Example usage for android.text.util Rfc822Token Rfc822Token

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

Introduction

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

Prototype

public Rfc822Token(@Nullable String name, @Nullable String address, @Nullable String comment) 

Source Link

Document

Creates a new Rfc822Token with the specified name, address, and comment.

Usage

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.  j  av a2s.  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.ex.chips.RecipientEditTextView.java

String createChipDisplayText(final RecipientEntry entry) {
    String display = entry.getDisplayName();
    final String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address))
        display = null;//from   w w  w . ja v  a2  s  .  c  o  m
    if (!TextUtils.isEmpty(display))
        return display;
    else if (!TextUtils.isEmpty(address))
        return address;
    else
        return new Rfc822Token(display, address, null).toString();
}

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  ww  w. j  a v a 2 s. 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.
 *//*from  www  . j av  a2  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.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  ww  w.j  a va  2s  . c o m*/
    }
    //[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
}