blob: a0d54c26c6d9de6a897f6bc41e6e4dda94e1e4c7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.text;
18
19/**
20 * This is the interface for text that has markup objects attached to
21 * ranges of it. Not all text classes have mutable markup or text;
22 * see {@link Spannable} for mutable markup and {@link Editable} for
23 * mutable text.
24 */
25public interface Spanned
26extends CharSequence
27{
28 /**
29 * Bitmask of bits that are relevent for controlling point/mark behavior
30 * of spans.
Gilles Debunne26b62d42012-04-26 18:46:19 -070031 *
32 * MARK and POINT are conceptually located <i>between</i> two adjacent characters.
Gilles Debunnedd0c25c2012-06-26 15:00:00 -070033 * A MARK is "attached" to the character before, while a POINT will stick to the character
34 * after. The insertion cursor is conceptually located between the MARK and the POINT.
35 *
36 * As a result, inserting a new character between a MARK and a POINT will leave the MARK
37 * unchanged, while the POINT will be shifted, now located after the inserted character and
38 * still glued to the same character after it.
39 *
40 * Depending on whether the insertion happens at the beginning or the end of a span, the span
41 * will hence be expanded to <i>include</i> the new character (when the span is using a MARK at
42 * its beginning or a POINT at its end) or it will be <i>excluded</i>.
43 *
44 * Note that <i>before</i> and <i>after</i> here refer to offsets in the String, which are
45 * independent from the visual representation of the text (left-to-right or right-to-left).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 */
47 public static final int SPAN_POINT_MARK_MASK = 0x33;
48
49 /**
50 * 0-length spans with type SPAN_MARK_MARK behave like text marks:
51 * they remain at their original offset when text is inserted
Gilles Debunne26b62d42012-04-26 18:46:19 -070052 * at that offset. Conceptually, the text is added after the mark.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 */
54 public static final int SPAN_MARK_MARK = 0x11;
55 /**
56 * SPAN_MARK_POINT is a synonym for {@link #SPAN_INCLUSIVE_INCLUSIVE}.
57 */
58 public static final int SPAN_MARK_POINT = 0x12;
59 /**
60 * SPAN_POINT_MARK is a synonym for {@link #SPAN_EXCLUSIVE_EXCLUSIVE}.
61 */
62 public static final int SPAN_POINT_MARK = 0x21;
63
64 /**
65 * 0-length spans with type SPAN_POINT_POINT behave like cursors:
66 * they are pushed forward by the length of the insertion when text
67 * is inserted at their offset.
Gilles Debunne26b62d42012-04-26 18:46:19 -070068 * The text is conceptually inserted before the point.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 */
70 public static final int SPAN_POINT_POINT = 0x22;
71
72 /**
73 * SPAN_PARAGRAPH behaves like SPAN_INCLUSIVE_EXCLUSIVE
74 * (SPAN_MARK_MARK), except that if either end of the span is
75 * at the end of the buffer, that end behaves like _POINT
76 * instead (so SPAN_INCLUSIVE_INCLUSIVE if it starts in the
77 * middle and ends at the end, or SPAN_EXCLUSIVE_INCLUSIVE
78 * if it both starts and ends at the end).
79 * <p>
80 * Its endpoints must be the start or end of the buffer or
81 * immediately after a \n character, and if the \n
82 * that anchors it is deleted, the endpoint is pulled to the
83 * next \n that follows in the buffer (or to the end of
Siyamed Sinir3463c042016-01-06 13:02:59 -080084 * the buffer). If a span with SPAN_PARAGRAPH flag is pasted
85 * into another text and the paragraph boundary constraint
86 * is not satisfied, the span is discarded.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 */
88 public static final int SPAN_PARAGRAPH = 0x33;
89
90 /**
91 * Non-0-length spans of type SPAN_INCLUSIVE_EXCLUSIVE expand
92 * to include text inserted at their starting point but not at their
93 * ending point. When 0-length, they behave like marks.
94 */
95 public static final int SPAN_INCLUSIVE_EXCLUSIVE = SPAN_MARK_MARK;
96
97 /**
98 * Spans of type SPAN_INCLUSIVE_INCLUSIVE expand
99 * to include text inserted at either their starting or ending point.
100 */
101 public static final int SPAN_INCLUSIVE_INCLUSIVE = SPAN_MARK_POINT;
102
103 /**
104 * Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand
105 * to include text inserted at either their starting or ending point.
106 * They can never have a length of 0 and are automatically removed
107 * from the buffer if all the text they cover is removed.
108 */
109 public static final int SPAN_EXCLUSIVE_EXCLUSIVE = SPAN_POINT_MARK;
110
111 /**
Seth Pensack-Rinehartb7332c72010-05-10 17:32:46 +0900112 * Non-0-length spans of type SPAN_EXCLUSIVE_INCLUSIVE expand
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 * to include text inserted at their ending point but not at their
114 * starting point. When 0-length, they behave like points.
115 */
116 public static final int SPAN_EXCLUSIVE_INCLUSIVE = SPAN_POINT_POINT;
117
118 /**
119 * This flag is set on spans that are being used to apply temporary
120 * styling information on the composing text of an input method, so that
121 * they can be found and removed when the composing text is being
122 * replaced.
123 */
124 public static final int SPAN_COMPOSING = 0x100;
125
126 /**
127 * This flag will be set for intermediate span changes, meaning there
128 * is guaranteed to be another change following it. Typically it is
129 * used for {@link Selection} which automatically uses this with the first
130 * offset it sets when updating the selection.
131 */
132 public static final int SPAN_INTERMEDIATE = 0x200;
133
134 /**
135 * The bits numbered SPAN_USER_SHIFT and above are available
136 * for callers to use to store scalar data associated with their
137 * span object.
138 */
139 public static final int SPAN_USER_SHIFT = 24;
140 /**
141 * The bits specified by the SPAN_USER bitfield are available
142 * for callers to use to store scalar data associated with their
143 * span object.
144 */
145 public static final int SPAN_USER = 0xFFFFFFFF << SPAN_USER_SHIFT;
146
147 /**
148 * The bits numbered just above SPAN_PRIORITY_SHIFT determine the order
149 * of change notifications -- higher numbers go first. You probably
150 * don't need to set this; it is used so that when text changes, the
151 * text layout gets the chance to update itself before any other
152 * callbacks can inquire about the layout of the text.
153 */
154 public static final int SPAN_PRIORITY_SHIFT = 16;
155 /**
156 * The bits specified by the SPAN_PRIORITY bitmap determine the order
157 * of change notifications -- higher numbers go first. You probably
158 * don't need to set this; it is used so that when text changes, the
159 * text layout gets the chance to update itself before any other
160 * callbacks can inquire about the layout of the text.
161 */
162 public static final int SPAN_PRIORITY = 0xFF << SPAN_PRIORITY_SHIFT;
163
164 /**
165 * Return an array of the markup objects attached to the specified
166 * slice of this CharSequence and whose type is the specified type
167 * or a subclass of it. Specify Object.class for the type if you
168 * want all the objects regardless of type.
169 */
170 public <T> T[] getSpans(int start, int end, Class<T> type);
171
172 /**
173 * Return the beginning of the range of text to which the specified
174 * markup object is attached, or -1 if the object is not attached.
175 */
176 public int getSpanStart(Object tag);
177
178 /**
179 * Return the end of the range of text to which the specified
180 * markup object is attached, or -1 if the object is not attached.
181 */
182 public int getSpanEnd(Object tag);
183
184 /**
185 * Return the flags that were specified when {@link Spannable#setSpan} was
186 * used to attach the specified markup object, or 0 if the specified
187 * object has not been attached.
188 */
189 public int getSpanFlags(Object tag);
190
191 /**
Raph Levien7d627eb2015-06-10 15:19:50 -0700192 * Return the first offset greater than <code>start</code> where a markup
193 * object of class <code>type</code> begins or ends, or <code>limit</code>
194 * if there are no starts or ends greater than <code>start</code> but less
195 * than <code>limit</code>. Specify <code>null</code> or Object.class for
196 * the type if you want every transition regardless of type.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 */
198 public int nextSpanTransition(int start, int limit, Class type);
199}