Example usage for android.text SpannableStringBuilder append

List of usage examples for android.text SpannableStringBuilder append

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder append.

Prototype

public SpannableStringBuilder append(char text) 

Source Link

Usage

From source file:com.robomorphine.fragment.AboutDialogFragment.java

private CharSequence linkify(String text, String link) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    URLSpan span = new URLSpan(link);

    builder.append(text);
    builder.setSpan(span, 0, builder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return builder;
}

From source file:de.azapps.mirakel.new_ui.adapter.AutoCompleteAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    final AutocompleteViewHolder viewHolder = (AutocompleteViewHolder) view.getTag();
    final SearchObject searchObject = new SearchObject(cursor);
    // This is ok for tasks and a fallback variant for tags
    viewHolder.taskName.setText(searchObject.getName());
    switch (searchObject.getAutocompleteType()) {
    case TASK:/*  w w w . ja  v  a 2s. co m*/
        if (searchObject.isDone()) {
            viewHolder.taskName
                    .setPaintFlags(viewHolder.taskName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            viewHolder.taskName
                    .setPaintFlags(viewHolder.taskName.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }
        break;
    case TAG:
        final Tag tag = new Tag(searchObject.getObjId(), searchObject.getName(),
                searchObject.getBackgroundColor(), false);
        TagSpan tagSpan = new TagSpan(tag, context);
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
        stringBuilder.append(new SpannableString(tag.getName()));
        stringBuilder.setSpan(tagSpan, 0, tag.getName().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.taskName.setText(stringBuilder, TextView.BufferType.SPANNABLE);
        break;
    }
}

From source file:com.yelinaung.karrency.app.ui.HomeActivity.java

private void firstTimeTask() {
    if (SharePrefUtils.getInstance(getApplicationContext()).isFirstTime()) {
        lastSync.setVisibility(View.GONE);
    } else {/*from ww  w  .j  av  a 2 s . c  om*/
        String time = SharePrefUtils.getInstance(getApplicationContext()).getTime();
        SpannableStringBuilder lastSyncTime = new SpannableStringBuilder();
        lastSyncTime.append(Html.fromHtml(getString(R.string.sync_time, time)));
        lastSync.setText(lastSyncTime);
    }
}

From source file:com.bdevlin.apps.ui.fragments.HelpListFragment.java

private void updateText() {
    // mHelpText = (TextView) getView().findViewById(R.id.help_text);
    mHelpText = (WebView) getView().findViewById(R.id.webView1);
    mHelpText.getSettings().setJavaScriptEnabled(false);

    CharSequence text = Utils.bold(Utils.italic(getResources().getString(R.string.about_eula)),
            Utils.color(Color.RED, getResources().getString(R.string.about_licenses)));
    CharSequence yourHtml = "<table>table</table>";

    CharSequence content = getContent();
    ;/*w  w w  . j a v  a  2  s  .c om*/
    SpannedString sstr = SpannedString.valueOf(content);
    SpannedString message = SpannedString.valueOf(mMessage);
    SpannedString message2 = SpannedString.valueOf(text);
    SpannedString message3 = SpannedString.valueOf(yourHtml);

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    aboutBody.append(Html.fromHtml(Html.toHtml(message)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message2)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message3)));
    aboutBody.append(Html.fromHtml(Html.toHtml(sstr)));
    aboutBody.setSpan(new StyleSpan(Typeface.ITALIC), 0, aboutBody.length(), 0);
    // mHelpText.setText(aboutBody);
    // mHelpText.loadData(Html.toHtml(aboutBody), "text/html", null);

    mHelpText.loadUrl("file:///android_asset/" + mTitle + ".html", null);

    //mHelpText.loadUrl("http://www.choosemyplate.gov/tools-supertracker");

}

From source file:com.none.tom.simplerssreader.view.ReadMoreTextView.java

@SuppressWarnings("SameParameterValue")
public void setText(final CharSequence text, final int maxEms) {
    if (!TextUtils.isEmpty(text) && text.length() > maxEms) {
        final SpannableStringBuilder ssb = new SpannableStringBuilder(text.subSequence(0, maxEms));

        ssb.append('\u2026');

        final int textLength = ssb.length();

        ssb.append('\n');
        ssb.append(getContext().getString(R.string.read_more));

        final int readMoreLength = ssb.length() - textLength;

        ssb.setSpan(new ReadMoreClickableSpan(), textLength, textLength + readMoreLength,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        super.setText(ssb);

        setMaxEms(maxEms + readMoreLength);
        setMovementMethod(LinkMovementMethod.getInstance());

        mText = text;//from  w  ww. ja  v a  2  s  .c o m
    } else {
        super.setText(text);
    }
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void handleLi(SpannableStringBuilder text, Object tag, int level) {
    if (tag == null)
        return;//w  ww.ja  v a  2 s. c o m

    int len = text.length();
    if (len >= 1 && text.charAt(len - 1) != '\n')
        text.append("\n");
    for (int i = 1; i < level; ++i)
        text.append("\t");
    if (tag instanceof OlTag)
        text.append(Integer.toString(((OlTag) tag).curIndex++) + ". ");
    else if (tag instanceof UlTag)
        text.append("\u2022 ");
}

From source file:com.woodblockwithoutco.beretainedexample.MainActivity.java

protected CharSequence[] getItems() {
    //filling list with entries like "fieldName 0xfieldHash"
    String[] fieldNames = new String[] { "mIntArray", "mObject", "mMap", };

    String[] fieldHashcodes = new String[] { "0x" + Integer.toHexString(System.identityHashCode(mIntArray)),
            "0x" + Integer.toHexString(System.identityHashCode(mObject)),
            "0x" + Integer.toHexString(System.identityHashCode(mMap)) };

    if (fieldHashcodes.length != fieldNames.length) {
        throw new IllegalStateException("Did you forget to add something?");
    }//from   w  w w .ja v a  2 s  .c o  m

    int length = fieldHashcodes.length;
    CharSequence[] items = new CharSequence[length];
    for (int i = 0; i < length; i++) {
        SpannableStringBuilder description = new SpannableStringBuilder();
        description.append(fieldNames[i]);
        description.setSpan(new TypefaceSpan("bold"), 0, description.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        description.append(" ").append(fieldHashcodes[i]);
        items[i] = description;
    }

    return items;
}

From source file:de.schildbach.litecoinwallet.ui.WalletDisclaimerFragment.java

private void updateView() {
    if (!isResumed())
        return;/*from  ww w. j  a v a 2 s . c  om*/

    final boolean showBackup = prefs.getBoolean(Constants.PREFS_KEY_REMIND_BACKUP, true);
    final boolean showSafety = prefs.getBoolean(Constants.PREFS_KEY_DISCLAIMER, true);

    final int progressResId;
    if (download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK)
        progressResId = 0;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_storage;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_network;
    else
        throw new IllegalStateException("download=" + download);

    final SpannableStringBuilder text = new SpannableStringBuilder();
    if (progressResId != 0)
        text.append(Html.fromHtml("<b>" + getString(progressResId) + "</b>"));
    if (progressResId != 0 && (showBackup || showSafety))
        text.append('\n');
    if (showBackup)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_backup)));
    if (showBackup && showSafety)
        text.append('\n');
    if (showSafety)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_safety)));
    messageView.setText(text);

    final View view = getView();
    final ViewParent parent = view.getParent();
    final View fragment = parent instanceof FrameLayout ? (FrameLayout) parent : view;
    fragment.setVisibility(text.length() > 0 ? View.VISIBLE : View.GONE);
}

