@Test public void testExpandTemplate() throws Exception { assertThat(TextUtils.expandTemplate("a^1b^2c^3d", "A", "B", "C", "D").toString()).isEqualTo("aAbBcCd"); }
/** * @return a formatted message with links to {@code panelId}. */ private CharSequence formatBeforeInfoBarMessage(String template, String sourceLanguage, String targetLanguage, final int panelId) { SpannableString formattedSourceLanguage = new SpannableString(sourceLanguage); formattedSourceLanguage.setSpan(new ClickableSpan() { @Override public void onClick(View view) { swapPanel(panelId); } }, 0, sourceLanguage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); SpannableString formattedTargetLanguage = new SpannableString(targetLanguage); formattedTargetLanguage.setSpan(new ClickableSpan() { @Override public void onClick(View view) { swapPanel(panelId); } }, 0, targetLanguage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return TextUtils.expandTemplate(template, formattedSourceLanguage, formattedTargetLanguage); }
public void setPickTarget(DocumentInfo pickTarget, CharSequence displayName) { mPickTarget = pickTarget; if (mContainer != null) { if (mPickTarget != null) { mContainer.setVisibility(View.VISIBLE); final Locale locale = getResources().getConfiguration().locale; final String raw = getString(R.string.menu_select).toUpperCase(locale); mPick.setText(TextUtils.expandTemplate(raw, displayName)); } else { mContainer.setVisibility(View.GONE); } } } }
/** * Returns the infobar message for the case when PasswordManager has a guess which credentials * pair should be updated. There are two cases possible: there is only one credential pair that * should be updated and there several guesses available. In the first case user is presented * with the username of the credentials that should be updated in the second case user is able * to choose which of the available credentials to update. * It also remembered the choice made. */ private CharSequence createUsernameMessageText(int selectedUsername) { CharSequence message; mSelectedUsername = selectedUsername; final String template = getContext().getString(R.string.update_password_for_account); final String usernameToDisplay = mUsernames[mSelectedUsername]; if (mShowMultipleAccounts) { final String downPointingArrow = " \u25BE"; SpannableString usernameSelector = new SpannableString(usernameToDisplay + downPointingArrow); usernameSelector.setSpan(new ClickableSpan() { @Override public void onClick(View view) { onUsernameLinkClicked(view); } }, 0, usernameSelector.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); message = TextUtils.expandTemplate(template, mBrandingSpan, usernameSelector); } else { message = TextUtils.expandTemplate(template, mBrandingSpan, usernameToDisplay); } return message; }
/** * Sets the accessibility descriptions for the action buttons in the action button ViewStub. * * @param views The views associated with the current call log entry. */ public void setActionContentDescriptions(CallLogListItemViewHolder views) { if (views.nameOrNumber == null) { Log.e(TAG, "setActionContentDescriptions; name or number is null."); } // Calling expandTemplate with a null parameter will cause a NullPointerException. // Although we don't expect a null name or number, it is best to protect against it. CharSequence nameOrNumber = views.nameOrNumber == null ? "" : views.nameOrNumber; views.videoCallButtonView.setContentDescription( TextUtils.expandTemplate( mResources.getString(R.string.description_video_call_action), nameOrNumber)); views.createNewContactButtonView.setContentDescription( TextUtils.expandTemplate( mResources.getString(R.string.description_create_new_contact_action), nameOrNumber)); views.addToExistingContactButtonView.setContentDescription( TextUtils.expandTemplate( mResources.getString(R.string.description_add_to_existing_contact_action), nameOrNumber)); views.detailsButtonView.setContentDescription( TextUtils.expandTemplate( mResources.getString(R.string.description_details_action), nameOrNumber)); }
/** * Create infobar message in the form of CharSequence. * * @param context The context. * @param template The template CharSequence. * @param fileName The file name. * @param dirName The directory name. * @param dirNameIntent The intent to be launched when user touches the directory name link. * @return CharSequence formatted message for InfoBar. */ private static CharSequence formatInfoBarMessage(final Context context, String template, String fileName, String dirName, final Intent dirNameIntent) { SpannableString formattedFileName = new SpannableString(fileName); formattedFileName.setSpan(new StyleSpan(Typeface.BOLD), 0, fileName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); SpannableString formattedDirName = new SpannableString(dirName); if (canResolveIntent(context, dirNameIntent)) { formattedDirName.setSpan(new ClickableSpan() { @Override public void onClick(View view) { context.startActivity(dirNameIntent); } }, 0, dirName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } return TextUtils.expandTemplate(template, formattedFileName, formattedDirName); }
/** * 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 public void createContent(InfoBarLayout layout) { super.createContent(layout); CharSequence message; if (mIsSmartLockEnabled) { mBrandingSpan.setSpan(new ClickableSpan() { @Override public void onClick(View view) { onLinkClicked(); } }, 0, mBrandingSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (mShowMultipleAccounts || mUsernames.length != 0) { message = createUsernameMessageText(0); } else { String template = getContext().getString(R.string.update_password); message = TextUtils.expandTemplate(template, mBrandingSpan); } mMessageView = layout.getMessageTextView(); mMessageView.setText(message, TextView.BufferType.SPANNABLE); }
primaryActionButtonView.setContentDescription(TextUtils.expandTemplate( mContext.getString(R.string.description_voicemail_action), nameOrNumber)); primaryActionButtonView.setContentDescription(TextUtils.expandTemplate( mContext.getString(R.string.description_call_action), nameOrNumber));
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())); }
callButtonView.setTag(IntentProvider.getReturnCallIntentProvider(number)); ((TextView) callButtonView.findViewById(R.id.call_action_text)) .setText(TextUtils.expandTemplate( mContext.getString(R.string.call_log_action_call), nameOrNumber));
TextUtils.expandTemplate( mResources.getString(stringID), nameOrNumber,