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