Example usage for android.text SpannableStringBuilder SpannableStringBuilder

List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder

Introduction

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

Prototype

public SpannableStringBuilder(CharSequence text) 

Source Link

Document

Create a new SpannableStringBuilder containing a copy of the specified text, including its spans if any.

Usage

From source file:org.amahi.anywhere.adapter.ServerFilesAdapter.java

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
    final ServerFileViewHolder fileHolder = (ServerFileViewHolder) holder;

    final ServerFile file = filteredFiles.get(position);

    if (Mimes.match(file.getMime()) == Mimes.Type.DIRECTORY) {
        fileHolder.moreInfo.setVisibility(View.GONE);
        fileHolder.moreOptions.setVisibility(View.GONE);

    } else {//from   w w w .j a  v  a2 s .  com
        fileHolder.moreInfo.setVisibility(View.VISIBLE);
        fileHolder.moreOptions.setVisibility(View.VISIBLE);

        if (!isOfflineMode()) {
            fileHolder.fileSize.setText(Formatter.formatFileSize(context, getFileSize(file)));
        } else {
            if (isFileDownloading(fileHolder, file, position)) {
                fileHolder.moreInfo.setVisibility(View.GONE);
                fileHolder.progressBar.setVisibility(View.VISIBLE);
            } else {
                fileHolder.moreInfo.setVisibility(View.VISIBLE);
                fileHolder.progressBar.setVisibility(View.GONE);
                File localFile = new File(context.getFilesDir(),
                        Downloader.OFFLINE_PATH + "/" + file.getName());
                fileHolder.fileSize.setText(Formatter.formatFileSize(context, localFile.length()));
            }
        }

        Date d = getLastModified(file);
        SimpleDateFormat dt = new SimpleDateFormat("EEE LLL dd yyyy", Locale.getDefault());
        fileHolder.fileLastModified.setText(dt.format(d));
    }

    SpannableStringBuilder sb = new SpannableStringBuilder(file.getName());
    if (queryString != null && !TextUtils.isEmpty(queryString)) {
        int searchMatchPosition = file.getName().toLowerCase().indexOf(queryString.toLowerCase());
        if (searchMatchPosition != -1)
            sb.setSpan(fcs, searchMatchPosition, searchMatchPosition + queryString.length(),
                    Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    }
    fileHolder.fileTextView.setText(sb);

    if (Mimes.match(file.getMime()) == Mimes.Type.IMAGE) {
        setUpImageIcon(file, fileHolder.fileIconView);
    } else if (Mimes.match(file.getMime()) == Mimes.Type.AUDIO) {
        setUpAudioArt(file, fileHolder.fileIconView);
    } else {
        fileHolder.fileIconView.setImageResource(Mimes.getFileIcon(file));
    }

    fileHolder.itemView.setOnClickListener(view -> {
        mListener.onItemClick(fileHolder.itemView, fileHolder.getAdapterPosition());
    });

    fileHolder.moreOptions.setOnClickListener(view -> {
        selectedPosition = fileHolder.getAdapterPosition();
        mListener.onMoreOptionClick(fileHolder.itemView, fileHolder.getAdapterPosition());
    });
}

From source file:org.cnc.mombot.utils.ContactsEditText.java

private CharSequence getContactSpanned(ContactResource contact) {
    String friendName = "@{name: " + contact.name + ", email: " + contact.email + ", mobile:  " + contact.phone
            + " }";
    return addPeopleToGroupChat(new SpannableStringBuilder(friendName));
}

From source file:com.kncwallet.wallet.ui.TransactionsListFragment.java

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final SpannableStringBuilder emptyText = new SpannableStringBuilder(
            getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent
                    : R.string.wallet_transactions_fragment_empty_text_received));
    emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
            SpannableStringBuilder.SPAN_POINT_MARK);
    if (direction != Direction.SENT)
        emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));

    Drawable divider = getResources().getDrawable(R.drawable.transaction_list_divider);
    this.getListView().setDivider(divider);
    this.getListView().setDividerHeight(1);

    setEmptyText(emptyText);// w w w .  j  av a 2  s.  co  m
}

From source file:map.IconGeneratorDemoActivity.java

private CharSequence makeCharSequence() {
    String prefix = "Mixing ";
    String suffix = "different fonts";
    String sequence = prefix + suffix;
    SpannableStringBuilder ssb = new SpannableStringBuilder(sequence);
    ssb.setSpan(new StyleSpan(ITALIC), 0, prefix.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new StyleSpan(BOLD), prefix.length(), sequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;/*w w  w. j  a v  a 2s.co  m*/
}

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

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final SpannableStringBuilder emptyText = new SpannableStringBuilder(
            getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent
                    : R.string.wallet_transactions_fragment_empty_text_received));
    emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
            SpannableStringBuilder.SPAN_POINT_MARK);
    if (direction != Direction.SENT)
        emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));

    setEmptyText(emptyText);/* ww w  .  j av  a 2s .c om*/
}

From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java

