Example usage for android.text.util Rfc822Token getAddress

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

Introduction

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

Prototype

@Nullable
public String getAddress() 

Source Link

Document

Returns the address part.

Usage

From source file:info.guardianproject.otr.app.im.app.AddContactActivity.java

void inviteBuddies() {
    Rfc822Token[] recipients = Rfc822Tokenizer.tokenize(mAddressList.getText());
    try {//from w w  w.  j a v  a  2  s.  c o m
        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);
    }
}

From source file:org.awesomeapp.messenger.ui.AddContactActivity.java

void inviteBuddies() {
    Rfc822Token[] recipients = Rfc822Tokenizer.tokenize(mNewAddress.getText());

    Pattern pattern = Pattern.compile(EMAIL_PATTERN);

    boolean foundOne = false;

    for (Rfc822Token recipient : recipients) {

        String address = recipient.getAddress();
        if (pattern.matcher(address).matches()) {
            new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp)
                    .execute(address, null, null);
            foundOne = true;//w  w w  .  ja  v a 2  s.c om
        }
    }

    if (foundOne) {
        Intent intent = new Intent();
        intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME, recipients[0].getAddress());
        intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, mApp.getDefaultProviderId());
        setResult(RESULT_OK, intent);
        finish();
    }

}

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

private static HashSet<String> convertToHashSet(final List<Rfc822Token[]> list) {
    final HashSet<String> hash = new HashSet<String>();
    for (final Rfc822Token[] tokens : list) {
        for (final Rfc822Token token : tokens) {
            hash.add(token.getAddress());
        }/*from   w  w w  .j a  v  a 2  s  .  c om*/
    }
    return hash;
}

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  .java  2 s.c  o  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

/**
 * Compare all the recipients of an email to the current account and all
 * custom addresses associated with that account. Return the match if there
 * is one, or the default account if there isn't.
 *//*from  w  w w. j  ava2  s  . co m*/
protected ReplyFromAccount getMatchingRecipient(Account account, List<String> sentTo) {
    // Tokenize the list and place in a hashmap.
    ReplyFromAccount matchingReplyFrom = null;
    Rfc822Token[] tokens;
    HashSet<String> recipientsMap = new HashSet<String>();
    for (String address : sentTo) {
        tokens = Rfc822Tokenizer.tokenize(address);
        for (final Rfc822Token token : tokens) {
            recipientsMap.add(token.getAddress());
        }
    }

    int matchingAddressCount = 0;
    List<ReplyFromAccount> customFroms;
    customFroms = account.getReplyFroms();
    if (customFroms != null) {
        for (ReplyFromAccount entry : customFroms) {
            if (recipientsMap.contains(entry.address)) {
                matchingReplyFrom = entry;
                matchingAddressCount++;
            }
        }
    }
    if (matchingAddressCount > 1) {
        matchingReplyFrom = getDefaultReplyFromAccount(account);
    }
    return matchingReplyFrom;
}

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

@VisibleForTesting
protected void addCcAddressesToList(List<Rfc822Token[]> addresses, List<Rfc822Token[]> compareToList,
        RecipientEditTextView list) {/* ww  w  .  j av  a2s. 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);
                }
            }
        }
    }
}