use of android.text.style.UnderlineSpan in project android_frameworks_base by ParanoidAndroid.
the class HtmlTest method testMarkup.
@SmallTest
public void testMarkup() throws Exception {
SpannableString s;
s = new SpannableString("Hello bold world");
s.setSpan(new StyleSpan(Typeface.BOLD), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <b>bold</b> world</p>\n");
s = new SpannableString("Hello italic world");
s.setSpan(new StyleSpan(Typeface.ITALIC), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <i>italic</i> world</p>\n");
s = new SpannableString("Hello monospace world");
s.setSpan(new TypefaceSpan("monospace"), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <tt>monospace</tt> world</p>\n");
s = new SpannableString("Hello superscript world");
s.setSpan(new SuperscriptSpan(), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <sup>superscript</sup> world</p>\n");
s = new SpannableString("Hello subscript world");
s.setSpan(new SubscriptSpan(), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <sub>subscript</sub> world</p>\n");
s = new SpannableString("Hello underline world");
s.setSpan(new UnderlineSpan(), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <u>underline</u> world</p>\n");
s = new SpannableString("Hello struck world");
s.setSpan(new StrikethroughSpan(), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <strike>struck</strike> world</p>\n");
s = new SpannableString("Hello linky world");
s.setSpan(new URLSpan("http://www.google.com"), 6, s.length() - 6, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
assertEquals(Html.toHtml(s), "<p>Hello <a href=\"http://www.google.com\">linky</a> world</p>\n");
}
use of android.text.style.UnderlineSpan in project Anki-Android by Ramblurr.
the class Reviewer method updateScreenCounts.
private void updateScreenCounts() {
if (mCurrentCard == null) {
return;
}
try {
String[] title = mSched.getCol().getDecks().get(mCurrentCard.getDid()).getString("name").split("::");
AnkiDroidApp.getCompat().setTitle(this, title[title.length - 1], mInvertedColors);
} catch (JSONException e) {
throw new RuntimeException(e);
}
int[] counts = mSched.counts(mCurrentCard);
int eta = mSched.eta(counts, false);
AnkiDroidApp.getCompat().setSubtitle(this, getResources().getQuantityString(R.plurals.reviewer_window_title, eta, eta), mInvertedColors);
SpannableString newCount = new SpannableString(String.valueOf(counts[0]));
SpannableString lrnCount = new SpannableString(String.valueOf(counts[1]));
SpannableString revCount = new SpannableString(String.valueOf(counts[2]));
if (mPrefHideDueCount) {
revCount = new SpannableString("???");
}
switch(mCurrentCard.getQueue()) {
case Card.TYPE_NEW:
newCount.setSpan(new UnderlineSpan(), 0, newCount.length(), 0);
break;
case Card.TYPE_LRN:
lrnCount.setSpan(new UnderlineSpan(), 0, lrnCount.length(), 0);
break;
case Card.TYPE_REV:
revCount.setSpan(new UnderlineSpan(), 0, revCount.length(), 0);
break;
}
mTextBarRed.setText(newCount);
mTextBarBlack.setText(lrnCount);
mTextBarBlue.setText(revCount);
}
use of android.text.style.UnderlineSpan in project robolectric by robolectric.
the class ShadowSpannableStringTest method testRemoveSpan.
@Test
public void testRemoveSpan() {
URLSpan s1 = new URLSpan("http://www.foobar.com");
UnderlineSpan s2 = new UnderlineSpan();
spanStr.setSpan(s1, 12, 33, 0);
spanStr.setSpan(s2, 1, 10, 0);
spanStr.removeSpan(s1);
Object[] spans = spanStr.getSpans(0, TEST_STRING.length(), Object.class);
assertThat(spans).isNotNull();
assertThat(spans.length).isEqualTo(1);
assertThat((UnderlineSpan) spans[0]).isSameAs(s2);
}
use of android.text.style.UnderlineSpan in project platform_frameworks_base by android.
the class HtmlToSpannedConverter method withinParagraph.
private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
int next;
for (int i = start; i < end; i = next) {
next = text.nextSpanTransition(i, end, CharacterStyle.class);
CharacterStyle[] style = text.getSpans(i, next, CharacterStyle.class);
for (int j = 0; j < style.length; j++) {
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("<b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("<i>");
}
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if ("monospace".equals(s)) {
out.append("<tt>");
}
}
if (style[j] instanceof SuperscriptSpan) {
out.append("<sup>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("<sub>");
}
if (style[j] instanceof UnderlineSpan) {
out.append("<u>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("<span style=\"text-decoration:line-through;\">");
}
if (style[j] instanceof URLSpan) {
out.append("<a href=\"");
out.append(((URLSpan) style[j]).getURL());
out.append("\">");
}
if (style[j] instanceof ImageSpan) {
out.append("<img src=\"");
out.append(((ImageSpan) style[j]).getSource());
out.append("\">");
// Don't output the dummy character underlying the image.
i = next;
}
if (style[j] instanceof AbsoluteSizeSpan) {
AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
float sizeDip = s.getSize();
if (!s.getDip()) {
Application application = ActivityThread.currentApplication();
sizeDip /= application.getResources().getDisplayMetrics().density;
}
// px in CSS is the equivalance of dip in Android
out.append(String.format("<span style=\"font-size:%.0fpx\";>", sizeDip));
}
if (style[j] instanceof RelativeSizeSpan) {
float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
}
if (style[j] instanceof ForegroundColorSpan) {
int color = ((ForegroundColorSpan) style[j]).getForegroundColor();
out.append(String.format("<span style=\"color:#%06X;\">", 0xFFFFFF & color));
}
if (style[j] instanceof BackgroundColorSpan) {
int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
out.append(String.format("<span style=\"background-color:#%06X;\">", 0xFFFFFF & color));
}
}
withinStyle(out, text, i, next);
for (int j = style.length - 1; j >= 0; j--) {
if (style[j] instanceof BackgroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof ForegroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof RelativeSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof AbsoluteSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof URLSpan) {
out.append("</a>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("</span>");
}
if (style[j] instanceof UnderlineSpan) {
out.append("</u>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("</sub>");
}
if (style[j] instanceof SuperscriptSpan) {
out.append("</sup>");
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if (s.equals("monospace")) {
out.append("</tt>");
}
}
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("</b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("</i>");
}
}
}
}
}
use of android.text.style.UnderlineSpan in project qksms by moezbhatti.
the class MessageListAdapter method bindVcard.
private void bindVcard(MessageListViewHolder holder, MessageItem messageItem) {
if (!ContentType.TEXT_VCARD.equals(messageItem.mTextContentType)) {
return;
}
VCard vCard = Ezvcard.parse(messageItem.mBody).first();
SpannableString name = new SpannableString(vCard.getFormattedName().getValue());
name.setSpan(new UnderlineSpan(), 0, name.length(), 0);
holder.mBodyTextView.setText(name);
}
Aggregations