Search in sources :

Example 51 with StyleSpan

use of android.text.style.StyleSpan in project android_frameworks_base by DirtyUnicorns.

the class NotificationTests method BOLD.

static SpannableStringBuilder BOLD(CharSequence str) {
    final SpannableStringBuilder ssb = new SpannableStringBuilder(str);
    ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, ssb.length(), 0);
    return ssb;
}
Also used : StyleSpan(android.text.style.StyleSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 52 with StyleSpan

use of android.text.style.StyleSpan in project weex-example by KalicyZhou.

the class SearchBookContentsListItem method set.

public void set(SearchBookContentsResult result) {
    pageNumberView.setText(result.getPageNumber());
    String snippet = result.getSnippet();
    if (snippet.isEmpty()) {
        snippetView.setText("");
    } else {
        if (result.getValidSnippet()) {
            String lowerQuery = SearchBookContentsResult.getQuery().toLowerCase(Locale.getDefault());
            String lowerSnippet = snippet.toLowerCase(Locale.getDefault());
            Spannable styledSnippet = new SpannableString(snippet);
            StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
            int queryLength = lowerQuery.length();
            int offset = 0;
            while (true) {
                int pos = lowerSnippet.indexOf(lowerQuery, offset);
                if (pos < 0) {
                    break;
                }
                styledSnippet.setSpan(boldSpan, pos, pos + queryLength, 0);
                offset = pos + queryLength;
            }
            snippetView.setText(styledSnippet);
        } else {
            // This may be an error message, so don't try to bold the query terms within it
            snippetView.setText(snippet);
        }
    }
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) SpannableString(android.text.SpannableString) Spannable(android.text.Spannable)

Example 53 with StyleSpan

use of android.text.style.StyleSpan in project materialistic by hidroh.

the class HackerNewsItem method createAuthorSpannable.

@NonNull
private SpannableString createAuthorSpannable(boolean authorLink) {
    SpannableString bySpannable = new SpannableString(AUTHOR_SEPARATOR + by);
    if (!authorLink) {
        return bySpannable;
    }
    bySpannable.setSpan(new StyleSpan(Typeface.BOLD), AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    ClickableSpan clickableSpan = new ClickableSpan() {

        @Override
        public void onClick(View view) {
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(AppUtils.createUserUri(getBy())));
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
        }
    };
    bySpannable.setSpan(clickableSpan, AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return bySpannable;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextPaint(android.text.TextPaint) NonNull(android.support.annotation.NonNull)

Example 54 with StyleSpan

use of android.text.style.StyleSpan in project android_frameworks_base by AOSPA.

the class ProgressDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    TypedArray a = mContext.obtainStyledAttributes(null, com.android.internal.R.styleable.AlertDialog, com.android.internal.R.attr.alertDialogStyle, 0);
    if (mProgressStyle == STYLE_HORIZONTAL) {
        /* Use a separate handler to update the text views as they
             * must be updated on the same thread that created them.
             */
        mViewUpdateHandler = new Handler() {

            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                /* Update the number and percent */
                int progress = mProgress.getProgress();
                int max = mProgress.getMax();
                if (mProgressNumberFormat != null) {
                    String format = mProgressNumberFormat;
                    mProgressNumber.setText(String.format(format, progress, max));
                } else {
                    mProgressNumber.setText("");
                }
                if (mProgressPercentFormat != null) {
                    double percent = (double) progress / (double) max;
                    SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
                    tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    mProgressPercent.setText(tmp);
                } else {
                    mProgressPercent.setText("");
                }
            }
        };
        View view = inflater.inflate(a.getResourceId(com.android.internal.R.styleable.AlertDialog_horizontalProgressLayout, R.layout.alert_dialog_progress), null);
        mProgress = (ProgressBar) view.findViewById(R.id.progress);
        mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
        mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
        setView(view);
    } else {
        View view = inflater.inflate(a.getResourceId(com.android.internal.R.styleable.AlertDialog_progressLayout, R.layout.progress_dialog), null);
        mProgress = (ProgressBar) view.findViewById(R.id.progress);
        mMessageView = (TextView) view.findViewById(R.id.message);
        setView(view);
    }
    a.recycle();
    if (mMax > 0) {
        setMax(mMax);
    }
    if (mProgressVal > 0) {
        setProgress(mProgressVal);
    }
    if (mSecondaryProgressVal > 0) {
        setSecondaryProgress(mSecondaryProgressVal);
    }
    if (mIncrementBy > 0) {
        incrementProgressBy(mIncrementBy);
    }
    if (mIncrementSecondaryBy > 0) {
        incrementSecondaryProgressBy(mIncrementSecondaryBy);
    }
    if (mProgressDrawable != null) {
        setProgressDrawable(mProgressDrawable);
    }
    if (mIndeterminateDrawable != null) {
        setIndeterminateDrawable(mIndeterminateDrawable);
    }
    if (mMessage != null) {
        setMessage(mMessage);
    }
    setIndeterminate(mIndeterminate);
    onProgressChanged();
    super.onCreate(savedInstanceState);
}
Also used : SpannableString(android.text.SpannableString) Message(android.os.Message) LayoutInflater(android.view.LayoutInflater) TypedArray(android.content.res.TypedArray) StyleSpan(android.text.style.StyleSpan) Handler(android.os.Handler) SpannableString(android.text.SpannableString) TextView(android.widget.TextView) View(android.view.View)

Example 55 with StyleSpan

use of android.text.style.StyleSpan in project Android-DialogFragments by wada811.

the class ProgressDialogBase method viewUpdate.

protected void viewUpdate() {
    /* Update the number and percent */
    int progress = progressBar.getProgress();
    int max = progressBar.getMax();
    if (progressNumberFormat != null) {
        String format = progressNumberFormat;
        progressNumber.setText(String.format(format, progress, max));
    } else {
        progressNumber.setText("");
    }
    if (progressPercentFormat != null) {
        double percent = (double) progress / (double) max;
        SpannableString spannableString = new SpannableString(progressPercentFormat.format(percent));
        StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
        spannableString.setSpan(styleSpan, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        progressPercent.setText(spannableString);
    } else {
        progressPercent.setText("");
    }
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) SpannableString(android.text.SpannableString)

Aggregations

StyleSpan (android.text.style.StyleSpan)145 SpannableString (android.text.SpannableString)56 SpannableStringBuilder (android.text.SpannableStringBuilder)36 RelativeSizeSpan (android.text.style.RelativeSizeSpan)32 ForegroundColorSpan (android.text.style.ForegroundColorSpan)25 View (android.view.View)18 TextView (android.widget.TextView)17 UnderlineSpan (android.text.style.UnderlineSpan)16 Spannable (android.text.Spannable)14 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)12 TypedArray (android.content.res.TypedArray)10 TextPaint (android.text.TextPaint)10 SubscriptSpan (android.text.style.SubscriptSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)10 Handler (android.os.Handler)9 Message (android.os.Message)9 URLSpan (android.text.style.URLSpan)8 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)8 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)8