/** * Retrieves a string from a string template that takes 1 phone number as argument, * span the number with a telephone {@link TtsSpan}, and return the spanned string. * * @param resources to retrieve the string from * @param stringId ID of the string * @param number to pass in the template * @return CharSequence with the phone number wrapped in a TtsSpan */ public static CharSequence getTtsSpannedPhoneNumber(Resources resources, int stringId, String number){ String msg = resources.getString(stringId, number); return ContactDisplayUtils.getTelephoneTtsSpannable(msg, number); }
/** * Gets a display label for a given phone type. * * @param type The type of number. * @param customLabel A custom label to use if the phone is determined to be of custom type * determined by {@link #isCustomPhoneType(Integer))} * @param interactionType whether this is a call or sms. Either {@link #INTERACTION_CALL} or * {@link #INTERACTION_SMS}. * @param context The application context. * @return An appropriate string label */ public static CharSequence getLabelForCallOrSms(Integer type, CharSequence customLabel, int interactionType, Context context) { Preconditions.checkNotNull(context); if (isCustomPhoneType(type)) { return (customLabel == null) ? "" : customLabel; } else { int resId; if (interactionType == INTERACTION_SMS) { resId = getSmsLabelResourceId(type); } else { resId = getPhoneLabelResourceId(type); if (interactionType != INTERACTION_CALL) { Log.e(TAG, "Un-recognized interaction type: " + interactionType + ". Defaulting to ContactDisplayUtils.INTERACTION_CALL."); } } return context.getResources().getText(resId); } }
private CharSequence getBlockedMessage() { return ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.snackbar_number_blocked, mDisplayNumber); }
/** * Construct the "on {accountLabel} via {viaNumber}" accessibility description for the account * list item, depending on the existence of the accountLabel and viaNumber. * @param viaNumber The number that this call is being placed via. * @param accountLabel The {@link PhoneAccount} label that this call is being placed with. * @return The description of the account that this call has been placed on. */ public static CharSequence createAccountLabelDescription(Resources resources, @Nullable String viaNumber, @Nullable CharSequence accountLabel) { if((!TextUtils.isEmpty(viaNumber)) && !TextUtils.isEmpty(accountLabel)) { String msg = resources.getString(R.string.description_via_number_phone_account, accountLabel, viaNumber); CharSequence accountNumberLabel = ContactDisplayUtils.getTelephoneTtsSpannable(msg, viaNumber); return (accountNumberLabel == null) ? msg : accountNumberLabel; } else if (!TextUtils.isEmpty(viaNumber)) { CharSequence viaNumberLabel = ContactDisplayUtils.getTtsSpannedPhoneNumber(resources, R.string.description_via_number, viaNumber); return (viaNumberLabel == null) ? viaNumber : viaNumberLabel; } else if (!TextUtils.isEmpty(accountLabel)) { return TextUtils.expandTemplate( resources.getString(R.string.description_phone_account), accountLabel); } return ""; } }
@Override protected boolean isCustom(Integer type) { return ContactDisplayUtils.isCustomPhoneType(type); }
/** * 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); } } }
@Override protected int getTypeLabelResource(Integer type) { return ContactDisplayUtils.getPhoneLabelResourceId(type); } }
@Override protected int getTypeLabelResource(Integer type) { return ContactDisplayUtils.getSmsLabelResourceId(type); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { final View view = super.getView(position, convertView, parent); final PhoneItem item = getItem(position); final TextView typeView = (TextView) view.findViewById(android.R.id.text1); CharSequence value = ContactDisplayUtils.getLabelForCallOrSms((int) item.type, item.label, mInteractionType, getContext()); typeView.setText(value); return view; } }
@Override protected boolean isCustom(Integer type) { return ContactDisplayUtils.isCustomPhoneType(type); }
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()); } }
private CharSequence getUnblockedMessage() { return ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.snackbar_number_unblocked, mDisplayNumber); }
CharSequence msg = ContactDisplayUtils.getTtsSpannedPhoneNumber( context.getResources(), R.string.menu_callNumber, name); Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (!FilteredNumbersUtil.canBlockNumber(getActivity(), mNumber, mCountryIso)) { dismiss(); Toast.makeText(getContext(), ContactDisplayUtils.getTtsSpannedPhoneNumber( getResources(), R.string.invalidNumber, mDisplayNumber), Toast.LENGTH_SHORT).show(); } }
@Override public void onCheckComplete(Integer id) { if (id == null) { BlockNumberDialogFragment.show( id, number, countryIso, PhoneNumberUtils.formatNumber(number, countryIso), R.id.blocked_numbers_activity_container, getFragmentManager(), BlockedListSearchFragment.this); } else { Toast.makeText(getContext(), ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.alreadyBlocked, number), Toast.LENGTH_SHORT).show(); } } };
private void blockContactNumber(final String number, final Integer blockId) { if (blockId != null) { Toast.makeText(getContext(), ContactDisplayUtils.getTtsSpannedPhoneNumber( getResources(), R.string.alreadyBlocked, number), Toast.LENGTH_SHORT).show(); return; } BlockNumberDialogFragment.show( blockId, number, GeoUtil.getCurrentCountryIso(getContext()), number, R.id.blocked_numbers_activity_container, getFragmentManager(), this); } }
switch (shortcutType) { case SHORTCUT_DIRECT_CALL: text = ContactDisplayUtils.getTtsSpannedPhoneNumber(resources, R.string.search_shortcut_call_number, mBidiFormatter.unicodeWrap(number, TextDirectionHeuristics.LTR));
if (!success) { Toast.makeText(getContext(), ContactDisplayUtils.getTtsSpannedPhoneNumber( getResources(), R.string.invalidNumber, number), Toast.LENGTH_SHORT).show();
title = null; okText = getString(R.string.unblock_number_ok); message = ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.unblock_number_confirmation_title, mDisplayNumber).toString(); } else { title = ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.block_number_confirmation_title, mDisplayNumber);
CharSequence msg = ContactDisplayUtils.getTtsSpannedPhoneNumber( resources, R.string.notification_new_voicemail_ticker,