Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d95a02c2 authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

Fix test breakage in Zaku. Modification to PhoneNumberUtils included.

Also add method String formatNumber(String source, int defaultFormattingType) with @hide tag.

Internal Issue number: 2217362
parent 3c828e24
Loading
Loading
Loading
Loading
+5 −17
Original line number Diff line number Diff line
@@ -480,23 +480,11 @@ public class ContactStruct {
            }
        }

        final String formattedPhoneNumber;
        {
            final String rawPhoneNumber = builder.toString();
            if (VCardConfig.isJapaneseDevice(mVCardType)) {
                // As of 2009-10-07, there's no formatNumber() which accepts
                // the second argument and returns String directly. 
                final SpannableStringBuilder tmpBuilder =
                    new SpannableStringBuilder(rawPhoneNumber);
                PhoneNumberUtils.formatNumber(tmpBuilder, PhoneNumberUtils.FORMAT_JAPAN);
                formattedPhoneNumber = tmpBuilder.toString();
            } else {
                // There's no information available on vCard side. Depend on the default
                // behavior, which may cause problem in the future when the additional format
                // rule is supported (e.g. PhoneNumberUtils.FORMAT_KLINGON)
                formattedPhoneNumber = PhoneNumberUtils.formatNumber(rawPhoneNumber);
            }
        }
        // Use NANP in default when there's no information about locale.
        final int formattingType = (VCardConfig.isJapaneseDevice(mVCardType) ?
                PhoneNumberUtils.FORMAT_JAPAN : PhoneNumberUtils.FORMAT_NANP);
        final String formattedPhoneNumber =
                PhoneNumberUtils.formatNumber(builder.toString(), formattingType);
        PhoneData phoneData = new PhoneData(type, formattedPhoneNumber, label, isPrimary);
        mPhoneList.add(phoneData);
    }
+22 −4
Original line number Diff line number Diff line
@@ -1060,8 +1060,8 @@ public class PhoneNumberUtils
     * Breaks the given number down and formats it according to the rules
     * for the country the number is from.
     *
     * @param source the phone number to format
     * @return a locally acceptable formatting of the input, or the raw input if
     * @param source The phone number to format
     * @return A locally acceptable formatting of the input, or the raw input if
     *  formatting rules aren't known for the number
     */
    public static String formatNumber(String source) {
@@ -1070,11 +1070,28 @@ public class PhoneNumberUtils
        return text.toString();
    }

    /**
     * Formats the given number with the given formatting type. Currently
     * {@link #FORMAT_NANP} and {@link #FORMAT_JAPAN} are supported as a formating type.
     *
     * @param source the phone number to format
     * @param defaultFormattingType The default formatting rules to apply if the number does
     * not begin with +<country_code>
     * @return The phone number formatted with the given formatting type.
     *
     * @hide TODO:Shuold be unhidden.
     */
    public static String formatNumber(String source, int defaultFormattingType) {
        SpannableStringBuilder text = new SpannableStringBuilder(source);
        formatNumber(text, defaultFormattingType);
        return text.toString();
    }

    /**
     * Returns the phone number formatting type for the given locale.
     *
     * @param locale The locale of interest, usually {@link Locale#getDefault()}
     * @return the formatting type for the given locale, or FORMAT_UNKNOWN if the formatting
     * @return The formatting type for the given locale, or FORMAT_UNKNOWN if the formatting
     * rules are not known for the given locale
     */
    public static int getFormatTypeForLocale(Locale locale) {
@@ -1084,7 +1101,8 @@ public class PhoneNumberUtils
    }

    /**
     * Formats a phone number in-place. Currently only supports NANP formatting.
     * Formats a phone number in-place. Currently {@link #FORMAT_JAPAN} and {@link #FORMAT_NANP}
     * is supported as a second argument.
     *
     * @param text The number to be formatted, will be modified with the formatting
     * @param defaultFormattingType The default formatting rules to apply if the number does