• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package 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  */
25 @android.ravenwood.annotation.RavenwoodKeepWholeClass
26 public interface Spanned
27 extends CharSequence
28 {
29     /**
30      * Bitmask of bits that are relevent for controlling point/mark behavior
31      * of spans.
32      *
33      * MARK and POINT are conceptually located <i>between</i> two adjacent characters.
34      * A MARK is "attached" to the character before, while a POINT will stick to the character
35      * after. The insertion cursor is conceptually located between the MARK and the POINT.
36      *
37      * As a result, inserting a new character between a MARK and a POINT will leave the MARK
38      * unchanged, while the POINT will be shifted, now located after the inserted character and
39      * still glued to the same character after it.
40      *
41      * Depending on whether the insertion happens at the beginning or the end of a span, the span
42      * will hence be expanded to <i>include</i> the new character (when the span is using a MARK at
43      * its beginning or a POINT at its end) or it will be <i>excluded</i>.
44      *
45      * Note that <i>before</i> and <i>after</i> here refer to offsets in the String, which are
46      * independent from the visual representation of the text (left-to-right or right-to-left).
47      */
48     public static final int SPAN_POINT_MARK_MASK = 0x33;
49 
50     /**
51      * 0-length spans with type SPAN_MARK_MARK behave like text marks:
52      * they remain at their original offset when text is inserted
53      * at that offset. Conceptually, the text is added after the mark.
54      */
55     public static final int SPAN_MARK_MARK =   0x11;
56     /**
57      * SPAN_MARK_POINT is a synonym for {@link #SPAN_INCLUSIVE_INCLUSIVE}.
58      */
59     public static final int SPAN_MARK_POINT =  0x12;
60     /**
61      * SPAN_POINT_MARK is a synonym for {@link #SPAN_EXCLUSIVE_EXCLUSIVE}.
62      */
63     public static final int SPAN_POINT_MARK =  0x21;
64 
65     /**
66      * 0-length spans with type SPAN_POINT_POINT behave like cursors:
67      * they are pushed forward by the length of the insertion when text
68      * is inserted at their offset.
69      * The text is conceptually inserted before the point.
70      */
71     public static final int SPAN_POINT_POINT = 0x22;
72 
73     /**
74      * SPAN_PARAGRAPH behaves like SPAN_INCLUSIVE_EXCLUSIVE
75      * (SPAN_MARK_MARK), except that if either end of the span is
76      * at the end of the buffer, that end behaves like _POINT
77      * instead (so SPAN_INCLUSIVE_INCLUSIVE if it starts in the
78      * middle and ends at the end, or SPAN_EXCLUSIVE_INCLUSIVE
79      * if it both starts and ends at the end).
80      * <p>
81      * Its endpoints must be the start or end of the buffer or
82      * immediately after a \n character, and if the \n
83      * that anchors it is deleted, the endpoint is pulled to the
84      * next \n that follows in the buffer (or to the end of
85      * the buffer). If a span with SPAN_PARAGRAPH flag is pasted
86      * into another text and the paragraph boundary constraint
87      * is not satisfied, the span is discarded.
88      */
89     public static final int SPAN_PARAGRAPH =   0x33;
90 
91     /**
92      * Non-0-length spans of type SPAN_INCLUSIVE_EXCLUSIVE expand
93      * to include text inserted at their starting point but not at their
94      * ending point.  When 0-length, they behave like marks.
95      */
96     public static final int SPAN_INCLUSIVE_EXCLUSIVE = SPAN_MARK_MARK;
97 
98     /**
99      * Spans of type SPAN_INCLUSIVE_INCLUSIVE expand
100      * to include text inserted at either their starting or ending point.
101      */
102     public static final int SPAN_INCLUSIVE_INCLUSIVE = SPAN_MARK_POINT;
103 
104     /**
105      * Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand
106      * to include text inserted at either their starting or ending point.
107      * They can never have a length of 0 and are automatically removed
108      * from the buffer if all the text they cover is removed.
109      */
110     public static final int SPAN_EXCLUSIVE_EXCLUSIVE = SPAN_POINT_MARK;
111 
112     /**
113      * Non-0-length spans of type SPAN_EXCLUSIVE_INCLUSIVE expand
114      * to include text inserted at their ending point but not at their
115      * starting point.  When 0-length, they behave like points.
116      */
117     public static final int SPAN_EXCLUSIVE_INCLUSIVE = SPAN_POINT_POINT;
118 
119     /**
120      * This flag is set on spans that are being used to apply temporary
121      * styling information on the composing text of an input method, so that
122      * they can be found and removed when the composing text is being
123      * replaced.
124      */
125     public static final int SPAN_COMPOSING = 0x100;
126 
127     /**
128      * This flag will be set for intermediate span changes, meaning there
129      * is guaranteed to be another change following it.  Typically it is
130      * used for {@link Selection} which automatically uses this with the first
131      * offset it sets when updating the selection.
132      */
133     public static final int SPAN_INTERMEDIATE = 0x200;
134 
135     /**
136      * The bits numbered SPAN_USER_SHIFT and above are available
137      * for callers to use to store scalar data associated with their
138      * span object.
139      */
140     public static final int SPAN_USER_SHIFT = 24;
141     /**
142      * The bits specified by the SPAN_USER bitfield are available
143      * for callers to use to store scalar data associated with their
144      * span object.
145      */
146     public static final int SPAN_USER = 0xFFFFFFFF << SPAN_USER_SHIFT;
147 
148     /**
149      * The bits numbered just above SPAN_PRIORITY_SHIFT determine the order
150      * of change notifications -- higher numbers go first.  You probably
151      * don't need to set this; it is used so that when text changes, the
152      * text layout gets the chance to update itself before any other
153      * callbacks can inquire about the layout of the text.
154      */
155     public static final int SPAN_PRIORITY_SHIFT = 16;
156     /**
157      * The bits specified by the SPAN_PRIORITY bitmap determine the order
158      * of change notifications -- higher numbers go first.  You probably
159      * don't need to set this; it is used so that when text changes, the
160      * text layout gets the chance to update itself before any other
161      * callbacks can inquire about the layout of the text.
162      */
163     public static final int SPAN_PRIORITY = 0xFF << SPAN_PRIORITY_SHIFT;
164 
165     /**
166      * Return an array of the markup objects attached to the specified
167      * slice of this CharSequence and whose type is the specified type
168      * or a subclass of it.  Specify Object.class for the type if you
169      * want all the objects regardless of type.
170      */
getSpans(int start, int end, Class<T> type)171     public <T> T[] getSpans(int start, int end, Class<T> type);
172 
173     /**
174      * Return the beginning of the range of text to which the specified
175      * markup object is attached, or -1 if the object is not attached.
176      */
getSpanStart(Object tag)177     public int getSpanStart(Object tag);
178 
179     /**
180      * Return the end of the range of text to which the specified
181      * markup object is attached, or -1 if the object is not attached.
182      */
getSpanEnd(Object tag)183     public int getSpanEnd(Object tag);
184 
185     /**
186      * Return the flags that were specified when {@link Spannable#setSpan} was
187      * used to attach the specified markup object, or 0 if the specified
188      * object has not been attached.
189      */
getSpanFlags(Object tag)190     public int getSpanFlags(Object tag);
191 
192     /**
193      * Return the first offset greater than <code>start</code> where a markup
194      * object of class <code>type</code> begins or ends, or <code>limit</code>
195      * if there are no starts or ends greater than <code>start</code> but less
196      * than <code>limit</code>. Specify <code>null</code> or Object.class for
197      * the type if you want every transition regardless of type.
198      */
nextSpanTransition(int start, int limit, Class type)199     public int nextSpanTransition(int start, int limit, Class type);
200 }
201