blob: acee3c5f1a41a02b39edc7fa274c3eee4e16a6be [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
19
20/**
21 * This is the class for text whose content and markup are immutable.
22 * For mutable markup, see {@link SpannableString}; for mutable text,
23 * see {@link SpannableStringBuilder}.
24 */
25public final class SpannedString
26extends SpannableStringInternal
27implements CharSequence, GetChars, Spanned
28{
Seigo Nonaka3483bc72018-03-19 19:02:39 -070029 /**
30 * @param source source object to copy from
31 * @param ignoreNoCopySpan whether to copy NoCopySpans in the {@code source}
32 * @hide
33 */
34 public SpannedString(CharSequence source, boolean ignoreNoCopySpan) {
35 super(source, 0, source.length(), ignoreNoCopySpan);
36 }
37
38 /**
39 * For the backward compatibility reasons, this constructor copies all spans including {@link
40 * android.text.NoCopySpan}.
41 * @param source source text
42 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 public SpannedString(CharSequence source) {
Seigo Nonaka3483bc72018-03-19 19:02:39 -070044 this(source, false /* ignoreNoCopySpan */); // preserve existing NoCopySpan behavior
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 }
46
47 private SpannedString(CharSequence source, int start, int end) {
Seigo Nonaka3483bc72018-03-19 19:02:39 -070048 // preserve existing NoCopySpan behavior
49 super(source, start, end, false /* ignoreNoCopySpan */);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 }
51
52 public CharSequence subSequence(int start, int end) {
53 return new SpannedString(this, start, end);
54 }
55
56 public static SpannedString valueOf(CharSequence source) {
57 if (source instanceof SpannedString) {
58 return (SpannedString) source;
59 } else {
60 return new SpannedString(source);
61 }
62 }
63}