use of android.text.style.StyleSpan in project Conversations by siacs.
the class FormFieldWrapper method createSpannableLabelString.
protected SpannableString createSpannableLabelString(String label, boolean required) {
SpannableString spannableString = new SpannableString(label + (required ? " *" : ""));
if (required) {
int start = label.length();
int end = label.length() + 2;
spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0);
spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.accent)), start, end, 0);
}
return spannableString;
}
use of android.text.style.StyleSpan in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class TextUtilsTest method testEllipsize.
@LargeTest
public void testEllipsize() {
CharSequence s1 = "The quick brown fox jumps over þhe lazy dog.";
CharSequence s2 = new Wrapper(s1);
Spannable s3 = new SpannableString(s1);
s3.setSpan(new StyleSpan(0), 5, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextPaint p = new TextPaint();
p.setFlags(p.getFlags() & ~p.DEV_KERN_TEXT_FLAG);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 3; j++) {
TextUtils.TruncateAt kind = null;
switch(j) {
case 0:
kind = TextUtils.TruncateAt.START;
break;
case 1:
kind = TextUtils.TruncateAt.END;
break;
case 2:
kind = TextUtils.TruncateAt.MIDDLE;
break;
}
String out1 = TextUtils.ellipsize(s1, p, i, kind).toString();
String out2 = TextUtils.ellipsize(s2, p, i, kind).toString();
String out3 = TextUtils.ellipsize(s3, p, i, kind).toString();
String keep1 = TextUtils.ellipsize(s1, p, i, kind, true, null).toString();
String keep2 = TextUtils.ellipsize(s2, p, i, kind, true, null).toString();
String keep3 = TextUtils.ellipsize(s3, p, i, kind, true, null).toString();
String trim1 = keep1.replace("", "");
// Are all normal output strings identical?
assertEquals("wid " + i + " pass " + j, out1, out2);
assertEquals("wid " + i + " pass " + j, out2, out3);
// Are preserved output strings identical?
assertEquals("wid " + i + " pass " + j, keep1, keep2);
assertEquals("wid " + i + " pass " + j, keep2, keep3);
// Does trimming padding from preserved yield normal?
assertEquals("wid " + i + " pass " + j, out1, trim1);
// Did preserved output strings preserve length?
assertEquals("wid " + i + " pass " + j, keep1.length(), s1.length());
// Does the output string actually fit in the space?
assertTrue("wid " + i + " pass " + j, p.measureText(out1) <= i);
// Is the padded output the same width as trimmed output?
assertTrue("wid " + i + " pass " + j, p.measureText(keep1) == p.measureText(out1));
}
}
}
use of android.text.style.StyleSpan in project iosched by google.
the class SearchSnippet method setText.
@Override
public void setText(CharSequence text, BufferType type) {
if (!TextUtils.isEmpty(text)) {
Matcher matcher = PATTERN_SEARCH_TERM.matcher(text);
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
List<String> hits = new ArrayList<>();
while (matcher.find()) {
hits.add(matcher.group(1));
}
for (String hit : hits) {
int start = ssb.toString().indexOf(hit);
int end = start + hit.length();
ssb.setSpan(new StyleSpan(Typeface.BOLD), start, end, 0);
// delete the markup tokens
ssb.delete(end - 1, end);
ssb.delete(start, start + 1);
}
text = ssb;
}
super.setText(text, type);
}
use of android.text.style.StyleSpan in project android-delicious by lexs.
the class TagsBinder method buildTagList.
public static Spannable buildTagList(List<String> tags) {
SpannableStringBuilder builder = new SpannableStringBuilder();
if (tags == null || tags.isEmpty()) {
return builder;
}
for (String tag : tags) {
int pos = builder.length();
builder.append(tag);
int color = generateColor(tag);
builder.setSpan(new ForegroundColorSpan(color), pos, builder.length(), 0);
builder.append(SEPARATOR);
// Thin space, so we get 1.5 spaces between
builder.append(' ');
}
// Remove last thin and hard space
builder.delete(builder.length() - 2, builder.length());
// Make the whole thing bold
builder.setSpan(new StyleSpan(Typeface.BOLD), 0, builder.length(), 0);
return builder;
}
Aggregations