android.text.util.Rfc822Token

Here are the examples of the java api class android.text.util.Rfc822Token taken from open source projects.

1. TextUtilsTest#testRfc822TokenizeItemWithError()

Project: j2objc
File: TextUtilsTest.java
@SmallTest
public void testRfc822TokenizeItemWithError() {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("\"Foo Bar\\");
    assertNotNull(tokens);
    assertEquals(1, tokens.length);
    assertEquals("Foo Bar", tokens[0].getAddress());
}

2. TextUtilsTest#testRfc822TokenizerFullAddress()

Project: j2objc
File: TextUtilsTest.java
@SmallTest
public void testRfc822TokenizerFullAddress() {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("Foo Bar (something) <[email protected]>");
    assertNotNull(tokens);
    assertEquals(1, tokens.length);
    assertEquals("[email protected]", tokens[0].getAddress());
    assertEquals("Foo Bar", tokens[0].getName());
    assertEquals("something", tokens[0].getComment());
}

3. RecipientEntry#constructFakeEntry()

Project: ChipsLibrary
File: RecipientEntry.java
/**
 * Construct a RecipientEntry from just an address that has been entered. This address has not been resolved to a
 * contact and therefore does not have a contact id or photo.
 */
public static RecipientEntry constructFakeEntry(final String address, final boolean isValid) {
    final Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(address);
    final String tokenizedAddress = tokens.length > 0 ? tokens[0].getAddress() : address;
    return new RecipientEntry(ENTRY_TYPE_PERSON, tokenizedAddress, tokenizedAddress, INVALID_DESTINATION_TYPE, null, INVALID_CONTACT, INVALID_CONTACT, null, true, isValid, false);
}

4. RecipientEditTextView#tokenizeAddress()

Project: ChipsLibrary
File: RecipientEditTextView.java
private static String tokenizeAddress(final String destination) {
    final Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(destination);
    if (tokens != null && tokens.length > 0)
        return tokens[0].getAddress();
    return destination;
}

5. RecipientEditTextView#createTokenizedEntry()

Project: ChipsLibrary
File: RecipientEditTextView.java
// VisibleForTesting
RecipientEntry createTokenizedEntry(final String token) {
    if (TextUtils.isEmpty(token))
        return null;
    if (isPhoneQuery() && isPhoneNumber(token))
        return RecipientEntry.constructFakePhoneEntry(token, true);
    final Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(token);
    String display = null;
    boolean isValid = isValid(token);
    if (isValid && tokens != null && tokens.length > 0) {
        // If we can get a name from tokenizing, then generate an entry from
        // this.
        display = tokens[0].getName();
        if (!TextUtils.isEmpty(display))
            return RecipientEntry.constructGeneratedEntry(display, tokens[0].getAddress(), isValid);
        else {
            display = tokens[0].getAddress();
            if (!TextUtils.isEmpty(display))
                return RecipientEntry.constructFakeEntry(display, isValid);
        }
    }
    // Unable to validate the token or to create a valid token from it.
    // Just create a chip the user can edit.
    String validatedToken = null;
    if (mValidator != null && !isValid) {
        // Try fixing up the entry using the validator.
        validatedToken = mValidator.fixText(token).toString();
        if (!TextUtils.isEmpty(validatedToken))
            if (validatedToken.contains(token)) {
                // protect against the case of a validator with a null
                // domain,
                // which doesn't add a domain to the token
                final Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(validatedToken);
                if (tokenized.length > 0) {
                    validatedToken = tokenized[0].getAddress();
                    isValid = true;
                }
            } else {
                // We ran into a case where the token was invalid and
                // removed
                // by the validator. In this case, just use the original
                // token
                // and let the user sort out the error chip.
                validatedToken = null;
                isValid = false;
            }
    }
    // Otherwise, fallback to just creating an editable email address chip.
    return RecipientEntry.constructFakeEntry(!TextUtils.isEmpty(validatedToken) ? validatedToken : token, isValid);
}

6. AddContactActivity#inviteBuddies()

Project: ChatSecureAndroid
File: AddContactActivity.java
void inviteBuddies() {
    Rfc822Token[] recipients = Rfc822Tokenizer.tokenize(mAddressList.getText());
    try {
        IImConnection conn = mApp.getConnection(mProviderId);
        IContactList list = getContactList(conn);
        if (list == null) {
            // Log.e(ImApp.LOG_TAG, "<AddContactActivity> can't find given contact list:"
            //                    + getSelectedListName());
            finish();
        } else {
            boolean fail = false;
            String username = null;
            for (Rfc822Token recipient : recipients) {
                username = recipient.getAddress();
                if (username.indexOf('@') == -1) {
                    username = username + "@" + getDomain(mProviderId);
                }
                if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
                    log("addContact:" + username);
                }
                int res = list.addContact(username);
                if (res != ImErrorInfo.NO_ERROR) {
                    fail = true;
                    mHandler.showAlert(R.string.error, ErrorResUtils.getErrorRes(getResources(), res, username));
                }
            }
            // close the screen if there's no error.
            if (!fail) {
                if (username != null) {
                    Intent intent = new Intent();
                    intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME, username);
                    intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, mProviderId);
                    setResult(RESULT_OK, intent);
                    finish();
                }
            }
        }
    } catch (RemoteException ex) {
        Log.e(ImApp.LOG_TAG, "<AddContactActivity> inviteBuddies: caught " + ex);
    }
}