blob: afb5df809bc032633248c57a3a7673a8574748a1 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019/**
20 * This is the class for text whose content is immutable but to which
21 * markup objects can be attached and detached.
22 * For mutable text, see {@link SpannableStringBuilder}.
23 */
24public class SpannableString
25extends SpannableStringInternal
26implements CharSequence, GetChars, Spannable
27{
Seigo Nonaka3483bc72018-03-19 19:02:39 -070028 /**
29 * @param source source object to copy from
30 * @param ignoreNoCopySpan whether to copy NoCopySpans in the {@code source}
31 * @hide
32 */
33 public SpannableString(CharSequence source, boolean ignoreNoCopySpan) {
34 super(source, 0, source.length(), ignoreNoCopySpan);
35 }
36
37 /**
38 * For the backward compatibility reasons, this constructor copies all spans including {@link
39 * android.text.NoCopySpan}.
40 * @param source source text
41 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 public SpannableString(CharSequence source) {
Seigo Nonaka3483bc72018-03-19 19:02:39 -070043 this(source, false /* ignoreNoCopySpan */); // preserve existing NoCopySpan behavior
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 }
45
46 private SpannableString(CharSequence source, int start, int end) {
Seigo Nonaka3483bc72018-03-19 19:02:39 -070047 // preserve existing NoCopySpan behavior
48 super(source, start, end, false /* ignoreNoCopySpan */);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 }
50
51 public static SpannableString valueOf(CharSequence source) {
52 if (source instanceof SpannableString) {
53 return (SpannableString) source;
54 } else {
55 return new SpannableString(source);
56 }
57 }
58
59 public void setSpan(Object what, int start, int end, int flags) {
60 super.setSpan(what, start, end, flags);
61 }
62
63 public void removeSpan(Object what) {
64 super.removeSpan(what);
65 }
66
67 public final CharSequence subSequence(int start, int end) {
68 return new SpannableString(this, start, end);
69 }
70}