android.text.util.Rfc822Token Java Examples

The following examples show how to use android.text.util.Rfc822Token. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecipientEditTextView.java    From talk-android with MIT License 6 votes vote down vote up
String createAddressText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    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.
            Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0) {
                address = tokenized[0].getAddress();
            }
        }
        Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer
            .terminateToken(trimmedDisplayText) : trimmedDisplayText;
}
 
Example #2
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 6 votes vote down vote up
String createAddressText(final RecipientEntry entry)
{
String display=entry.getDisplayName();
String address=entry.getDestination();
if(TextUtils.isEmpty(display)||TextUtils.equals(display,address))
  display=null;
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;
}
 
Example #3
Source File: TextChipsEditView.java    From talk-android with MIT License 6 votes vote down vote up
String createAddressText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    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.
            Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0) {
                address = tokenized[0].getAddress();
            }
        }
        Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer
            .terminateToken(trimmedDisplayText) : trimmedDisplayText;
}
 
Example #4
Source File: EmailAddressAdapter.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public final String convertToString(Cursor cursor) {

  int POST_HONEYCOMB_NAME_INDEX = cursor.getColumnIndex(HoneycombMR1Util.getDisplayName());
  int POST_HONEYCOMB_EMAIL_INDEX = cursor.getColumnIndex(HoneycombMR1Util.getEmailAddress());
  String name = "";
  String address = "";

  if (SdkLevel.getLevel() >= SdkLevel.LEVEL_HONEYCOMB_MR1) {
    name = cursor.getString(POST_HONEYCOMB_NAME_INDEX);
    address = cursor.getString(POST_HONEYCOMB_EMAIL_INDEX);
  } else {
    name = cursor.getString(PRE_HONEYCOMB_NAME_INDEX);
    address = cursor.getString(PRE_HONEYCOMB_DATA_INDEX);
  }

  return new Rfc822Token(name, address, null).toString();
}
 
Example #5
Source File: RecipientEntry.java    From talk-android with MIT License 5 votes vote down vote up
/**
 * 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, null /* directoryId */,
            INVALID_CONTACT, null, true, isValid, null /* lookupKey */);
}
 
Example #6
Source File: BaseRecipientAdapter.java    From ChipsLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence convertResultToString(final Object resultValue)
  {
  final RecipientEntry entry=(RecipientEntry)resultValue;
  final String displayName=entry.getDisplayName();
  final String emailAddress=entry.getDestination();
  if(TextUtils.isEmpty(displayName)||TextUtils.equals(displayName,emailAddress))
    return emailAddress;
  else return new Rfc822Token(displayName,emailAddress,null).toString();
  }
 
Example #7
Source File: RecipientEntry.java    From ChipsLibrary with Apache License 2.0 5 votes vote down vote up
/**
 * 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 /* isGalContact */);
  }
 
Example #8
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 5 votes vote down vote up
String createChipDisplayText(final RecipientEntry entry)
{
String display=entry.getDisplayName();
final String address=entry.getDestination();
if(TextUtils.isEmpty(display)||TextUtils.equals(display,address))
  display=null;
if(!TextUtils.isEmpty(display))
  return display;
else if(!TextUtils.isEmpty(address))
  return address;
else return new Rfc822Token(display,address,null).toString();
}
 
Example #9
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: TextUtilsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@SmallTest
public void testRfc822TokenizeItemWithError() {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("\"Foo Bar\\");
    assertNotNull(tokens);
    assertEquals(1, tokens.length);
    assertEquals("Foo Bar", tokens[0].getAddress());
}
 
Example #11
Source File: TextUtilsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: BaseRecipientAdapter.java    From talk-android with MIT License 5 votes vote down vote up
@Override
public CharSequence convertResultToString(Object resultValue) {
    final RecipientEntry entry = (RecipientEntry)resultValue;
    final String displayName = entry.getDisplayName();
    final String emailAddress = entry.getDestination();
    if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, emailAddress)) {
         return emailAddress;
    } else {
        return new Rfc822Token(displayName, emailAddress, null).toString();
    }
}
 
Example #13
Source File: TextChipsEditView.java    From talk-android with MIT License 5 votes vote down vote up
String createChipDisplayText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    if (!TextUtils.isEmpty(display)) {
        return display;
    } else if (!TextUtils.isEmpty(address)) {
        return address;
    } else {
        return new Rfc822Token(display, address, null).toString();
    }
}
 
Example #14
Source File: TextChipsEditView.java    From talk-android with MIT License 5 votes vote down vote up
private static String tokenizeAddress(String destination) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(destination);
    if (tokens != null && tokens.length > 0) {
        return tokens[0].getAddress();
    }
    return destination;
}
 
Example #15
Source File: RecipientEditTextView.java    From talk-android with MIT License 5 votes vote down vote up
String createChipDisplayText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    if (!TextUtils.isEmpty(display)) {
        return display;
    } else if (!TextUtils.isEmpty(address)) {
        return address;
    } else {
        return new Rfc822Token(display, address, null).toString();
    }
}
 
Example #16
Source File: RecipientEditTextView.java    From talk-android with MIT License 5 votes vote down vote up
private static String tokenizeAddress(String destination) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(destination);
    if (tokens != null && tokens.length > 0) {
        return tokens[0].getAddress();
    }
    return destination;
}
 
Example #17
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #18
Source File: TextChipsEditView.java    From talk-android with MIT License 4 votes vote down vote up
RecipientEntry createTokenizedEntry(final String token) {
    if (TextUtils.isEmpty(token)) {
        return null;
    }
    if (isPhoneQuery() && isPhoneNumber(token)) {
        return RecipientEntry.constructFakePhoneEntry(token, true);
    }
    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
                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);
}
 
Example #19
Source File: RecipientEditTextView.java    From talk-android with MIT License 4 votes vote down vote up
RecipientEntry createTokenizedEntry(final String token) {
    if (TextUtils.isEmpty(token)) {
        return null;
    }
    if (isPhoneQuery() && isPhoneNumber(token)) {
        return RecipientEntry.constructFakePhoneEntry(token, true);
    }
    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
                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);
}