Search in sources :

Example 1 with PhoneNumberUtil

use of com.android.i18n.phonenumbers.PhoneNumberUtil in project platform_frameworks_base by android.

the class LinkSpec method gatherTelLinks.

private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(), Locale.getDefault().getCountry(), Leniency.POSSIBLE, Long.MAX_VALUE);
    for (PhoneNumberMatch match : matches) {
        LinkSpec spec = new LinkSpec();
        spec.url = "tel:" + PhoneNumberUtils.normalizeNumber(match.rawString());
        spec.start = match.start();
        spec.end = match.end();
        links.add(spec);
    }
}
Also used : PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumberMatch(com.android.i18n.phonenumbers.PhoneNumberMatch)

Example 2 with PhoneNumberUtil

use of com.android.i18n.phonenumbers.PhoneNumberUtil in project platform_frameworks_base by android.

the class CallerInfo method getGeoDescription.

/**
     * @return a geographical description string for the specified number.
     * @see com.android.i18n.phonenumbers.PhoneNumberOfflineGeocoder
     */
private static String getGeoDescription(Context context, String number) {
    if (VDBG)
        Rlog.v(TAG, "getGeoDescription('" + number + "')...");
    if (TextUtils.isEmpty(number)) {
        return null;
    }
    PhoneNumberUtil util = PhoneNumberUtil.getInstance();
    PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
    Locale locale = context.getResources().getConfiguration().locale;
    String countryIso = getCurrentCountryIso(context, locale);
    PhoneNumber pn = null;
    try {
        if (VDBG)
            Rlog.v(TAG, "parsing '" + number + "' for countryIso '" + countryIso + "'...");
        pn = util.parse(number, countryIso);
        if (VDBG)
            Rlog.v(TAG, "- parsed number: " + pn);
    } catch (NumberParseException e) {
        Rlog.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + Rlog.pii(TAG, number) + "'");
    }
    if (pn != null) {
        String description = geocoder.getDescriptionForNumber(pn, locale);
        if (VDBG)
            Rlog.v(TAG, "- got description: '" + description + "'");
        return description;
    } else {
        return null;
    }
}
Also used : Locale(java.util.Locale) PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumberOfflineGeocoder(com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Example 3 with PhoneNumberUtil

use of com.android.i18n.phonenumbers.PhoneNumberUtil in project XobotOS by xamarin.

the class PhoneNumberUtils method formatNumberToE164.

/**
     * Format the given phoneNumber to the E.164 representation.
     * <p>
     * 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.
     *
     * @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.
     *
     * @hide
     */
public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) {
    PhoneNumberUtil util = PhoneNumberUtil.getInstance();
    String result = null;
    try {
        PhoneNumber pn = util.parse(phoneNumber, defaultCountryIso);
        if (util.isValidNumber(pn)) {
            result = util.format(pn, PhoneNumberFormat.E164);
        }
    } catch (NumberParseException e) {
    }
    return result;
}
Also used : PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Example 4 with PhoneNumberUtil

use of com.android.i18n.phonenumbers.PhoneNumberUtil in project android_frameworks_base by ParanoidAndroid.

the class PhoneNumberUtils method formatNumberToE164.

/**
     * Format the given phoneNumber to the E.164 representation.
     * <p>
     * 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.
     *
     * @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.
     *
     * @hide
     */
public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) {
    PhoneNumberUtil util = PhoneNumberUtil.getInstance();
    String result = null;
    try {
        PhoneNumber pn = util.parse(phoneNumber, defaultCountryIso);
        if (util.isValidNumber(pn)) {
            result = util.format(pn, PhoneNumberFormat.E164);
        }
    } catch (NumberParseException e) {
    }
    return result;
}
Also used : PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Example 5 with PhoneNumberUtil

use of com.android.i18n.phonenumbers.PhoneNumberUtil in project XobotOS by xamarin.

the class CallerInfo method getGeoDescription.

/**
     * @return a geographical description string for the specified number.
     * @see com.android.i18n.phonenumbers.PhoneNumberOfflineGeocoder
     */
private static String getGeoDescription(Context context, String number) {
    if (VDBG)
        Log.v(TAG, "getGeoDescription('" + number + "')...");
    if (TextUtils.isEmpty(number)) {
        return null;
    }
    PhoneNumberUtil util = PhoneNumberUtil.getInstance();
    PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
    Locale locale = context.getResources().getConfiguration().locale;
    String countryIso = getCurrentCountryIso(context, locale);
    PhoneNumber pn = null;
    try {
        if (VDBG)
            Log.v(TAG, "parsing '" + number + "' for countryIso '" + countryIso + "'...");
        pn = util.parse(number, countryIso);
        if (VDBG)
            Log.v(TAG, "- parsed number: " + pn);
    } catch (NumberParseException e) {
        Log.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + number + "'");
    }
    if (pn != null) {
        String description = geocoder.getDescriptionForNumber(pn, locale);
        if (VDBG)
            Log.v(TAG, "- got description: '" + description + "'");
        return description;
    } else {
        return null;
    }
}
Also used : Locale(java.util.Locale) PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumberOfflineGeocoder(com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Aggregations

PhoneNumberUtil (com.android.i18n.phonenumbers.PhoneNumberUtil)22 NumberParseException (com.android.i18n.phonenumbers.NumberParseException)16 PhoneNumber (com.android.i18n.phonenumbers.Phonenumber.PhoneNumber)16 PhoneNumberMatch (com.android.i18n.phonenumbers.PhoneNumberMatch)6 PhoneNumberOfflineGeocoder (com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder)6 Locale (java.util.Locale)6 TtsSpan (android.text.style.TtsSpan)4