use of com.android.i18n.phonenumbers.PhoneNumberUtil in project android_frameworks_base by crdroidandroid.
the class PhoneNumberUtils method createTtsSpan.
/**
* Create a {@code TtsSpan} for the supplied {@code String}.
*
* @param phoneNumberString A {@code String} the entirety of which represents a phone number.
* @return A {@code TtsSpan} for {@param phoneNumberString}.
*/
public static TtsSpan createTtsSpan(String phoneNumberString) {
if (phoneNumberString == null) {
return null;
}
// Parse the phone number
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
PhoneNumber phoneNumber = null;
try {
// Don't supply a defaultRegion so this fails for non-international numbers because
// we don't want to TalkBalk to read a country code (e.g. +1) if it is not already
// present
phoneNumber = phoneNumberUtil.parse(phoneNumberString, /* defaultRegion */
null);
} catch (NumberParseException ignored) {
}
// Build a telephone tts span
final TtsSpan.TelephoneBuilder builder = new TtsSpan.TelephoneBuilder();
if (phoneNumber == null) {
// Strip separators otherwise TalkBack will be silent
// (this behavior was observed with TalkBalk 4.0.2 from their alpha channel)
builder.setNumberParts(splitAtNonNumerics(phoneNumberString));
} else {
if (phoneNumber.hasCountryCode()) {
builder.setCountryCode(Integer.toString(phoneNumber.getCountryCode()));
}
builder.setNumberParts(Long.toString(phoneNumber.getNationalNumber()));
}
return builder.build();
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project android_frameworks_base by AOSPA.
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);
}
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project android_frameworks_base by ParanoidAndroid.
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 '" + number + "'");
}
if (pn != null) {
String description = geocoder.getDescriptionForNumber(pn, locale);
if (VDBG)
Rlog.v(TAG, "- got description: '" + description + "'");
return description;
} else {
return null;
}
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project platform_frameworks_base by android.
the class PhoneNumberUtils method createTtsSpan.
/**
* Create a {@code TtsSpan} for the supplied {@code String}.
*
* @param phoneNumberString A {@code String} the entirety of which represents a phone number.
* @return A {@code TtsSpan} for {@param phoneNumberString}.
*/
public static TtsSpan createTtsSpan(String phoneNumberString) {
if (phoneNumberString == null) {
return null;
}
// Parse the phone number
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
PhoneNumber phoneNumber = null;
try {
// Don't supply a defaultRegion so this fails for non-international numbers because
// we don't want to TalkBalk to read a country code (e.g. +1) if it is not already
// present
phoneNumber = phoneNumberUtil.parse(phoneNumberString, /* defaultRegion */
null);
} catch (NumberParseException ignored) {
}
// Build a telephone tts span
final TtsSpan.TelephoneBuilder builder = new TtsSpan.TelephoneBuilder();
if (phoneNumber == null) {
// Strip separators otherwise TalkBack will be silent
// (this behavior was observed with TalkBalk 4.0.2 from their alpha channel)
builder.setNumberParts(splitAtNonNumerics(phoneNumberString));
} else {
if (phoneNumber.hasCountryCode()) {
builder.setCountryCode(Integer.toString(phoneNumber.getCountryCode()));
}
builder.setNumberParts(Long.toString(phoneNumber.getNationalNumber()));
}
return builder.build();
}
use of com.android.i18n.phonenumbers.PhoneNumberUtil in project android_frameworks_base by ResurrectionRemix.
the class PhoneNumberUtils method createTtsSpan.
/**
* Create a {@code TtsSpan} for the supplied {@code String}.
*
* @param phoneNumberString A {@code String} the entirety of which represents a phone number.
* @return A {@code TtsSpan} for {@param phoneNumberString}.
*/
public static TtsSpan createTtsSpan(String phoneNumberString) {
if (phoneNumberString == null) {
return null;
}
// Parse the phone number
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
PhoneNumber phoneNumber = null;
try {
// Don't supply a defaultRegion so this fails for non-international numbers because
// we don't want to TalkBalk to read a country code (e.g. +1) if it is not already
// present
phoneNumber = phoneNumberUtil.parse(phoneNumberString, /* defaultRegion */
null);
} catch (NumberParseException ignored) {
}
// Build a telephone tts span
final TtsSpan.TelephoneBuilder builder = new TtsSpan.TelephoneBuilder();
if (phoneNumber == null) {
// Strip separators otherwise TalkBack will be silent
// (this behavior was observed with TalkBalk 4.0.2 from their alpha channel)
builder.setNumberParts(splitAtNonNumerics(phoneNumberString));
} else {
if (phoneNumber.hasCountryCode()) {
builder.setCountryCode(Integer.toString(phoneNumber.getCountryCode()));
}
builder.setNumberParts(Long.toString(phoneNumber.getNationalNumber()));
}
return builder.build();
}
Aggregations