use of android.text.style.UnderlineSpan in project android_frameworks_base by ParanoidAndroid.
the class HtmlToSpannedConverter method handleEndTag.
private void handleEndTag(String tag) {
if (tag.equalsIgnoreCase("br")) {
handleBr(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("p")) {
handleP(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("div")) {
handleP(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("strong")) {
end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
} else if (tag.equalsIgnoreCase("b")) {
end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
} else if (tag.equalsIgnoreCase("em")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("cite")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("dfn")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("i")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("big")) {
end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
} else if (tag.equalsIgnoreCase("small")) {
end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
} else if (tag.equalsIgnoreCase("font")) {
endFont(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("blockquote")) {
handleP(mSpannableStringBuilder);
end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
} else if (tag.equalsIgnoreCase("tt")) {
end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan("monospace"));
} else if (tag.equalsIgnoreCase("a")) {
endA(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("u")) {
end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
} else if (tag.equalsIgnoreCase("sup")) {
end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
} else if (tag.equalsIgnoreCase("sub")) {
end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
} else if (tag.length() == 2 && Character.toLowerCase(tag.charAt(0)) == 'h' && tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
handleP(mSpannableStringBuilder);
endHeader(mSpannableStringBuilder);
} else if (mTagHandler != null) {
mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
}
}
use of android.text.style.UnderlineSpan in project android_frameworks_base by ParanoidAndroid.
the class ViewPropertyAlphaActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_properties);
getWindow().getDecorView().postDelayed(new Runnable() {
@Override
public void run() {
startAnim(R.id.button);
startAnim(R.id.textview);
startAnim(R.id.spantext);
startAnim(R.id.edittext);
startAnim(R.id.selectedtext);
startAnim(R.id.textviewbackground);
startAnim(R.id.layout);
startAnim(R.id.imageview);
startAnim(myViewAlphaDefault);
startAnim(myViewAlphaHandled);
EditText selectedText = (EditText) findViewById(R.id.selectedtext);
selectedText.setSelection(3, 8);
}
}, 2000);
Button invalidator = (Button) findViewById(R.id.invalidateButton);
invalidator.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
findViewById(R.id.textview).invalidate();
findViewById(R.id.spantext).invalidate();
}
});
TextView textView = (TextView) findViewById(R.id.spantext);
if (textView != null) {
SpannableStringBuilder text = new SpannableStringBuilder("Now this is a short text message with spans");
text.setSpan(new BackgroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.BLUE), 4, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new SuggestionSpan(this, new String[] { "longer" }, 3), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new UnderlineSpan(), 17, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ImageSpan(this, R.drawable.icon), 21, 22, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(text);
}
LinearLayout container = (LinearLayout) findViewById(R.id.container);
myViewAlphaDefault = new MyView(this, false);
myViewAlphaDefault.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
container.addView(myViewAlphaDefault);
myViewAlphaHandled = new MyView(this, true);
myViewAlphaHandled.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
container.addView(myViewAlphaHandled);
}
use of android.text.style.UnderlineSpan in project LuaViewSDK by alibaba.
the class UDSpannableString method initSpannableStringBuilder.
private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
if (text != null && text.isstring()) {
spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
}
if (spannableStringBuilder.length() > 0) {
if (config != null && config.istable()) {
final int end = spannableStringBuilder.length();
final int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
final Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
final String fontName = config.get("fontName").optjstring(null);
final LuaValue weightValue = config.get("fontWeight");
final int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));
final LuaValue styleValue = config.get("fontStyle");
final int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));
final Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
final boolean strikethrough = config.get("strikethrough").optboolean(false);
final boolean underline = config.get("underline").optboolean(false);
if (fontSize != -1) {
//字体大小
spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontColor != null) {
//字体颜色
spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontName != null && getLuaResourceFinder() != null) {
//字体
spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {
//文字Weight
spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {
//文字样式
spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (backgroundColor != null) {
//背景色
spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (strikethrough) {
//删除线
spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (underline) {
//下划线
spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
use of android.text.style.UnderlineSpan in project robolectric by robolectric.
the class ShadowSpannableStringTest method testSetSpan.
@Test
public void testSetSpan() {
URLSpan s1 = new URLSpan("http://www.foobar.com");
UnderlineSpan s2 = new UnderlineSpan();
spanStr.setSpan(s1, 12, 33, 0);
spanStr.setSpan(s2, 1, 10, 0);
assertBothSpans(s1, s2);
}
use of android.text.style.UnderlineSpan in project robolectric by robolectric.
the class ShadowSpannableStringTest method testGetSpans.
@Test
public void testGetSpans() {
URLSpan s1 = new URLSpan("http://www.foobar.com");
UnderlineSpan s2 = new UnderlineSpan();
spanStr.setSpan(s1, 1, 10, 0);
spanStr.setSpan(s2, 20, 30, 0);
Object[] spans = spanStr.getSpans(0, TEST_STRING.length(), Object.class);
assertThat(spans).isNotNull();
assertThat(spans.length).isEqualTo(2);
assertBothSpans(s1, s2);
spans = spanStr.getSpans(0, TEST_STRING.length(), URLSpan.class);
assertThat(spans).isNotNull();
assertThat(spans.length).isEqualTo(1);
assertThat((URLSpan) spans[0]).isSameAs(s1);
spans = spanStr.getSpans(11, 35, Object.class);
assertThat(spans).isNotNull();
assertThat(spans.length).isEqualTo(1);
assertThat((UnderlineSpan) spans[0]).isSameAs(s2);
spans = spanStr.getSpans(21, 35, Object.class);
assertThat(spans).isNotNull();
assertThat(spans.length).isEqualTo(1);
assertThat((UnderlineSpan) spans[0]).isSameAs(s2);
spans = spanStr.getSpans(5, 15, Object.class);
assertThat(spans).isNotNull();
assertThat(spans.length).isEqualTo(1);
assertThat((URLSpan) spans[0]).isSameAs(s1);
}
Aggregations