Search in sources :

Example 41 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project libsignal-service-java by signalapp.

the class PhoneNumberFormatter method getInternationalFormatFromE164.

public static String getInternationalFormatFromE164(String e164number) {
    try {
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        PhoneNumber parsedNumber = util.parse(e164number, null);
        return util.format(parsedNumber, PhoneNumberFormat.INTERNATIONAL);
    } catch (NumberParseException e) {
        Log.w(TAG, e);
        return e164number;
    }
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 42 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project libsignal-service-java by signalapp.

the class PhoneNumberFormatter method formatNumberInternational.

public static String formatNumberInternational(String number) {
    try {
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        PhoneNumber parsedNumber = util.parse(number, null);
        return util.format(parsedNumber, PhoneNumberFormat.INTERNATIONAL);
    } catch (NumberParseException e) {
        Log.w(TAG, e);
        return number;
    }
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 43 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project Signal-Android by signalapp.

the class PhoneNumberFormatter method formatNumber.

public static String formatNumber(String number, String localNumber) throws InvalidNumberException {
    if (number == null) {
        throw new InvalidNumberException("Null String passed as number.");
    }
    if (number.contains("@")) {
        throw new InvalidNumberException("Possible attempt to use email address.");
    }
    number = number.replaceAll("[^0-9+]", "");
    if (number.length() == 0) {
        throw new InvalidNumberException("No valid characters found.");
    }
    try {
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        PhoneNumber localNumberObject = util.parse(localNumber, null);
        String localCountryCode = util.getRegionCodeForNumber(localNumberObject);
        Log.w(TAG, "Got local CC: " + localCountryCode);
        PhoneNumber numberObject = util.parse(number, localCountryCode);
        return util.format(numberObject, PhoneNumberFormat.E164);
    } catch (NumberParseException e) {
        Log.w(TAG, e);
        return impreciseFormatNumber(number, localNumber);
    }
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 44 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project Signal-Android by signalapp.

the class PhoneNumberFormatter method getInternationalFormatFromE164.

public static String getInternationalFormatFromE164(String e164number) {
    try {
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        PhoneNumber parsedNumber = util.parse(e164number, null);
        return util.format(parsedNumber, PhoneNumberFormat.INTERNATIONAL);
    } catch (NumberParseException e) {
        Log.w(TAG, e);
        return e164number;
    }
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Example 45 with PhoneNumberUtil

use of com.google.i18n.phonenumbers.PhoneNumberUtil in project Signal-Android by signalapp.

the class PhoneNumberFormatter method formatE164.

public static String formatE164(String countryCode, String number) {
    try {
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        int parsedCountryCode = Integer.parseInt(countryCode);
        PhoneNumber parsedNumber = util.parse(number, util.getRegionCodeForCountryCode(parsedCountryCode));
        return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
    } catch (NumberParseException | NumberFormatException npe) {
        Log.w(TAG, npe);
    }
    return "+" + countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") + (number != null ? number.replaceAll("[^0-9]", "") : "");
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException)

Aggregations

PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)47 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)34 PhoneNumber (com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)23 Phonenumber (com.google.i18n.phonenumbers.Phonenumber)13 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)6 TextParameters (org.talend.dataquality.indicators.TextParameters)6 Locale (java.util.Locale)5 SuppressLint (android.annotation.SuppressLint)4 Nullable (androidx.annotation.Nullable)2 PhoneNumberOfflineGeocoder (com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder)2 RemoteLoginException (io.kamax.mxisd.exception.RemoteLoginException)2 IOException (java.io.IOException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)2 GenericValue (org.apache.ofbiz.entity.GenericValue)2 SpannableString (android.text.SpannableString)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1