Java Code Examples for android.text.Spanned#nextSpanTransition()
The following examples show how to use
android.text.Spanned#nextSpanTransition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Html.java From MHViewer with Apache License 2.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text) { int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for(int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next); if (needDiv) { out.append("</div>"); } } }
Example 2
Source File: Html.java From tysq-android with GNU General Public License v3.0 | 5 votes |
private static void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, IBlockStyle.class); // ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); // String elements = " "; // boolean needDiv = false; // for (int j = 0; j < style.length; j++) { // if (style[j] instanceof AlignmentSpan) { // Layout.Alignment align = // ((AlignmentSpan) style[j]).getAlignment(); // needDiv = true; // if (align == Layout.Alignment.ALIGN_CENTER) { // elements = "align=\"center\" " + elements; // } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { // elements = "align=\"right\" " + elements; // } else { // elements = "align=\"left\" " + elements; // } // } // } // if (needDiv) { // out.append("<div ").append(elements).append(">"); // } withinDiv(out, text, i, next, option); // if (needDiv) { // out.append("</div>"); // } } }
Example 3
Source File: HtmlEx.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private /* static */ void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for(int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next, option); if (needDiv) { out.append("</div>"); } } }
Example 4
Source File: HtmlCompat.java From HtmlCompat with Apache License 2.0 | 5 votes |
private static void encodeTextAlignmentByDiv(Context context, StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] styles = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for (ParagraphStyle style : styles) { if (style instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(context, out, text, i, next, option); if (needDiv) { out.append("</div>"); } } }
Example 5
Source File: Html.java From ForPDA with GNU General Public License v3.0 | 5 votes |
private static void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for (int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next, option); if (needDiv) { out.append("</div>"); } } }
Example 6
Source File: MyHtml.java From nono-android with GNU General Public License v3.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text) { int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for(int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next); if (needDiv) { out.append("</div>"); } } }
Example 7
Source File: Html.java From Nimingban with Apache License 2.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text) { int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for(int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next); if (needDiv) { out.append("</div>"); } } }
Example 8
Source File: EmailHtmlUtil.java From RichEditText with Apache License 2.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text ) { int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for (int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]) .getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div " + elements + ">"); } withinDiv(out, text, i, next); if (needDiv) { out.append("</div>"); } } }
Example 9
Source File: SelectionPopupController.java From 365browser with Apache License 2.0 | 5 votes |
private boolean hasStyleSpan(Spanned spanned) { // Only check against those three classes below, which could affect text appearance, since // there are other kind of classes won't affect appearance. Class<?>[] styleClasses = { CharacterStyle.class, ParagraphStyle.class, UpdateAppearance.class}; for (Class<?> clazz : styleClasses) { if (spanned.nextSpanTransition(-1, spanned.length(), clazz) < spanned.length()) { return true; } } return false; }
Example 10
Source File: Clipboard.java From 365browser with Apache License 2.0 | 5 votes |
private boolean hasStyleSpan(Spanned spanned) { Class<?>[] styleClasses = { CharacterStyle.class, ParagraphStyle.class, UpdateAppearance.class}; for (Class<?> clazz : styleClasses) { if (spanned.nextSpanTransition(-1, spanned.length(), clazz) < spanned.length()) { return true; } } return false; }
Example 11
Source File: KnifeParser.java From Knife with Apache License 2.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text) { int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, text.length(), ParagraphStyle.class); ParagraphStyle[] styles = text.getSpans(i, next, ParagraphStyle.class); if (styles.length == 2) { if (styles[0] instanceof BulletSpan && styles[1] instanceof QuoteSpan) { // Let a <br> follow the BulletSpan or QuoteSpan end, so next++ withinBulletThenQuote(out, text, i, next++); } else if (styles[0] instanceof QuoteSpan && styles[1] instanceof BulletSpan) { withinQuoteThenBullet(out, text, i, next++); } else { withinContent(out, text, i, next); } } else if (styles.length == 1) { if (styles[0] instanceof BulletSpan) { withinBullet(out, text, i, next++); } else if (styles[0] instanceof QuoteSpan) { withinQuote(out, text, i, next++); } else { withinContent(out, text, i, next); } } else { withinContent(out, text, i, next); } } }
Example 12
Source File: Html.java From EhViewer with Apache License 2.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text) { int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for(int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next); if (needDiv) { out.append("</div>"); } } }
Example 13
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 5 votes |
private static void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for (int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next, option); if (needDiv) { out.append("</div>"); } } }