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;
}
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);
}
}
}
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;
}
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);
}
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("");
}
}
Aggregations