Java Code Examples for android.text.Spanned#SPAN_INCLUSIVE_INCLUSIVE
The following examples show how to use
android.text.Spanned#SPAN_INCLUSIVE_INCLUSIVE .
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: RichUtils.java From RichEditor with MIT License | 6 votes |
private void handleInlineStyle(int start, int end, Class spanClazz, StyleBtnVm styleBtnVm) { Editable editable = mRichEditText.getEditableText(); IInlineSpan[] inlineSpans = (IInlineSpan[]) editable.getSpans(start, end, spanClazz); // 先将两端的span进行切割 handleInlineStyleBoundary(start, end, spanClazz); // 可能存在多个分段的span,需要先都移除 for (IInlineSpan span : inlineSpans) { editable.removeSpan(span); } if (styleBtnVm.isLight()) { int flags = start == end ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : Spanned.SPAN_EXCLUSIVE_INCLUSIVE; editable.setSpan(getInlineStyleSpan(spanClazz), start, end, flags); mergeContinuousInlineSpan(start, end, spanClazz); } }
Example 2
Source File: ParagraphSpanProcessor.java From memoir with Apache License 2.0 | 6 votes |
void process(Spannable str) { for (ParagraphSpan paragraphSpan : mParagraphSpans) { RTParagraphSpan<V> span = paragraphSpan.mSpan; int paraStart = paragraphSpan.mParagraph.start(); if (paragraphSpan.mRemove) { int spanStart = str.getSpanStart(span); if (spanStart > -1 && spanStart < paraStart) { // process preceding spans str.setSpan(span.createClone(), spanStart, paraStart, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); } str.removeSpan(span); } else { Paragraph paragraph = paragraphSpan.mParagraph; int paraEnd = paragraphSpan.mParagraph.end(); int flags = paragraph.isLast() && paragraph.isEmpty() ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : paragraph.isLast() && paragraph.isFirst() ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : paragraph.isLast() ? Spanned.SPAN_EXCLUSIVE_INCLUSIVE : Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; str.setSpan(span, paraStart, paraEnd, flags); } } }
Example 3
Source File: ParagraphSpanProcessor.java From memoir with Apache License 2.0 | 6 votes |
void process(Spannable str) { for (ParagraphSpan paragraphSpan : mParagraphSpans) { RTParagraphSpan<V> span = paragraphSpan.mSpan; int paraStart = paragraphSpan.mParagraph.start(); if (paragraphSpan.mRemove) { int spanStart = str.getSpanStart(span); if (spanStart > -1 && spanStart < paraStart) { // process preceding spans str.setSpan(span.createClone(), spanStart, paraStart, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); } str.removeSpan(span); } else { Paragraph paragraph = paragraphSpan.mParagraph; int paraEnd = paragraphSpan.mParagraph.end(); int flags = paragraph.isLast() && paragraph.isEmpty() ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : paragraph.isLast() && paragraph.isFirst() ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : paragraph.isLast() ? Spanned.SPAN_EXCLUSIVE_INCLUSIVE : Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; str.setSpan(span, paraStart, paraEnd, flags); } } }
Example 4
Source File: ParagraphSpanProcessor.java From Android-RTEditor with Apache License 2.0 | 6 votes |
void process(Spannable str) { for (ParagraphSpan paragraphSpan : mParagraphSpans) { RTParagraphSpan<V> span = paragraphSpan.mSpan; int paraStart = paragraphSpan.mParagraph.start(); if (paragraphSpan.mRemove) { int spanStart = str.getSpanStart(span); if (spanStart > -1 && spanStart < paraStart) { // process preceding spans str.setSpan(span.createClone(), spanStart, paraStart, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); } str.removeSpan(span); } else { Paragraph paragraph = paragraphSpan.mParagraph; int paraEnd = paragraphSpan.mParagraph.end(); int flags = paragraph.isLast() && paragraph.isEmpty() ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : paragraph.isLast() && paragraph.isFirst() ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : paragraph.isLast() ? Spanned.SPAN_EXCLUSIVE_INCLUSIVE : Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; str.setSpan(span, paraStart, paraEnd, flags); } } }
Example 5
Source File: RichUtils.java From RichEditor with MIT License | 5 votes |
/** * 获取合并后的span flag * * @param mergedLeftSpanFlag 被合并的左侧span flag * @param mergedRightSpanFlag 被合并的右侧span flag * @return 合并后的flag */ private int getMergeSpanFlag(int mergedLeftSpanFlag, int mergedRightSpanFlag) { boolean isStartInclusive = false; // 是否包括左端点 boolean isEndInclusive = false; // 是否包括右端点 if (mergedLeftSpanFlag == Spanned.SPAN_INCLUSIVE_EXCLUSIVE || mergedLeftSpanFlag == Spanned.SPAN_INCLUSIVE_INCLUSIVE) { isStartInclusive = true; } if (mergedRightSpanFlag == Spanned.SPAN_INCLUSIVE_INCLUSIVE || mergedRightSpanFlag == Spanned.SPAN_EXCLUSIVE_INCLUSIVE) { isEndInclusive = true; } if (isStartInclusive && isEndInclusive) { return Spanned.SPAN_INCLUSIVE_INCLUSIVE; } if (isStartInclusive) { return Spanned.SPAN_INCLUSIVE_EXCLUSIVE; } if (isEndInclusive) { return Spanned.SPAN_EXCLUSIVE_INCLUSIVE; } return Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; }
Example 6
Source File: RichUtils.java From RichEditor with MIT License | 5 votes |
private int getBlockSpanFlag(@RichTypeEnum String type) { if (RichTypeEnum.BLOCK_QUOTE.equals(type)) { return Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; } return Spanned.SPAN_INCLUSIVE_INCLUSIVE; }
Example 7
Source File: RichUtils.java From RichEditor with MIT License | 5 votes |
/** * 处理行内样式各个按钮的状态(点亮或置灰) * * @param type 样式类型 */ private boolean handleInlineStyleButtonStatus(@RichTypeEnum String type) { Editable editable = mRichEditText.getEditableText(); int cursorPos = mRichEditText.getSelectionEnd(); IInlineSpan[] inlineSpans = (IInlineSpan[]) editable.getSpans(cursorPos, cursorPos, getSpanClassFromType(type)); if (inlineSpans.length <= 0) { return false; } boolean isLight = false; //是否点亮 for (IInlineSpan span : inlineSpans) { int spanStart = editable.getSpanStart(span); int spanEnd = editable.getSpanEnd(span); int spanFlag = editable.getSpanFlags(span); if (spanStart < cursorPos && spanEnd > cursorPos) { isLight = true; } else if (spanStart == cursorPos && (spanFlag == Spanned.SPAN_INCLUSIVE_INCLUSIVE || spanFlag == Spanned.SPAN_INCLUSIVE_EXCLUSIVE)) { isLight = true; } else if (spanEnd == cursorPos && (spanFlag == Spanned.SPAN_INCLUSIVE_INCLUSIVE || spanFlag == Spanned.SPAN_EXCLUSIVE_INCLUSIVE)) { isLight = true; } } return isLight; }
Example 8
Source File: LocaleSpanCompatUtils.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
private static int getSpanPointMarkFlag(final boolean isStartExclusive, final boolean isEndExclusive) { if (isStartExclusive) { return isEndExclusive ? Spanned.SPAN_EXCLUSIVE_EXCLUSIVE : Spanned.SPAN_EXCLUSIVE_INCLUSIVE; } return isEndExclusive ? Spanned.SPAN_INCLUSIVE_EXCLUSIVE : Spanned.SPAN_INCLUSIVE_INCLUSIVE; }
Example 9
Source File: SpannableStringHelper.java From revolution-irc with GNU General Public License v3.0 | 5 votes |
public static boolean checkSpanInclude(int spanStart, int spanEnd, int spanFlags, int start, int end) { int pointFlags = spanFlags & Spanned.SPAN_POINT_MARK_MASK; boolean includesStart = pointFlags == Spanned.SPAN_INCLUSIVE_EXCLUSIVE || pointFlags == Spanned.SPAN_INCLUSIVE_INCLUSIVE; boolean includesEnd = pointFlags == Spanned.SPAN_EXCLUSIVE_INCLUSIVE || pointFlags == Spanned.SPAN_INCLUSIVE_INCLUSIVE; return (start > spanStart || (spanStart == start && includesStart)) && (end < spanEnd || (spanEnd == end && includesEnd)); }
Example 10
Source File: RichEditor.java From RichEditor with MIT License | 5 votes |
public <T extends Styleable> int startStyleWithRange(Style<T> style, int start, int end, Object... args) { SpannableStringBuilder spannableStringBuilder = getSSB(); int flag = start == end ? Spanned.SPAN_INCLUSIVE_INCLUSIVE : Spanned.SPAN_EXCLUSIVE_INCLUSIVE; Styleable span = style.needArgument() ? style.createSpan(args) : style.createSpan(); if (style instanceof StyleExt) { ((StyleExt) style).beforeStyle(spannableStringBuilder, start, end); } startStyle(start, end, spannedProvider.getSSB(), span, flag); if (style instanceof StyleExt) { ((StyleExt) style).afterStyle(spannableStringBuilder, start, end); } return StyleTypeStateSpec.StyleTypeState.STATE_ACTIVE; }
Example 11
Source File: LocaleSpanCompatUtils.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
private static int getSpanPointMarkFlag(final boolean isStartExclusive, final boolean isEndExclusive) { if (isStartExclusive) { return isEndExclusive ? Spanned.SPAN_EXCLUSIVE_EXCLUSIVE : Spanned.SPAN_EXCLUSIVE_INCLUSIVE; } return isEndExclusive ? Spanned.SPAN_INCLUSIVE_EXCLUSIVE : Spanned.SPAN_INCLUSIVE_INCLUSIVE; }
Example 12
Source File: SpanEZ.java From SpanEZ with Apache License 2.0 | 4 votes |
@Override public StyleEZ inclusive() { spanFlags = Spanned.SPAN_INCLUSIVE_INCLUSIVE; return this; }
Example 13
Source File: SpannableStringUtilsTests.java From Indic-Keyboard with Apache License 2.0 | 4 votes |
public void testSplitCharSequenceWithSpan() { // text: " a bcd efg hij " // span1: ^^^^^^^ // span2: ^^^^^ // span3: ^ final SpannableString spannableString = new SpannableString(" a bcd efg hij "); final Object span1 = new Object(); final Object span2 = new Object(); final Object span3 = new Object(); final int SPAN1_FLAGS = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; final int SPAN2_FLAGS = Spanned.SPAN_EXCLUSIVE_INCLUSIVE; final int SPAN3_FLAGS = Spanned.SPAN_INCLUSIVE_INCLUSIVE; spannableString.setSpan(span1, 0, 7, SPAN1_FLAGS); spannableString.setSpan(span2, 0, 5, SPAN2_FLAGS); spannableString.setSpan(span3, 12, 13, SPAN3_FLAGS); final CharSequence[] charSequencesFromSpanned = SpannableStringUtils.split( spannableString, " ", true /* preserveTrailingEmptySegmengs */); final CharSequence[] charSequencesFromString = SpannableStringUtils.split( spannableString.toString(), " ", true /* preserveTrailingEmptySegmengs */); assertEquals(7, charSequencesFromString.length); assertEquals(7, charSequencesFromSpanned.length); // text: "" // span1: ^ // span2: ^ // span3: assertEquals("", charSequencesFromString[0].toString()); assertSpanCount(0, charSequencesFromString[0]); assertEquals("", charSequencesFromSpanned[0].toString()); assertSpanCount(2, charSequencesFromSpanned[0]); assertSpan(charSequencesFromSpanned[0], span1, 0, 0, SPAN1_FLAGS); assertSpan(charSequencesFromSpanned[0], span2, 0, 0, SPAN2_FLAGS); // text: "a" // span1: ^ // span2: ^ // span3: assertEquals("a", charSequencesFromString[1].toString()); assertSpanCount(0, charSequencesFromString[1]); assertEquals("a", charSequencesFromSpanned[1].toString()); assertSpanCount(2, charSequencesFromSpanned[1]); assertSpan(charSequencesFromSpanned[1], span1, 0, 1, SPAN1_FLAGS); assertSpan(charSequencesFromSpanned[1], span2, 0, 1, SPAN2_FLAGS); // text: "bcd" // span1: ^^^ // span2: ^^ // span3: assertEquals("bcd", charSequencesFromString[2].toString()); assertSpanCount(0, charSequencesFromString[2]); assertEquals("bcd", charSequencesFromSpanned[2].toString()); assertSpanCount(2, charSequencesFromSpanned[2]); assertSpan(charSequencesFromSpanned[2], span1, 0, 3, SPAN1_FLAGS); assertSpan(charSequencesFromSpanned[2], span2, 0, 2, SPAN2_FLAGS); // text: "efg" // span1: // span2: // span3: assertEquals("efg", charSequencesFromString[3].toString()); assertSpanCount(0, charSequencesFromString[3]); assertEquals("efg", charSequencesFromSpanned[3].toString()); assertSpanCount(0, charSequencesFromSpanned[3]); // text: "hij" // span1: // span2: // span3: ^ assertEquals("hij", charSequencesFromString[4].toString()); assertSpanCount(0, charSequencesFromString[4]); assertEquals("hij", charSequencesFromSpanned[4].toString()); assertSpanCount(1, charSequencesFromSpanned[4]); assertSpan(charSequencesFromSpanned[4], span3, 1, 2, SPAN3_FLAGS); // text: "" // span1: // span2: // span3: assertEquals("", charSequencesFromString[5].toString()); assertSpanCount(0, charSequencesFromString[5]); assertEquals("", charSequencesFromSpanned[5].toString()); assertSpanCount(0, charSequencesFromSpanned[5]); // text: "" // span1: // span2: // span3: assertEquals("", charSequencesFromString[6].toString()); assertSpanCount(0, charSequencesFromString[6]); assertEquals("", charSequencesFromSpanned[6].toString()); assertSpanCount(0, charSequencesFromSpanned[6]); }