Example usage for android.text.util Rfc822Tokenizer tokenize

List of usage examples for android.text.util Rfc822Tokenizer tokenize

Introduction

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

Prototype

public static Rfc822Token[] tokenize(CharSequence text) 

Source Link

Document

This method will try to take a string like "Foo Bar (something) <foo\@google.com>, blah\@google.com (something)" and convert it into one or more Rfc822Tokens.

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;/*  www .j a  v  a 2  s .  c  o m*/
    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

private static void addAddressToList(final String address, final RecipientEditTextView list) {
    if (address == null || list == null)
        return;//w ww  . ja va 2 s. c o m

    final Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(address);

    for (final Rfc822Token token : tokens) {
        list.append(token + END_TOKEN);
    }
}

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

protected List<Rfc822Token[]> tokenizeAddressList(Collection<String> addresses) {
    @VisibleForTesting/*  ww  w.ja  v a 2 s  .  co m*/
    List<Rfc822Token[]> tokenized = new ArrayList<Rfc822Token[]>();

    for (String address : addresses) {
        tokenized.add(Rfc822Tokenizer.tokenize(address));
    }
    return tokenized;
}

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

private void addAddressesToRecipientList(final List<String> recipients, final String addressString) {
    if (recipients == null) {
        throw new IllegalArgumentException("recipientList cannot be null");
    }/*from  w  w  w. ja va 2  s .  co  m*/
    if (TextUtils.isEmpty(addressString)) {
        return;
    }
    final Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressString);
    for (final Rfc822Token token : tokens) {
        recipients.add(token.getAddress());
    }
}

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

public String[] getAddressesFromList(RecipientEditTextView list) {
    if (list == null) {
        return new String[0];
    }//from   ww  w. j  ava2  s . c o m
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(list.getText());
    int count = tokens.length;
    String[] result = new String[count];
    for (int i = 0; i < count; i++) {
        result[i] = tokens[i].toString();
    }
    return result;
}

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

/**
 * Returns a list of email addresses from the recipients. List only contains
 * email addresses strips additional info like the recipient's name.
 *///from w w w  .ja va2 s .  com
private static ArrayList<String> buildEmailAddressList(String[] recips) {
    // Tokenize them all and put them in the list.
    final ArrayList<String> recipAddresses = Lists.newArrayListWithCapacity(recips.length);
    for (int i = 0; i < recips.length; i++) {
        recipAddresses.add(Rfc822Tokenizer.tokenize(recips[i])[0].getAddress());
    }
    return recipAddresses;
}