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;
}
Aggregations