@SuppressLint("InflateParams")
@Override//from  w w  w .jav  a  2s.  c om
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object item = l.getItemAtPosition(position);
    final int changeId;
    if (item instanceof AutohideRule) {
        changeId = position - 1;
    } else {
        changeId = -1; //-1 - ?  
    }

    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
            ? new ContextThemeWrapper(this, R.style.Neutron_Medium)
            : this;
    View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null);
    final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex);
    final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner);
    final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname);
    final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum);
    final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment);
    final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject);
    final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name);

    chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans));
    if (changeId != -1) {
        AutohideRule rule = (AutohideRule) item;
        regexEditText.setText(rule.regex);
        int chanPosition = chans.indexOf(rule.chanName);
        chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0);
        boardEditText.setText(rule.boardName);
        threadEditText.setText(rule.threadNumber);
        inCommentCheckBox.setChecked(rule.inComment);
        inSubjectCheckBox.setChecked(rule.inSubject);
        inNameCheckBox.setChecked(rule.inName);
    } else {
        chanSpinner.setSelection(0);
    }

    DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String regex = regexEditText.getText().toString();
            if (regex.length() == 0) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            try {
                Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);
            } catch (Exception e) {
                CharSequence message = null;
                if (e instanceof PatternSyntaxException) {
                    String eMessage = e.getMessage();
                    if (!TextUtils.isEmpty(eMessage)) {
                        SpannableStringBuilder a = new SpannableStringBuilder(
                                getString(R.string.autohide_error_incorrect_regex));
                        a.append('\n');
                        int startlen = a.length();
                        a.append(eMessage);
                        a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(),
                                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        message = a;
                    }
                }
                if (message == null)
                    message = getString(R.string.error_unknown);
                Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show();
                return;
            }

            AutohideRule rule = new AutohideRule();
            int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition();
            rule.regex = regex;
            rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? 
            rule.boardName = boardEditText.getText().toString();
            rule.threadNumber = threadEditText.getText().toString();
            rule.inComment = inCommentCheckBox.isChecked();
            rule.inSubject = inSubjectCheckBox.isChecked();
            rule.inName = inNameCheckBox.isChecked();

            if (!rule.inComment && !rule.inSubject && !rule.inName) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            if (changeId == -1) {
                rulesJson.put(rule.toJson());
            } else {
                rulesJson.put(changeId, rule.toJson());
            }
            rulesChanged();
        }
    };
    AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView)
            .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title)
            .setPositiveButton(R.string.autohide_save_button, save)
            .setNegativeButton(android.R.string.cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:com.mybitcoin.wallet.ui.TransactionsListFragment.java

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final SpannableStringBuilder emptyText = new SpannableStringBuilder(
            getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent
                    : R.string.wallet_transactions_fragment_empty_text_received));
    emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
            SpannableStringBuilder.SPAN_POINT_MARK);
    /*if (direction != Direction.SENT)
       emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));*/

    setEmptyText(emptyText);/*from  w  ww.j  a  va 2s  . c  o m*/
}

From source file:com.owncloud.android.ui.adapter.NotificationListAdapter.java

private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {
    String text = notification.getSubjectRich();
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);

    int openingBrace = text.indexOf('{');
    int closingBrace;
    String replaceablePart;//w  ww. j  av a2s  .  co m
    while (openingBrace != -1) {
        closingBrace = text.indexOf('}', openingBrace) + 1;
        replaceablePart = text.substring(openingBrace + 1, closingBrace - 1);

        RichObject richObject = notification.subjectRichParameters.get(replaceablePart);
        if (richObject != null) {
            String name = richObject.getName();
            ssb.replace(openingBrace, closingBrace, name);
            text = ssb.toString();
            closingBrace = openingBrace + name.length();

            ssb.setSpan(styleSpanBold, openingBrace, closingBrace, 0);
            ssb.setSpan(foregroundColorSpanBlack, openingBrace, closingBrace,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        openingBrace = text.indexOf('{', closingBrace);
    }

    return ssb;
}

From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java

public void setTitle(CharSequence title) {
    this.title = title;
    this.displayText = new SpannableStringBuilder(title);
}

From source file:net.zionsoft.obadiah.ui.adapters.TranslationListAdapter.java

public void setTranslations(@Nullable List<TranslationInfo> downloaded,
        @Nullable List<TranslationInfo> available) {
    mSectionHeaders.clear();/*from w ww  . ja  va  2s  . c o m*/
    mTranslations.clear();
    mCount = 0;
    if (downloaded != null && downloaded.size() > 0) {
        final List<TranslationInfoHolder> translations = new ArrayList<TranslationInfoHolder>(
                downloaded.size());
        for (TranslationInfo translationInfo : downloaded) {
            final SpannableStringBuilder text = new SpannableStringBuilder(translationInfo.name);
            text.setSpan(mMediumSizeSpan, 0, translationInfo.name.length(), 0);

            translations.add(new TranslationInfoHolder(translationInfo, text, true));
        }
        mSectionHeaders.add(mDownloadedTranslationsTitle);
        mTranslations.add(translations);
        mCount = downloaded.size() + 1;
    }

    if (available != null) {
        for (TranslationInfo translationInfo : available) {
            final String language = new Locale(translationInfo.language.split("_")[0]).getDisplayLanguage();
            int index = 0;
            List<TranslationInfoHolder> translations = null;
            for (String sectionHeader : mSectionHeaders) {
                if (sectionHeader.equals(language)) {
                    translations = mTranslations.get(index);
                    break;
                }
                ++index;
            }
            if (translations == null) {
                translations = new ArrayList<TranslationInfoHolder>();
                mSectionHeaders.add(language);
                mTranslations.add(translations);
                ++mCount;
            }

            final SpannableStringBuilder text = new SpannableStringBuilder(
                    mResources.getString(R.string.text_available_translation_info, translationInfo.name,
                            translationInfo.size / 1024));
            text.setSpan(mMediumSizeSpan, 0, translationInfo.name.length(), 0);
            text.setSpan(mSmallSizeSpan, translationInfo.name.length(), text.length(), 0);

            translations.add(new TranslationInfoHolder(translationInfo, text, false));
            ++mCount;
        }
    }
}