• 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 to which markup objects can be
21  * attached and detached.  Not all Spannable classes have mutable text;
22  * see {@link Editable} for that.
23  */
24 @android.ravenwood.annotation.RavenwoodKeepWholeClass
25 public interface Spannable
26 extends Spanned
27 {
28     /**
29      * Attach the specified markup object to the range <code>start&hellip;end</code>
30      * of the text, or move the object to that range if it was already
31      * attached elsewhere.  See {@link Spanned} for an explanation of
32      * what the flags mean.  The object can be one that has meaning only
33      * within your application, or it can be one that the text system will
34      * use to affect text display or behavior.  Some noteworthy ones are
35      * the subclasses of {@link android.text.style.CharacterStyle} and
36      * {@link android.text.style.ParagraphStyle}, and
37      * {@link android.text.TextWatcher} and
38      * {@link android.text.SpanWatcher}.
39      */
setSpan(Object what, int start, int end, int flags)40     public void setSpan(Object what, int start, int end, int flags);
41 
42     /**
43      * Remove the specified object from the range of text to which it
44      * was attached, if any.  It is OK to remove an object that was never
45      * attached in the first place.
46      */
removeSpan(Object what)47     public void removeSpan(Object what);
48 
49     /**
50      * Remove the specified object from the range of text to which it
51      * was attached, if any.  It is OK to remove an object that was never
52      * attached in the first place.
53      *
54      * See {@link Spanned} for an explanation of what the flags mean.
55      *
56      * @hide
57      */
removeSpan(Object what, int flags)58     default void removeSpan(Object what, int flags) {
59         removeSpan(what);
60     }
61 
62     /**
63      * Factory used by TextView to create new {@link Spannable Spannables}. You can subclass
64      * it to provide something other than {@link SpannableString}.
65      *
66      * @see android.widget.TextView#setSpannableFactory(Factory)
67      */
68     public static class Factory {
69         private static Spannable.Factory sInstance = new Spannable.Factory();
70 
71         /**
72          * Returns the standard Spannable Factory.
73          */
getInstance()74         public static Spannable.Factory getInstance() {
75             return sInstance;
76         }
77 
78         /**
79          * Returns a new SpannableString from the specified CharSequence.
80          * You can override this to provide a different kind of Spannable.
81          */
newSpannable(CharSequence source)82         public Spannable newSpannable(CharSequence source) {
83             return new SpannableString(source);
84         }
85     }
86 }
87