Package icyllis.modernui.text
Class SpannableStringBuilder
java.lang.Object
icyllis.modernui.text.SpannableStringBuilder
- All Implemented Interfaces:
Editable,GetChars,Spannable,Spanned,Appendable,CharSequence
public class SpannableStringBuilder
extends Object
implements Editable, Spannable, GetChars, Appendable
This is the class for text whose content and markup can both be changed.
-
Nested Class Summary
Nested classes/interfaces inherited from interface icyllis.modernui.text.Editable
Editable.FactoryNested classes/interfaces inherited from interface icyllis.modernui.text.Spannable
Spannable.Factory -
Field Summary
FieldsFields inherited from interface icyllis.modernui.text.Editable
DEFAULT_FACTORY, NO_COPY_FACTORYFields inherited from interface icyllis.modernui.text.Spannable
DEFAULT_FACTORY, NO_COPY_FACTORYFields inherited from interface icyllis.modernui.text.Spanned
SPAN_COMPOSING, SPAN_EXCLUSIVE_EXCLUSIVE, SPAN_EXCLUSIVE_INCLUSIVE, SPAN_INCLUSIVE_EXCLUSIVE, SPAN_INCLUSIVE_INCLUSIVE, SPAN_INTERMEDIATE, SPAN_MARK_MARK, SPAN_MARK_POINT, SPAN_PARAGRAPH, SPAN_POINT_MARK, SPAN_POINT_MARK_MASK, SPAN_POINT_POINT, SPAN_PRIORITY, SPAN_PRIORITY_SHIFT, SPAN_USER, SPAN_USER_SHIFT -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new SpannableStringBuilder with empty contentsCreate a new SpannableStringBuilder containing a copy of the specified text, including its spans if any.SpannableStringBuilder(CharSequence text, int start, int end) Create a new SpannableStringBuilder containing a copy of the specified slice of the specified text, including its spans if any. -
Method Summary
Modifier and TypeMethodDescriptionappend(char text) Convenience for append(String.valueOf(text)).append(CharSequence text) Convenience for replace(length(), length(), text, 0, text.length())append(CharSequence text, int start, int end) Convenience for replace(length(), length(), text, start, end)append(CharSequence text, Object what, int flags) Appends the character sequencetextand spanswhatover the appended part.charcharAt(int where) Return the char at the specified offset within the buffer.voidclear()Convenience for replace(0, length(), "", 0, 0).voidRemoves all spans from the Editable, as if by callingremoveSpan(int, int)on each of them.delete(int start, int end) Convenience for replace(st, en, "", 0, 0)booleanvoidgetChars(int start, int end, char[] dest, int destoff) Copy the specified range of chars from this buffer into the specified array, beginning at the specified offset.Returns the array of input filters that are currently applied to changes to this Editable.intgetSpanEnd(Object what) Return the buffer offset of the end of the specified markup object, or -1 if it is not attached to this buffer.intgetSpanFlags(Object what) Return the flags of the end of the specified markup object, or 0 if it is not attached to this buffer.<T> List<T> Return an array of the spans of the specified type that overlap the specified range of the buffer.intgetSpanStart(Object what) Return the buffer offset of the beginning of the specified markup object, or -1 if it is not attached to this buffer.intReturns the depth of TextWatcher callbacks.inthashCode()insert(int where, CharSequence tb) Convenience for replace(where, where, text, 0, text.length());insert(int where, CharSequence tb, int start, int end) Convenience for replace(where, where, text, start, end)intlength()Return the number of chars in the buffer.intnextSpanTransition(int start, int limit, Class<?> kind) Return the next offset afterstartbut less than or equal tolimitwhere a span of the specified type begins or ends.voidremoveSpan(Object what) Remove the specified markup object from the buffer.voidremoveSpan(Object what, int flags) Remove the specified markup object from the buffer.replace(int start, int end, CharSequence tb) Convenience for replace(st, en, text, 0, text.length())replace(int start, int end, CharSequence tb, int tbstart, int tbend) Replaces the specified range (start…end) of text in this Editable with a copy of the slicetbstart…tbendfromtb.voidsetFilters(InputFilter[] filters) Sets the series of filters that will be called in succession whenever the text of this Editable is changed, each of which has the opportunity to limit or transform the text that is being inserted.voidMark the specified range of text with the specified object.subSequence(int start, int end) Return a new CharSequence containing a copy of the specified range of this buffer, including the overlapping spans.substring(int start, int end) Return a String containing a copy of the chars in this buffer, limited to the [start, end) range.toString()Return a String containing a copy of the chars in this buffer.static SpannableStringBuildervalueOf(CharSequence source) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
MARKER
public static final org.slf4j.Marker MARKER
-
-
Constructor Details
-
SpannableStringBuilder
public SpannableStringBuilder()Create a new SpannableStringBuilder with empty contents -
SpannableStringBuilder
Create a new SpannableStringBuilder containing a copy of the specified text, including its spans if any. -
SpannableStringBuilder
Create a new SpannableStringBuilder containing a copy of the specified slice of the specified text, including its spans if any.
-
-
Method Details
-
valueOf
-
charAt
public char charAt(int where) Return the char at the specified offset within the buffer.- Specified by:
charAtin interfaceCharSequence
-
length
public int length()Return the number of chars in the buffer.- Specified by:
lengthin interfaceCharSequence
-
insert
Convenience for replace(where, where, text, start, end) -
insert
Convenience for replace(where, where, text, 0, text.length()); -
delete
Convenience for replace(st, en, "", 0, 0) -
clear
public void clear()Convenience for replace(0, length(), "", 0, 0). Note that this clears the text, not the spans; useclearSpans()if you need that. -
clearSpans
public void clearSpans()Removes all spans from the Editable, as if by callingremoveSpan(int, int)on each of them.- Specified by:
clearSpansin interfaceEditable
-
append
Convenience for replace(length(), length(), text, 0, text.length())- Specified by:
appendin interfaceAppendable- Specified by:
appendin interfaceEditable- See Also:
-
append
Appends the character sequencetextand spanswhatover the appended part. SeeSpannedfor an explanation of what the flags mean.- Parameters:
text- the character sequence to append.what- the object to be spanned over the appended text.flags- seeSpanned.- Returns:
- this
SpannableStringBuilder.
-
append
Convenience for replace(length(), length(), text, start, end)- Specified by:
appendin interfaceAppendable- Specified by:
appendin interfaceEditable- See Also:
-
append
Convenience for append(String.valueOf(text)).- Specified by:
appendin interfaceAppendable- Specified by:
appendin interfaceEditable- See Also:
-
replace
Convenience for replace(st, en, text, 0, text.length()) -
replace
public SpannableStringBuilder replace(int start, int end, @NonNull CharSequence tb, int tbstart, int tbend) Replaces the specified range (start…end) of text in this Editable with a copy of the slicetbstart…tbendfromtb. The destination slice may be empty, in which case the operation is an insertion, or the source slice may be empty, in which case the operation is a deletion.Before the change is committed, each filter that was set with
setFilters(icyllis.modernui.text.InputFilter[])is given the opportunity to modify thesourcetext.If
sourceis Spanned, the spans from it are preserved into the Editable. Existing spans within the Editable that entirely cover the replaced range are retained, but any that were strictly within the range that was replaced are removed. If thesourcecontains a span withSpanned.SPAN_PARAGRAPHflag, and it does not satisfy the paragraph boundary constraint, it is not retained. As a special case, the cursor position is preserved even when the entire range where it is located is replaced. -
setSpan
Mark the specified range of text with the specified object. The flags determine how the span will behave when text is inserted at the start or end of the span's range. -
removeSpan
Remove the specified markup object from the buffer.- Specified by:
removeSpanin interfaceSpannable- Parameters:
what- markup object to remove
-
removeSpan
Remove the specified markup object from the buffer.- Specified by:
removeSpanin interfaceSpannable- Parameters:
what- markup object to removeflags- flags
-
getSpanStart
Return the buffer offset of the beginning of the specified markup object, or -1 if it is not attached to this buffer.- Specified by:
getSpanStartin interfaceSpanned- Parameters:
what- markup object- Returns:
- the start char index
-
getSpanEnd
Return the buffer offset of the end of the specified markup object, or -1 if it is not attached to this buffer.- Specified by:
getSpanEndin interfaceSpanned- Parameters:
what- markup object- Returns:
- the end char index
-
getSpanFlags
Return the flags of the end of the specified markup object, or 0 if it is not attached to this buffer.- Specified by:
getSpanFlagsin interfaceSpanned- Parameters:
what- markup object- Returns:
- the flags
-
getSpans
@NonNull public <T> List<T> getSpans(int queryStart, int queryEnd, @Nullable Class<? extends T> kind, @Nullable List<T> dest) Return an array of the spans of the specified type that overlap the specified range of the buffer. The kind may be Object.class to get a list of all the spans regardless of type. -
nextSpanTransition
Return the next offset afterstartbut less than or equal tolimitwhere a span of the specified type begins or ends.- Specified by:
nextSpanTransitionin interfaceSpanned- Parameters:
start- start char index of the slicelimit- end char index of the slicekind- the markup type- Returns:
- transition point
-
subSequence
Return a new CharSequence containing a copy of the specified range of this buffer, including the overlapping spans.- Specified by:
subSequencein interfaceCharSequence
-
getChars
public void getChars(int start, int end, char[] dest, int destoff) Copy the specified range of chars from this buffer into the specified array, beginning at the specified offset. -
toString
Return a String containing a copy of the chars in this buffer.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
substring
Return a String containing a copy of the chars in this buffer, limited to the [start, end) range. -
getTextWatcherDepth
public int getTextWatcherDepth()Returns the depth of TextWatcher callbacks. Returns 0 when the object is not handling TextWatchers. A return value greater than 1 implies that a TextWatcher caused a change that recursively triggered a TextWatcher. -
setFilters
Sets the series of filters that will be called in succession whenever the text of this Editable is changed, each of which has the opportunity to limit or transform the text that is being inserted.- Specified by:
setFiltersin interfaceEditable
-
getFilters
Returns the array of input filters that are currently applied to changes to this Editable.- Specified by:
getFiltersin interfaceEditable
-
equals
-
hashCode
public int hashCode()
-