Example usage for android.text TextUtils replace

List of usage examples for android.text TextUtils replace

Introduction

In this page you can find the example usage for android.text TextUtils replace.

Prototype

public static CharSequence replace(CharSequence template, String[] sources, CharSequence[] destinations) 

Source Link

Document

Return a new CharSequence in which each of the source strings is replaced by the corresponding element of the destinations.

Usage

From source file:zack.yovel.clear.controller.foreground.DayFragment.java

private void initInfo() {

    // get the view
    TextView tvInfo = (TextView) getView().findViewById(R.id.tvInfoCurrently);

    if (tvInfo != null) {

        // get the template from the view
        int templateResourceId = R.string.template_info_day;
        CharSequence templateTemperatures = getResources().getString(templateResourceId);

        // format the text
        String[] placeHolders = getInfoPlaceHolders();
        int directionResourceId = ConvertUtil.bearingTo16PointsResourceIds(dayDataPoint.getWindBearing());

        String[] values = getInfoValues(directionResourceId);
        CharSequence info = TextUtils.replace(templateTemperatures, placeHolders, values);

        // set the text to the view
        tvInfo.setText(info);/*from   w ww .ja  va 2  s.c  o m*/
    }
}

From source file:zack.yovel.clear.controller.foreground.DayFragment.java

private void initTemps() {
    // get the view
    TextView tvTemps = (TextView) getView().findViewById(R.id.tvTempsCurrently);
    tvTemps.setTextSize(28);/*from   ww  w  .j a  v  a  2 s  . com*/

    if (tvTemps != null) {

        // get the template
        int templateResourceId = R.string.template_temperatures_daily;
        CharSequence templateTemperatures = Html.fromHtml(getResources().getString(templateResourceId));

        // format the text
        String[] placeHolders = getTempsPlaceHolders();
        String[] values = getTempsValues(dayDataPoint);
        CharSequence info = TextUtils.replace(templateTemperatures, placeHolders, values);

        // set the text to the view
        tvTemps.setText(info);
    }
}

From source file:de.fmaul.android.cmis.utils.FeedUtils.java

public static String getSearchQueryFeed(String urlTemplate, String query) {
    final CharSequence feedUrl = TextUtils.replace(urlTemplate,
            new String[] { "{q}", "{searchAllVersions}", "{maxItems}", "{skipCount}",
                    "{includeAllowableActions}", "{includeRelationships}" },
            new String[] { query, "false", "50", "0", "false", "false" });

    return feedUrl.toString();
}

From source file:de.fmaul.android.cmis.utils.FeedUtils.java

public static String getSearchQueryFeedCmisQuery(String urlTemplate, String cmisQuery) {
    String encodedCmisQuery = "";
    try {//from   w w w  . j  a v a  2 s.c  o m
        encodedCmisQuery = URLEncoder.encode(cmisQuery, "iso-8859-1");
    } catch (UnsupportedEncodingException e) {
        encodedCmisQuery = URLEncoder.encode(cmisQuery);
    }

    final CharSequence feedUrl = TextUtils.replace(urlTemplate,
            new String[] { "{q}", "{searchAllVersions}", "{maxItems}", "{skipCount}",
                    "{includeAllowableActions}", "{includeRelationships}" },
            new String[] { encodedCmisQuery, "false", "50", "0", "false", "false" });

    return feedUrl.toString();
}

From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java

@Override
public void onItemAdded(String key, String value) {
    key = TextUtils.replace(key, new String[] { DELIMETER, SEPARATOR }, new String[] { "", "" }).toString();
    value = TextUtils.replace(value, new String[] { DELIMETER, SEPARATOR }, new String[] { "", "" }).toString();
    Parcelable[] parcelables = mCurrentRestrictions.getParcelableArray(RESTRICTION_KEY_ITEMS);
    Map<String, String> items = new HashMap<>();
    if (parcelables != null) {
        for (Parcelable parcelable : parcelables) {
            Bundle bundle = (Bundle) parcelable;
            items.put(bundle.getString(RESTRICTION_KEY_ITEM_KEY), bundle.getString(RESTRICTION_KEY_ITEM_VALUE));
        }/*  w  w  w  .  j  a  v a2s  . c  o  m*/
    }
    items.put(key, value);
    insertItemRow(LayoutInflater.from(getActivity()), key, value);
    saveItems(getActivity(), items);
}

From source file:com.determinato.feeddroid.parser.RssParser.java

