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 /** 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 */ 25 @android.ravenwood.annotation.RavenwoodKeepWholeClass 26 public final class SpannedString 27 extends SpannableStringInternal 28 implements CharSequence, GetChars, Spanned 29 { 30 /** 31 * @param source source object to copy from 32 * @param ignoreNoCopySpan whether to copy NoCopySpans in the {@code source} 33 * @hide 34 */ SpannedString(CharSequence source, boolean ignoreNoCopySpan)35 public SpannedString(CharSequence source, boolean ignoreNoCopySpan) { 36 super(source, 0, source.length(), ignoreNoCopySpan); 37 } 38 39 /** 40 * For the backward compatibility reasons, this constructor copies all spans including {@link 41 * android.text.NoCopySpan}. 42 * @param source source text 43 */ SpannedString(CharSequence source)44 public SpannedString(CharSequence source) { 45 this(source, false /* ignoreNoCopySpan */); // preserve existing NoCopySpan behavior 46 } 47 SpannedString(CharSequence source, int start, int end)48 private SpannedString(CharSequence source, int start, int end) { 49 // preserve existing NoCopySpan behavior 50 super(source, start, end, false /* ignoreNoCopySpan */); 51 } 52 subSequence(int start, int end)53 public CharSequence subSequence(int start, int end) { 54 return new SpannedString(this, start, end); 55 } 56 valueOf(CharSequence source)57 public static SpannedString valueOf(CharSequence source) { 58 if (source instanceof SpannedString) { 59 return (SpannedString) source; 60 } else { 61 return new SpannedString(source); 62 } 63 } 64 } 65