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.Factory
Nested classes/interfaces inherited from interface icyllis.modernui.text.Spannable
Spannable.Factory
-
Field Summary
Fields inherited from interface icyllis.modernui.text.Editable
DEFAULT_FACTORY
Fields inherited from interface icyllis.modernui.text.Spannable
DEFAULT_FACTORY
Fields 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
ConstructorDescriptionCreate 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 sequencetext
and spanswhat
over the appended part.char
charAt
(int where) Return the char at the specified offset within the buffer.void
clear()
Convenience for replace(0, length(), "", 0, 0).void
Removes 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)boolean
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.Returns the array of input filters that are currently applied to changes to this Editable.int
getSpanEnd
(Object what) Return the buffer offset of the end of the specified markup object, or -1 if it is not attached to this buffer.int
getSpanFlags
(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> getSpans
(int queryStart, int queryEnd, Class<? extends T> kind, boolean sortByInsertionOrder, List<T> dest) Return an array of the spans of the specified type that overlap the specified range of the buffer.<T> List
<T> Return an array of the spans of the specified type that overlap the specified range of the buffer.int
getSpanStart
(Object what) Return the buffer offset of the beginning of the specified markup object, or -1 if it is not attached to this buffer.int
Returns the depth of TextWatcher callbacks.int
hashCode()
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)int
length()
Return the number of chars in the buffer.int
nextSpanTransition
(int start, int limit, Class<?> kind) Return the next offset afterstart
but less than or equal tolimit
where a span of the specified type begins or ends.void
removeSpan
(Object what) Remove the specified markup object from the buffer.void
removeSpan
(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…tbend
fromtb
.void
setFilters
(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.void
Mark 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 SpannableStringBuilder
valueOf
(CharSequence source) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
MARKER
public static final org.apache.logging.log4j.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:
charAt
in interfaceCharSequence
-
length
public int length()Return the number of chars in the buffer.- Specified by:
length
in 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:
clearSpans
in interfaceEditable
-
append
Convenience for replace(length(), length(), text, 0, text.length())- Specified by:
append
in interfaceAppendable
- Specified by:
append
in interfaceEditable
- See Also:
-
append
Appends the character sequencetext
and spanswhat
over the appended part. SeeSpanned
for 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:
append
in interfaceAppendable
- Specified by:
append
in interfaceEditable
- See Also:
-
append
Convenience for append(String.valueOf(text)).- Specified by:
append
in interfaceAppendable
- Specified by:
append
in 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…tbend
fromtb
. 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 thesource
text.If
source
is 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 thesource
contains a span withSpanned.SPAN_PARAGRAPH
flag, 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:
removeSpan
in interfaceSpannable
- Parameters:
what
- markup object to remove
-
removeSpan
Remove the specified markup object from the buffer.- Specified by:
removeSpan
in 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:
getSpanStart
in 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:
getSpanEnd
in 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:
getSpanFlags
in 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> out) 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. -
getSpans
@Nonnull public <T> List<T> getSpans(int queryStart, int queryEnd, @Nullable Class<? extends T> kind, boolean sortByInsertionOrder, @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.- Type Parameters:
T
- Markup type.- Parameters:
queryStart
- Start index.queryEnd
- End index.kind
- Class type to search for.sortByInsertionOrder
- If true the results are sorted by the insertion order.- Returns:
- List of the spans.
-
nextSpanTransition
Return the next offset afterstart
but less than or equal tolimit
where a span of the specified type begins or ends.- Specified by:
nextSpanTransition
in 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:
subSequence
in 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:
toString
in interfaceCharSequence
- Overrides:
toString
in 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:
setFilters
in interfaceEditable
-
getFilters
Returns the array of input filters that are currently applied to changes to this Editable.- Specified by:
getFilters
in interfaceEditable
-
equals
-
hashCode
public int hashCode()
-