summaryrefslogtreecommitdiffstats
path: root/telephony/java/android
diff options
context:
space:
mode:
authorBen Gilad <gilad@google.com>2015-01-08 17:56:28 -0800
committerBen Gilad <gilad@google.com>2015-01-08 17:56:28 -0800
commit95cde2dc211f51deed6da2836d1bc7b23988782d (patch)
tree043e57830cc46a09f96d022b79f0140e27301f4e /telephony/java/android
parentadf1c93ff77c996be7952f98b9f554befb089543 (diff)
downloadframeworks_base-95cde2dc211f51deed6da2836d1bc7b23988782d.zip
frameworks_base-95cde2dc211f51deed6da2836d1bc7b23988782d.tar.gz
frameworks_base-95cde2dc211f51deed6da2836d1bc7b23988782d.tar.bz2
API to satisfy the dependency in https://go/contacthandler1135
Bug: 17586396 Change-Id: I10bad15b4db3ec8928316507119c529c5d1f304b
Diffstat (limited to 'telephony/java/android')
-rw-r--r--telephony/java/android/telephony/PhoneNumberUtils.java66
1 files changed, 46 insertions, 20 deletions
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java
index ba07a95..9d2a1ec 100644
--- a/telephony/java/android/telephony/PhoneNumberUtils.java
+++ b/telephony/java/android/telephony/PhoneNumberUtils.java
@@ -1145,6 +1145,7 @@ public class PhoneNumberUtils
*
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
+ @Deprecated
public static String formatNumber(String source) {
SpannableStringBuilder text = new SpannableStringBuilder(source);
formatNumber(text, getFormatTypeForLocale(Locale.getDefault()));
@@ -1163,6 +1164,7 @@ public class PhoneNumberUtils
* @hide
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
+ @Deprecated
public static String formatNumber(String source, int defaultFormattingType) {
SpannableStringBuilder text = new SpannableStringBuilder(source);
formatNumber(text, defaultFormattingType);
@@ -1178,6 +1180,7 @@ public class PhoneNumberUtils
*
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
+ @Deprecated
public static int getFormatTypeForLocale(Locale locale) {
String country = locale.getCountry();
@@ -1194,6 +1197,7 @@ public class PhoneNumberUtils
*
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
+ @Deprecated
public static void formatNumber(Editable text, int defaultFormattingType) {
int formatType = defaultFormattingType;
@@ -1242,6 +1246,7 @@ public class PhoneNumberUtils
*
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
+ @Deprecated
public static void formatNanpNumber(Editable text) {
int length = text.length();
if (length > "+1-nnn-nnn-nnnn".length()) {
@@ -1357,6 +1362,7 @@ public class PhoneNumberUtils
*
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
+ @Deprecated
public static void formatJapaneseNumber(Editable text) {
JapanesePhoneNumberFormatter.format(text);
}
@@ -1378,32 +1384,52 @@ public class PhoneNumberUtils
}
/**
- * Format the given phoneNumber to the E.164 representation.
+ * Formats the specified {@code phoneNumber} to the E.164 representation.
+ *
+ * @param phoneNumber the phone number to format.
+ * @param defaultCountryIso the ISO 3166-1 two letters country code.
+ * @return the E.164 representation, or null if the given phone number is not valid.
+ */
+ public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) {
+ return formatNumberInternal(phoneNumber, defaultCountryIso, PhoneNumberFormat.E164);
+ }
+
+ /**
+ * Formats the specified {@code phoneNumber} to the RFC3966 representation.
+ *
+ * @param phoneNumber the phone number to format.
+ * @param defaultCountryIso the ISO 3166-1 two letters country code.
+ * @return the RFC3966 representation, or null if the given phone number is not valid.
+ */
+ public static String formatNumberToRFC3966(String phoneNumber, String defaultCountryIso) {
+ return formatNumberInternal(phoneNumber, defaultCountryIso, PhoneNumberFormat.RFC3966);
+ }
+
+ /**
+ * Formats the raw phone number (string) using the specified {@code formatIdentifier}.
* <p>
- * The given phone number must have an area code and could have a country
- * code.
+ * The given phone number must have an area code and could have a country code.
* <p>
- * The defaultCountryIso is used to validate the given number and generate
- * the E.164 phone number if the given number doesn't have a country code.
+ * The defaultCountryIso is used to validate the given number and generate the formatted number
+ * if the specified number doesn't have a country code.
*
- * @param phoneNumber
- * the phone number to format
- * @param defaultCountryIso
- * the ISO 3166-1 two letters country code
- * @return the E.164 representation, or null if the given phone number is
- * not valid.
+ * @param rawPhoneNumber The phone number to format.
+ * @param defaultCountryIso The ISO 3166-1 two letters country code.
+ * @param formatIdentifier The (enum) identifier of the desired format.
+ * @return the formatted representation, or null if the specified number is not valid.
*/
- public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) {
+ private static String formatNumberInternal(
+ String rawPhoneNumber, String defaultCountryIso, PhoneNumberFormat formatIdentifier) {
+
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
- String result = null;
try {
- PhoneNumber pn = util.parse(phoneNumber, defaultCountryIso);
- if (util.isValidNumber(pn)) {
- result = util.format(pn, PhoneNumberFormat.E164);
+ PhoneNumber phoneNumber = util.parse(rawPhoneNumber, defaultCountryIso);
+ if (util.isValidNumber(phoneNumber)) {
+ return util.format(phoneNumber, formatIdentifier);
}
- } catch (NumberParseException e) {
- }
- return result;
+ } catch (NumberParseException ignored) { }
+
+ return null;
}
/**
@@ -2454,7 +2480,7 @@ public class PhoneNumberUtils
*
* @param number SIP address of the form "username@domainname"
* (or the URI-escaped equivalent "username%40domainname")
- * @see isUriNumber
+ * @see #isUriNumber
*
* @hide
*/