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