From source file:cc.mintcoin.wallet.ui.WalletDisclaimerFragment.java

private void updateView() {
    if (!isResumed())
        return;/*from   w  ww  .ja  v  a  2s .c o  m*/

    final boolean showBackup = config.remindBackup();
    final boolean showDisclaimer = config.getDisclaimerEnabled();

    final int progressResId;
    if (download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK)
        progressResId = 0;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_storage;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_network;
    else
        throw new IllegalStateException("download=" + download);

    final SpannableStringBuilder text = new SpannableStringBuilder();
    if (progressResId != 0)
        text.append(Html.fromHtml("<b>" + getString(progressResId) + "</b>"));
    if (progressResId != 0 && (showBackup || showDisclaimer))
        text.append('\n');
    if (showBackup)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_backup)));
    if (showBackup && showDisclaimer)
        text.append('\n');
    if (showDisclaimer)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_safety)));
    messageView.setText(text);

    final View view = getView();
    final ViewParent parent = view.getParent();
    final View fragment = parent instanceof FrameLayout ? (FrameLayout) parent : view;
    fragment.setVisibility(text.length() > 0 ? View.VISIBLE : View.GONE);
}

From source file:com.oasisfeng.nevo.decorators.whatsapp.WhatsAppDecorator.java

@Override
public void apply(final StatusBarNotificationEvo evolving) throws RemoteException {
    final INotification n = evolving.notification();
    final IBundle extras = n.extras();

    final CharSequence who, group, message;
    @SuppressWarnings("unchecked")
    final List<CharSequence> lines = extras.getCharSequenceArray(EXTRA_TEXT_LINES);
    final boolean has_lines = lines != null && !lines.isEmpty();
    final CharSequence title = extras.getCharSequence(EXTRA_TITLE);
    final CharSequence last = has_lines ? lines.get(lines.size() - 1) : extras.getCharSequence(EXTRA_TEXT);

    final CharSequence[] last_parts = extract(title, last);
    who = last_parts[0];/*from  www. j  a  va2s  .c om*/
    group = last_parts[1];
    message = last_parts[2];

    if (group != null)
        evolving.setTag(".Group");
    else if (who != null)
        evolving.setTag(".Direct");
    else
        return; // Nothing to do for other messages.

    final CharSequence new_title = group != null ? group : who;
    evolving.setId(new_title.toString().hashCode());
    if (n.getColor() == 0)
        n.setColor(DEFAULT_COLOR); // Fix the missing color in some notifications

    if (!has_lines)
        return;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
        n.removeFlags(Notification.FLAG_GROUP_SUMMARY);
    else
        extras.remove("android.support.isGroupSummary");

    extras.putCharSequence(EXTRA_TITLE, new_title);
    extras.putCharSequence(EXTRA_TITLE_BIG, new_title);
    extras.putCharSequence(EXTRA_TEXT, group != null ? who + ": " + message : message);

    final List<CharSequence> new_lines = new ArrayList<>(lines.size());
    for (final CharSequence line : lines) {
        final CharSequence[] parts = extract(title, line);
        if (group != null) { // Group chat, keep messages within the same group.
            if (!group.equals(parts[1]))
                continue;
            final SpannableStringBuilder new_line = new SpannableStringBuilder();
            new_line.append(parts[0]).setSpan(new StyleSpan(BOLD), 0, new_line.length(),
                    SPAN_EXCLUSIVE_EXCLUSIVE);
            new_lines.add(new_line.append(": ").append(parts[2]));
        } else if (who.equals(parts[0]) && parts[1] == null)
            new_lines.add(parts[2]); // Direct chat, keep messages from the same person (excluding group chat)
    }
    extras.putCharSequenceArray(EXTRA_TEXT_LINES, new_lines);
    extras.remove(EXTRA_SUMMARY_TEXT);
    extras.putString(EXTRA_REBUILD_STYLE, STYLE_INBOX);
    if (new_lines.size() > 1)
        n.setNumber(new_lines.size());
}