The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | /** |
| 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 | */ |
| 24 | public class SpannableString |
| 25 | extends SpannableStringInternal |
| 26 | implements CharSequence, GetChars, Spannable |
| 27 | { |
Seigo Nonaka | 3483bc7 | 2018-03-19 19:02:39 -0700 | [diff] [blame] | 28 | /** |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | public SpannableString(CharSequence source) { |
Seigo Nonaka | 3483bc7 | 2018-03-19 19:02:39 -0700 | [diff] [blame] | 43 | this(source, false /* ignoreNoCopySpan */); // preserve existing NoCopySpan behavior |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | private SpannableString(CharSequence source, int start, int end) { |
Seigo Nonaka | 3483bc7 | 2018-03-19 19:02:39 -0700 | [diff] [blame] | 47 | // preserve existing NoCopySpan behavior |
| 48 | super(source, start, end, false /* ignoreNoCopySpan */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | } |
| 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 | } |