/**
 * Examines string and replaces XML-escaped HTML entities with
 * their appropriate equivalents.//from  w w  w .  j  av a  2  s  .  c om
 * @param str String to examine
 * @return String with proper HTML elements
 */
private String reEncodeHtml(String str) {
    StringBuilder builder = new StringBuilder();
    if (str == null)
        return "";
    String[] sources = new String[] { "<![CDATA[", "]]>", "&gt;", "&lt;", "&amp;", "&#8217;", "&#8220;",
            "&#8221;" };
    String[] dests = new String[] { "", "", ">", "<", "&", "'", "\"", "\"" };
    builder.append(TextUtils.replace(str, sources, dests));
    return builder.toString();
}

From source file:com.android.mms.ui.MessageListItem.java

private CharSequence formatMessage(MessageItem msgItem, String body, String subject, Pattern highlight,
        String contentType) {//from   w  w w  .  j  av  a 2s.c  o m
    SpannableStringBuilder buf = new SpannableStringBuilder();

    boolean hasSubject = !TextUtils.isEmpty(subject);
    SmileyParser parser = SmileyParser.getInstance();
    if (hasSubject) {
        CharSequence smilizedSubject = parser.addSmileySpans(subject);
        // Can't use the normal getString() with extra arguments for string replacement
        // because it doesn't preserve the SpannableText returned by addSmileySpans.
        // We have to manually replace the %s with our text.
        buf.append(TextUtils.replace(mContext.getResources().getString(R.string.inline_subject),
                new String[] { "%s" }, new CharSequence[] { smilizedSubject }));
    }

    if (!TextUtils.isEmpty(body)) {
        // Converts html to spannable if ContentType is "text/html".
        if (contentType != null && ContentType.TEXT_HTML.equals(contentType)) {
            buf.append("\n");
            buf.append(Html.fromHtml(body));
        } else {
            if (hasSubject) {
                buf.append(" - ");
            }
            buf.append(parser.addSmileySpans(body));
        }
    }

    if (highlight != null) {
        Matcher m = highlight.matcher(buf.toString());
        while (m.find()) {
            buf.setSpan(new StyleSpan(Typeface.BOLD), m.start(), m.end(), 0);
        }
    }
    return buf;
}

From source file:org.telepatch.ui.ChatActivity.java

private void updateSubtitle() {
    if (currentChat != null) {
        actionBarLayer.setTitle(currentChat.title);
    } else if (currentUser != null) {
        if (currentUser.id / 1000 != 777 && currentUser.id / 1000 != 333
                && ContactsController.getInstance().contactsDict.get(currentUser.id) == null
                && (ContactsController.getInstance().contactsDict.size() != 0
                        || !ContactsController.getInstance().isLoadingContacts())) {
            if (currentUser.phone != null && currentUser.phone.length() != 0) {
                actionBarLayer.setTitle(PhoneFormat.getInstance().format("+" + currentUser.phone));
            } else {
                actionBarLayer//from   w  ww . jav a 2  s  . co  m
                        .setTitle(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
            }
        } else {
            actionBarLayer
                    .setTitle(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
        }
    }

    CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
    if (printString != null) {
        printString = TextUtils.replace(printString, new String[] { "..." }, new String[] { "" });
    }
    if (printString == null || printString.length() == 0) {
        lastPrintString = null;
        setTypingAnimation(false);
        if (currentChat != null) {
            if (currentChat instanceof TLRPC.TL_chatForbidden) {
                actionBarLayer.setSubtitle(LocaleController.getString("YouWereKicked", R.string.YouWereKicked));
            } else if (currentChat.left) {
                actionBarLayer.setSubtitle(LocaleController.getString("YouLeft", R.string.YouLeft));
            } else {
                int count = currentChat.participants_count;
                if (info != null) {
                    count = info.participants.size();
                }
                if (onlineCount > 1 && count != 0) {
                    actionBarLayer.setSubtitle(
                            String.format("%s, %s", LocaleController.formatPluralString("Members", count),
                                    LocaleController.formatPluralString("Online", onlineCount)));
                } else {
                    actionBarLayer.setSubtitle(LocaleController.formatPluralString("Members", count));
                }
            }
        } else if (currentUser != null) {
            TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
            if (user != null) {
                currentUser = user;
            }
            actionBarLayer.setSubtitle(LocaleController.formatUserStatus(currentUser));
        }
    } else {
        lastPrintString = printString;
        actionBarLayer.setSubtitle(printString);
        setTypingAnimation(true);
    }
}