Search in sources :

Example 1 with TtsSpan

use of android.text.style.TtsSpan in project android_frameworks_base by DirtyUnicorns.

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();
}
Also used : TtsSpan(android.text.style.TtsSpan) PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Example 2 with TtsSpan

use of android.text.style.TtsSpan 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();
}
Also used : TtsSpan(android.text.style.TtsSpan) PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Example 3 with TtsSpan

use of android.text.style.TtsSpan 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();
}
Also used : TtsSpan(android.text.style.TtsSpan) PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Example 4 with TtsSpan

use of android.text.style.TtsSpan 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();
}
Also used : TtsSpan(android.text.style.TtsSpan) PhoneNumberUtil(com.android.i18n.phonenumbers.PhoneNumberUtil) PhoneNumber(com.android.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.android.i18n.phonenumbers.NumberParseException)

Aggregations

TtsSpan (android.text.style.TtsSpan)4 NumberParseException (com.android.i18n.phonenumbers.NumberParseException)4 PhoneNumberUtil (com.android.i18n.phonenumbers.PhoneNumberUtil)4 PhoneNumber (com.android.i18n.phonenumbers.Phonenumber.PhoneNumber)4