/** * Compat method for addTtsSpan, see {@link PhoneNumberUtils#addTtsSpan} */ public static void addTtsSpan(Spannable s, int start, int endExclusive) { if (CompatUtils.isMarshmallowCompatible()) { PhoneNumberUtils.addTtsSpan(s, start, endExclusive); } else { addTtsSpanInternal(s, start, endExclusive); } }
/** * Returns a Spannable for the given message with a telephone {@link TtsSpan} set for * the given phone number text wherever it is found within the message. */ public static Spannable getTelephoneTtsSpannable(String message, String phoneNumber) { if (message == null) { return null; } final Spannable spannable = new SpannableString(message); int start = phoneNumber == null ? -1 : message.indexOf(phoneNumber); while (start >= 0) { final int end = start + phoneNumber.length(); final TtsSpan ttsSpan = PhoneNumberUtilsCompat.createTtsSpan(phoneNumber); spannable.setSpan(ttsSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // this is consistenly done in a misleading way.. start = message.indexOf(phoneNumber, end); } return spannable; }
public static TtsSpan createTtsSpan(String phoneNumber) { if (CompatUtils.isMarshmallowCompatible()) { return PhoneNumberUtils.createTtsSpan(phoneNumber); } else if (CompatUtils.isLollipopCompatible()) { return createTtsSpanLollipop(phoneNumber); } else { return null; } }
/** * Adds or updates a text view for the search snippet. */ public void setSnippet(String text) { if (TextUtils.isEmpty(text)) { if (mSnippetView != null) { mSnippetView.setVisibility(View.GONE); } } else { mTextHighlighter.setPrefixText(getSnippetView(), text, mHighlightedPrefix); mSnippetView.setVisibility(VISIBLE); if (ContactDisplayUtils.isPossiblePhoneNumber(text)) { // Give the text-to-speech engine a hint that it's a phone number mSnippetView.setContentDescription( PhoneNumberUtilsCompat.createTtsSpannable(text)); } else { mSnippetView.setContentDescription(null); } } }
/** * Implementation copied from {@link PhoneNumberUtils#normalizeNumber} */ private static String normalizeNumberInternal(String phoneNumber) { if (TextUtils.isEmpty(phoneNumber)) { return ""; } StringBuilder sb = new StringBuilder(); int len = phoneNumber.length(); for (int i = 0; i < len; i++) { char c = phoneNumber.charAt(i); // Character.digit() supports ASCII and Unicode digits (fullwidth, Arabic-Indic, etc.) int digit = Character.digit(c, 10); if (digit != -1) { sb.append(digit); } else if (sb.length() == 0 && c == '+') { sb.append(c); } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { return normalizeNumber(PhoneNumberUtils.convertKeypadLettersToDigits(phoneNumber)); } } return sb.toString(); }
public static CharSequence createTtsSpannable(CharSequence phoneNumber) { if (CompatUtils.isMarshmallowCompatible()) { return PhoneNumberUtils.createTtsSpannable(phoneNumber); } else { return createTtsSpannableInternal(phoneNumber); } }
public static String normalizeNumber(String phoneNumber) { if (CompatUtils.isLollipopCompatible()) { return PhoneNumberUtils.normalizeNumber(phoneNumber); } else { return normalizeNumberInternal(phoneNumber); } }
public void computeFormattedPhoneNumber(String defaultCountryIso) { final String phoneNumber = getNumber(); if (phoneNumber != null) { final String formattedPhoneNumber = PhoneNumberUtilsCompat.formatNumber(phoneNumber, getNormalizedNumber(), defaultCountryIso); getContentValues().put(KEY_FORMATTED_PHONE_NUMBER, formattedPhoneNumber); } }
builder.setNumberParts(splitAtNonNumerics(phoneNumberString)); } else { if (phoneNumber.hasCountryCode()) {
private CharSequence getSubDescription(SubscriptionInfo record) { CharSequence name = record.getDisplayName(); if (TextUtils.isEmpty(record.getNumber())) { // Don't include the phone number in the description, since we don't know the number. return getString(R.string.import_from_sim_summary_no_number, name); } return TextUtils.expandTemplate( getString(R.string.import_from_sim_summary), name, PhoneNumberUtilsCompat.createTtsSpannable(record.getNumber())); }
holder.numberTextView.setVisibility(View.VISIBLE); holder.numberTextView.setText( PhoneNumberUtilsCompat.createTtsSpannable( account.getAddress().getSchemeSpecificPart()));
/** * Copied from {@link PhoneNumberUtils#createTtsSpannable} */ private static CharSequence createTtsSpannableInternal(CharSequence phoneNumber) { if (phoneNumber == null) { return null; } Spannable spannable = Spannable.Factory.getInstance().newSpannable(phoneNumber); addTtsSpanInternal(spannable, 0, spannable.length()); return spannable; }
/** * Copied from {@link PhoneNumberUtils#addTtsSpan} */ private static void addTtsSpanInternal(Spannable s, int start, int endExclusive) { s.setSpan(createTtsSpan(s.subSequence(start, endExclusive).toString()), start, endExclusive, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
public void setDisplayName(CharSequence name) { if (!TextUtils.isEmpty(name)) { // Chooses the available highlighting method for highlighting. if (mHighlightedPrefix != null) { name = mTextHighlighter.applyPrefixHighlight(name, mHighlightedPrefix); } else if (mNameHighlightSequence.size() != 0) { final SpannableString spannableName = new SpannableString(name); for (HighlightSequence highlightSequence : mNameHighlightSequence) { mTextHighlighter.applyMaskingHighlight(spannableName, highlightSequence.start, highlightSequence.end); } name = spannableName; } } else { name = mUnknownNameText; } setMarqueeText(getNameTextView(), name); if (ContactDisplayUtils.isPossiblePhoneNumber(name)) { // Give the text-to-speech engine a hint that it's a phone number mNameTextView.setTextDirection(View.TEXT_DIRECTION_LTR); mNameTextView.setContentDescription( PhoneNumberUtilsCompat.createTtsSpannable(name.toString())); } else { // Remove span tags of highlighting for talkback to avoid reading highlighting and rest // of the name into two separate parts. mNameTextView.setContentDescription(name.toString()); } }
? null : PhoneNumberUtilsCompat.createTtsSpannable(info.formattedNumber);
menu.setHeaderTitle(mContext.getResources().getText(R.string.voicemail)); } else { menu.setHeaderTitle(PhoneNumberUtilsCompat.createTtsSpannable( BidiFormatter.getInstance().unicodeWrap(number, TextDirectionHeuristics.LTR)));