android.text.style.QuoteSpan Java Examples
The following examples show how to use
android.text.style.QuoteSpan.
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: KnifeText.java From Knife with Apache License 2.0 | 6 votes |
protected boolean containQuote(int index) { String[] lines = TextUtils.split(getEditableText().toString(), "\n"); if (index < 0 || index >= lines.length) { return false; } int start = 0; for (int i = 0; i < index; i++) { start = start + lines[i].length() + 1; } int end = start + lines[index].length(); if (start >= end) { return false; } QuoteSpan[] spans = getEditableText().getSpans(start, end, QuoteSpan.class); return spans.length > 0; }
Example #2
Source File: HtmlParser.java From Overchan-Android with GNU General Public License v3.0 | 6 votes |
private static void endBlockquote(SpannableStringBuilder text, ThemeColors colors) { int len = text.length(); Object obj = getLast(text, Blockquote.class); int where = text.getSpanStart(obj); text.removeSpan(obj); if (where != len) { Blockquote b = (Blockquote) obj; if (b.mIsUnkfunc) { if (colors != null) { text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { text.setSpan(new QuoteSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example #3
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 #4
Source File: KnifeText.java From Knife with Apache License 2.0 | 5 votes |
protected void quoteInvalid() { String[] lines = TextUtils.split(getEditableText().toString(), "\n"); for (int i = 0; i < lines.length; i++) { if (!containQuote(i)) { continue; } int lineStart = 0; for (int j = 0; j < i; j++) { lineStart = lineStart + lines[j].length() + 1; } int lineEnd = lineStart + lines[i].length(); if (lineStart >= lineEnd) { continue; } int quoteStart = 0; int quoteEnd = 0; if (lineStart <= getSelectionStart() && getSelectionEnd() <= lineEnd) { quoteStart = lineStart; quoteEnd = lineEnd; } else if (getSelectionStart() <= lineStart && lineEnd <= getSelectionEnd()) { quoteStart = lineStart; quoteEnd = lineEnd; } if (quoteStart < quoteEnd) { QuoteSpan[] spans = getEditableText().getSpans(quoteStart, quoteEnd, QuoteSpan.class); for (QuoteSpan span : spans) { getEditableText().removeSpan(span); } } } }
Example #5
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 5 votes |
public TextDecorator quote(final String... texts) { int index; for (String text : texts) { if (content.contains(text)) { index = content.indexOf(text); decoratedContent.setSpan(new QuoteSpan(), index, index + text.length(), flags); } } return this; }
Example #6
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 5 votes |
public TextDecorator quote(@ColorRes final int colorResId, final int start, final int end) { checkIndexOutOfBoundsException(start, end); decoratedContent.setSpan(new QuoteSpan(ContextCompat.getColor(textView.getContext(), colorResId)), start, end, flags); return this; }
Example #7
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 5 votes |
public TextDecorator quote(@ColorRes final int colorResId, final String... texts) { int index; for (String text : texts) { if (content.contains(text)) { index = content.indexOf(text); decoratedContent.setSpan(new QuoteSpan(ContextCompat.getColor(textView.getContext(), colorResId)), index, index + text.length(), flags); } } return this; }
Example #8
Source File: Trestle.java From Trestle with Apache License 2.0 | 5 votes |
private static void setUpQuoteSpan(Span span, SpannableString ss, int start, int end) { int quoteColor = span.getQuoteColor(); if (quoteColor != 0) { ss.setSpan( new QuoteSpan(quoteColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
Example #9
Source File: StyleBuilderImpl.java From Markdown with MIT License | 5 votes |
@Override public SpannableStringBuilder quota(CharSequence charSequence) { SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence); QuoteSpan span = new MarkDownQuoteSpan(quota_color); spannableStringBuilder.setSpan(span, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableStringBuilder.setSpan(new ForegroundColorSpan(quota_text_color), 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableStringBuilder; }
Example #10
Source File: KmarkProcessorTest.java From kaif-android with Apache License 2.0 | 5 votes |
public void testNestSpan_order_as_begin() { SpannableStringBuilder result = (SpannableStringBuilder) KmarkProcessor.process(getContext(), "> *Sample* text"); Object[] spans = result.getSpans(0, result.length(), Object.class); assertEquals(QuoteSpan.class, spans[0].getClass()); assertEquals(StyleSpan.class, spans[1].getClass()); }
Example #11
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 4 votes |
private static void endBlockquote(Editable text) { endBlockElement(text); end(text, Blockquote.class, new QuoteSpan()); }
Example #12
Source File: Html.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static void endBlockquote(Editable text) { endBlockElement(text); end(text, Blockquote.class, new QuoteSpan()); }
Example #13
Source File: Html.java From EhViewer with Apache License 2.0 | 4 votes |
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("ins")) { end(mSpannableStringBuilder, Underline.class, new UnderlineSpan()); } else if (tag.equalsIgnoreCase("strike")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("s")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("del")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } 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); } }
Example #14
Source File: SpanOptions.java From AndroidSpan with Apache License 2.0 | 4 votes |
public SpanOptions addQuoteSpan(int color) { QuoteSpan span = new QuoteSpan(color); listSpan.add(span); return this; }
Example #15
Source File: DefaultDecorator.java From kaif-android with Apache License 2.0 | 4 votes |
@Override public void closeBlockquote(SpannableStringBuilder out) { end(out, Blockquote.class, new QuoteSpan()); }
Example #16
Source File: Html.java From Nimingban with Apache License 2.0 | 4 votes |
private void handleEndTag(String tag) { if (mTagHandler == null || !mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader, null)) { 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("ins")) { end(mSpannableStringBuilder, Underline.class, new UnderlineSpan()); } else if (tag.equalsIgnoreCase("strike")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("s")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("del")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } 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); } } }
Example #17
Source File: ConverterHtmlToSpanned.java From memoir with Apache License 2.0 | 4 votes |
private void handleEndTag(String tag) { if (tag.equalsIgnoreCase("br")) { handleBr(); } else if (tag.equalsIgnoreCase("p")) { handleP(); } else if (tag.equalsIgnoreCase("div")) { endDiv(); } else if (tag.equalsIgnoreCase("ul")) { endList(false); } else if (tag.equalsIgnoreCase("ol")) { endList(true); } else if (tag.equalsIgnoreCase("li")) { endList(); } else if (tag.equalsIgnoreCase("strong")) { end(Bold.class, new BoldSpan()); } else if (tag.equalsIgnoreCase("b")) { end(Bold.class, new BoldSpan()); } else if (tag.equalsIgnoreCase("em")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("cite")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("dfn")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("i")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("strike")) { end(Strikethrough.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("del")) { end(Strikethrough.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("big")) { end(Big.class, new RelativeSizeSpan(1.25f)); } else if (tag.equalsIgnoreCase("small")) { end(Small.class, new RelativeSizeSpan(0.8f)); } else if (tag.equalsIgnoreCase("font")) { endFont(); } else if (tag.equalsIgnoreCase("blockquote")) { handleP(); end(Blockquote.class, new QuoteSpan()); } else if (tag.equalsIgnoreCase("a")) { endAHref(); } else if (tag.equalsIgnoreCase("u")) { end(Underline.class, new UnderlineSpan()); } else if (tag.equalsIgnoreCase("sup")) { end(Super.class, new SuperscriptSpan()); } else if (tag.equalsIgnoreCase("sub")) { end(Sub.class, new SubscriptSpan()); } else if (tag.length() == 2 && Character.toLowerCase(tag.charAt(0)) == 'h' && tag.charAt(1) >= '1' && tag.charAt(1) <= '6') { handleP(); endHeader(); } else if (sIgnoreTags.contains(tag.toLowerCase(Locale.getDefault()))) { mIgnoreContent = false; } }
Example #18
Source File: ConverterHtmlToSpanned.java From memoir with Apache License 2.0 | 4 votes |
private void handleEndTag(String tag) { if (tag.equalsIgnoreCase("br")) { handleBr(); } else if (tag.equalsIgnoreCase("p")) { handleP(); } else if (tag.equalsIgnoreCase("div")) { endDiv(); } else if (tag.equalsIgnoreCase("ul")) { endList(false); } else if (tag.equalsIgnoreCase("ol")) { endList(true); } else if (tag.equalsIgnoreCase("li")) { endList(); } else if (tag.equalsIgnoreCase("strong")) { end(Bold.class, new BoldSpan()); } else if (tag.equalsIgnoreCase("b")) { end(Bold.class, new BoldSpan()); } else if (tag.equalsIgnoreCase("em")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("cite")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("dfn")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("i")) { end(Italic.class, new ItalicSpan()); } else if (tag.equalsIgnoreCase("strike")) { end(Strikethrough.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("del")) { end(Strikethrough.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("big")) { end(Big.class, new RelativeSizeSpan(1.25f)); } else if (tag.equalsIgnoreCase("small")) { end(Small.class, new RelativeSizeSpan(0.8f)); } else if (tag.equalsIgnoreCase("font")) { endFont(); } else if (tag.equalsIgnoreCase("blockquote")) { handleP(); end(Blockquote.class, new QuoteSpan()); } else if (tag.equalsIgnoreCase("a")) { endAHref(); } else if (tag.equalsIgnoreCase("u")) { end(Underline.class, new UnderlineSpan()); } else if (tag.equalsIgnoreCase("sup")) { end(Super.class, new SuperscriptSpan()); } else if (tag.equalsIgnoreCase("sub")) { end(Sub.class, new SubscriptSpan()); } else if (tag.length() == 2 && Character.toLowerCase(tag.charAt(0)) == 'h' && tag.charAt(1) >= '1' && tag.charAt(1) <= '6') { handleP(); endHeader(); } else if (sIgnoreTags.contains(tag.toLowerCase(Locale.getDefault()))) { mIgnoreContent = false; } }
Example #19
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 4 votes |
public TextDecorator quote(final int start, final int end) { checkIndexOutOfBoundsException(start, end); decoratedContent.setSpan(new QuoteSpan(), start, end, flags); return this; }
Example #20
Source File: Html.java From ForPDA with GNU General Public License v3.0 | 4 votes |
private static void endBlockquote(Editable text) { endBlockElement(text); end(text, Blockquote.class, new QuoteSpan()); }
Example #21
Source File: HtmlToSpannedConverter.java From HtmlCompat with Apache License 2.0 | 4 votes |
private void endBlockquote(String tag, Editable text) { endBlockElement(tag, text); end(tag, text, Blockquote.class, new QuoteSpan()); }
Example #22
Source File: Span.java From Android-Spans with Apache License 2.0 | 4 votes |
public static Node quote(@ColorInt Integer color, Object... nodes) { return new SpanNode(new QuoteSpan(color), nodes); }
Example #23
Source File: Span.java From Android-Spans with Apache License 2.0 | 4 votes |
public static Node quote(Object... nodes) { return new SpanNode(new QuoteSpan(), nodes); }
Example #24
Source File: Html.java From MHViewer with Apache License 2.0 | 4 votes |
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("ins")) { end(mSpannableStringBuilder, Underline.class, new UnderlineSpan()); } else if (tag.equalsIgnoreCase("strike")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("s")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("del")) { end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan()); } 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); } }
Example #25
Source File: AndroidSpan.java From AndroidSpan with Apache License 2.0 | 2 votes |
/** * 左侧添加一条表示引用的竖线 * * @param text * @param color * @return */ public AndroidSpan drawQuoteSpan(String text, int color) { QuoteSpan span = new QuoteSpan(color); drawSpan(text, span); return this; }