diff options
author | Ingo Bauersachs <ingo@jitsi.org> | 2016-05-15 17:15:01 +0200 |
---|---|---|
committer | Ingo Bauersachs <ingo@jitsi.org> | 2016-05-17 21:41:16 +0200 |
commit | 4e72851284659c03da5194958c8b885eda54af7c (patch) | |
tree | a9521cb68117b5059877a860e814f0d9959604c1 | |
parent | 8c25c8d0fa5b50c91a29bc76bd825d655b352d73 (diff) | |
download | jitsi-4e72851284659c03da5194958c8b885eda54af7c.zip jitsi-4e72851284659c03da5194958c8b885eda54af7c.tar.gz jitsi-4e72851284659c03da5194958c8b885eda54af7c.tar.bz2 |
Format phone number in tooltips
4 files changed, 51 insertions, 1 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java index 72bec25..08aaf7e 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java @@ -573,7 +573,7 @@ public class SourceUIContact } else { - labelText = contactDetail.getDetail(); + labelText = contactDetail.getDisplayName(); } jLabels[i] = new JLabel(filterAddressDisplay(labelText)); diff --git a/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java b/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java index d1942b2..4d4d417 100644 --- a/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java +++ b/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java @@ -18,6 +18,9 @@ package net.java.sip.communicator.impl.phonenumbers; import com.google.i18n.phonenumbers.*; +import com.google.i18n.phonenumbers.PhoneNumberUtil.*; +import com.google.i18n.phonenumbers.Phonenumber.*; + import net.java.sip.communicator.service.protocol.*; import org.jitsi.service.configuration.*; @@ -183,6 +186,33 @@ public class PhoneNumberI18nServiceImpl } /** + * Tries to format the passed phone number into the international format. If + * parsing fails or the string is not recognized as a valid phone number, + * the input is returned as is. + * + * @param phoneNumber The phone number to format. + * @return the formatted phone number in the international format. + */ + public String formatForDisplay(String phoneNumber) + { + try + { + PhoneNumber pn = PhoneNumberUtil.getInstance().parse(phoneNumber, + System.getProperty("user.country")); + if (PhoneNumberUtil.getInstance().isPossibleNumber(pn)) + { + return PhoneNumberUtil.getInstance().format(pn, + PhoneNumberFormat.INTERNATIONAL); + } + } + catch (NumberParseException e) + { + } + + return phoneNumber; + } + + /** * Indicates if the given string is possibly a phone number. * * @param possibleNumber the string to be verified diff --git a/src/net/java/sip/communicator/service/contactsource/ContactDetail.java b/src/net/java/sip/communicator/service/contactsource/ContactDetail.java index c062035..332c18d 100644 --- a/src/net/java/sip/communicator/service/contactsource/ContactDetail.java +++ b/src/net/java/sip/communicator/service/contactsource/ContactDetail.java @@ -438,9 +438,19 @@ public class ContactDetail this.contactDetailValue = contactDetailValue; if (!StringUtils.isNullOrEmpty(detailDisplayName)) + { this.detailDisplayName = detailDisplayName; + } + else if (category == Category.Phone) + { + this.detailDisplayName = + ContactSourceActivator.getPhoneNumberI18nService() + .formatForDisplay(contactDetailValue); + } else + { this.detailDisplayName = contactDetailValue; + } // category & labels this.category = category; diff --git a/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java b/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java index fa93ce1..521afc5 100644 --- a/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java +++ b/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java @@ -41,6 +41,16 @@ public interface PhoneNumberI18nService public String normalize(String possibleNumber); /** + * Tries to format the passed phone number into the international format. If + * parsing fails or the string is not recognized as a valid phone number, + * the input is returned as is. + * + * @param phoneNumber The phone number to format. + * @return the formatted phone number in the international format. + */ + public String formatForDisplay(String phoneNumber); + + /** * Determines whether two <tt>String</tt> phone numbers match. * * @param aPhoneNumber a <tt>String</tt> which represents a phone number to |