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 public final class SpannedString 26 extends SpannableStringInternal 27 implements CharSequence, GetChars, Spanned 28 { 29 /** 30 * @param source source object to copy from 31 * @param ignoreNoCopySpan whether to copy NoCopySpans in the {@code source} 32 * @hide 33 */ SpannedString(CharSequence source, boolean ignoreNoCopySpan)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 */ SpannedString(CharSequence source)43 public SpannedString(CharSequence source) { 44 this(source, false /* ignoreNoCopySpan */); // preserve existing NoCopySpan behavior 45 } 46 SpannedString(CharSequence source, int start, int end)47 private SpannedString(CharSequence source, int start, int end) { 48 // preserve existing NoCopySpan behavior 49 super(source, start, end, false /* ignoreNoCopySpan */); 50 } 51 subSequence(int start, int end)52 public CharSequence subSequence(int start, int end) { 53 return new SpannedString(this, start, end); 54 } 55 valueOf(CharSequence source)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 } 64