use of com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder in project android_packages_apps_Dialer by MoKee.
the class PhoneNumberUtil method getGeoDescription.
/**
* @return a geographical description string for the specified number.
* @see com.android.i18n.phonenumbers.PhoneNumberOfflineGeocoder
*/
public static String getGeoDescription(Context context, String number) {
Log.v(TAG, "getGeoDescription('" + pii(number) + "')...");
if (TextUtils.isEmpty(number)) {
return null;
}
com.google.i18n.phonenumbers.PhoneNumberUtil util = com.google.i18n.phonenumbers.PhoneNumberUtil.getInstance();
PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
Locale locale = context.getResources().getConfiguration().locale;
String countryIso = TelephonyManagerUtils.getCurrentCountryIso(context, locale);
Phonenumber.PhoneNumber pn = null;
try {
Log.v(TAG, "parsing '" + pii(number) + "' for countryIso '" + countryIso + "'...");
pn = util.parse(number, countryIso);
Log.v(TAG, "- parsed number: " + pii(pn));
} catch (NumberParseException e) {
Log.v(TAG, "getGeoDescription: NumberParseException for incoming number '" + pii(number) + "'");
}
if (pn != null) {
String description = geocoder.getDescriptionForNumber(pn, locale);
Log.v(TAG, "- got description: '" + description + "'");
return description;
}
return null;
}
use of com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder in project android_packages_apps_Dialer by LineageOS.
the class GeoUtil method getGeocodedLocationFor.
public static String getGeocodedLocationFor(Context context, String phoneNumber) {
final PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
try {
final Phonenumber.PhoneNumber structuredPhoneNumber = phoneNumberUtil.parse(phoneNumber, getCurrentCountryIso(context));
final Locale locale = context.getResources().getConfiguration().locale;
return geocoder.getDescriptionForNumber(structuredPhoneNumber, locale);
} catch (NumberParseException e) {
return null;
}
}
use of com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder in project android_packages_apps_Dialer by LineageOS.
the class PhoneNumberHelper method getGeoDescription.
/**
* @return a geographical description string for the specified number.
* @see com.android.i18n.phonenumbers.PhoneNumberOfflineGeocoder
*/
public static String getGeoDescription(Context context, String number) {
LogUtil.v("PhoneNumberHelper.getGeoDescription", "" + LogUtil.sanitizePii(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.PhoneNumber pn = null;
try {
LogUtil.v("PhoneNumberHelper.getGeoDescription", "parsing '" + LogUtil.sanitizePii(number) + "' for countryIso '" + countryIso + "'...");
pn = util.parse(number, countryIso);
LogUtil.v("PhoneNumberHelper.getGeoDescription", "- parsed number: " + LogUtil.sanitizePii(pn));
} catch (NumberParseException e) {
LogUtil.e("PhoneNumberHelper.getGeoDescription", "getGeoDescription: NumberParseException for incoming number '" + LogUtil.sanitizePii(number) + "'");
}
if (pn != null) {
String description = geocoder.getDescriptionForNumber(pn, locale);
LogUtil.v("PhoneNumberHelper.getGeoDescription", "- got description: '" + description + "'");
return description;
}
return null;
}
Aggregations