use of android.text.style.BulletSpan in project Knife by mthli.
the class KnifeParser method withinBullet.
private static void withinBullet(StringBuilder out, Spanned text, int start, int end) {
out.append("<ul>");
int next;
for (int i = start; i < end; i = next) {
next = text.nextSpanTransition(i, end, BulletSpan.class);
BulletSpan[] spans = text.getSpans(i, next, BulletSpan.class);
for (BulletSpan span : spans) {
out.append("<li>");
}
withinContent(out, text, i, next);
for (BulletSpan span : spans) {
out.append("</li>");
}
}
out.append("</ul>");
}
use of android.text.style.BulletSpan in project Knife by mthli.
the class KnifeText method switchToKnifeStyle.
protected void switchToKnifeStyle(Editable editable, int start, int end) {
BulletSpan[] bulletSpans = editable.getSpans(start, end, BulletSpan.class);
for (BulletSpan span : bulletSpans) {
int spanStart = editable.getSpanStart(span);
int spanEnd = editable.getSpanEnd(span);
spanEnd = 0 < spanEnd && spanEnd < editable.length() && editable.charAt(spanEnd) == '\n' ? spanEnd - 1 : spanEnd;
editable.removeSpan(span);
editable.setSpan(new KnifeBulletSpan(bulletColor, bulletRadius, bulletGapWidth), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
QuoteSpan[] quoteSpans = editable.getSpans(start, end, QuoteSpan.class);
for (QuoteSpan span : quoteSpans) {
int spanStart = editable.getSpanStart(span);
int spanEnd = editable.getSpanEnd(span);
spanEnd = 0 < spanEnd && spanEnd < editable.length() && editable.charAt(spanEnd) == '\n' ? spanEnd - 1 : spanEnd;
editable.removeSpan(span);
editable.setSpan(new KnifeQuoteSpan(quoteColor, quoteStripeWidth, quoteGapWidth), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
URLSpan[] urlSpans = editable.getSpans(start, end, URLSpan.class);
for (URLSpan span : urlSpans) {
int spanStart = editable.getSpanStart(span);
int spanEnd = editable.getSpanEnd(span);
editable.removeSpan(span);
editable.setSpan(new KnifeURLSpan(span.getURL(), linkColor, linkUnderline), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
use of android.text.style.BulletSpan in project platform_frameworks_base by android.
the class HtmlToSpannedConverter method withinBlockquoteIndividual.
private static void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start, int end) {
boolean isInList = false;
int next;
for (int i = start; i <= end; i = next) {
next = TextUtils.indexOf(text, '\n', i, end);
if (next < 0) {
next = end;
}
if (next == i) {
if (isInList) {
// Current paragraph is no longer a list item; close the previously opened list
isInList = false;
out.append("</ul>\n");
}
out.append("<br>\n");
} else {
boolean isListItem = false;
ParagraphStyle[] paragraphStyles = text.getSpans(i, next, ParagraphStyle.class);
for (ParagraphStyle paragraphStyle : paragraphStyles) {
final int spanFlags = text.getSpanFlags(paragraphStyle);
if ((spanFlags & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH && paragraphStyle instanceof BulletSpan) {
isListItem = true;
break;
}
}
if (isListItem && !isInList) {
// Current paragraph is the first item in a list
isInList = true;
out.append("<ul").append(getTextStyles(text, i, next, true, false)).append(">\n");
}
if (isInList && !isListItem) {
// Current paragraph is no longer a list item; close the previously opened list
isInList = false;
out.append("</ul>\n");
}
String tagType = isListItem ? "li" : "p";
out.append("<").append(tagType).append(getTextDirection(text, i, next)).append(getTextStyles(text, i, next, !isListItem, true)).append(">");
withinParagraph(out, text, i, next);
out.append("</");
out.append(tagType);
out.append(">\n");
if (next == end && isInList) {
isInList = false;
out.append("</ul>\n");
}
}
next++;
}
}
use of android.text.style.BulletSpan in project platform_frameworks_base by android.
the class HtmlToSpannedConverter method endLi.
private static void endLi(Editable text) {
endCssStyle(text);
endBlockElement(text);
end(text, Bullet.class, new BulletSpan());
}
use of android.text.style.BulletSpan in project WordPress-Android by wordpress-mobile.
the class WPHtmlTagHandler method handleListTag.
private void handleListTag(Editable output) {
int size = mListParents.size();
if (size > 0 && output != null) {
if ("ul".equals(mListParents.get(size - 1))) {
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.setSpan(new BulletSpan(SPAN_INDENT_WIDTH * mListParents.size()), start, output.length(), 0);
} else if ("ol".equals(mListParents.get(size - 1))) {
mListItemCount++;
output.append("\n");
String[] split = output.toString().split("\n");
int start = 0;
if (split.length != 1) {
int lastIndex = split.length - 1;
start = output.length() - split[lastIndex].length() - 1;
}
output.insert(start, mListItemCount + ". ");
output.setSpan(new LeadingMarginSpan.Standard(SPAN_INDENT_WIDTH * mListParents.size()), start, output.length(), 0);
}
}
}
Aggregations