Search in sources :

Example 1 with PhoneNumberMatch

use of com.google.i18n.phonenumbers.PhoneNumberMatch in project qksms by moezbhatti.

the class NumberToContactFormatter method format.

@Override
public String format(String text) {
    PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> matches = phoneNumberUtil.findNumbers(text, getCurrentCountryIso());
    for (PhoneNumberMatch match : matches) {
        Contact contact = Contact.get(match.rawString(), true);
        if (contact.isNamed()) {
            String nameAndNumber = phoneNumberUtil.format(match.number(), PhoneNumberFormat.NATIONAL) + " (" + contact.getName() + ")";
            text = text.replace(match.rawString(), nameAndNumber);
        }
    // If the contact doesn't exist yet, leave the number as-is
    }
    return text;
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumberMatch(com.google.i18n.phonenumbers.PhoneNumberMatch) Contact(com.moez.QKSMS.data.Contact)

Aggregations

PhoneNumberMatch (com.google.i18n.phonenumbers.PhoneNumberMatch)1 PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)1 Contact (com.moez.QKSMS.data.Contact)1