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 * 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 @android.ravenwood.annotation.RavenwoodKeepWholeClass 25 public class SpannableString 26 extends SpannableStringInternal 27 implements CharSequence, GetChars, Spannable 28 { 29 /** 30 * @param source source object to copy from 31 * @param ignoreNoCopySpan whether to copy NoCopySpans in the {@code source} 32 * @hide 33 */ SpannableString(CharSequence source, boolean ignoreNoCopySpan)34 public SpannableString(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 */ SpannableString(CharSequence source)43 public SpannableString(CharSequence source) { 44 this(source, false /* ignoreNoCopySpan */); // preserve existing NoCopySpan behavior 45 } 46 SpannableString(CharSequence source, int start, int end)47 private SpannableString(CharSequence source, int start, int end) { 48 // preserve existing NoCopySpan behavior 49 super(source, start, end, false /* ignoreNoCopySpan */); 50 } 51 valueOf(CharSequence source)52 public static SpannableString valueOf(CharSequence source) { 53 if (source instanceof SpannableString) { 54 return (SpannableString) source; 55 } else { 56 return new SpannableString(source); 57 } 58 } 59 setSpan(Object what, int start, int end, int flags)60 public void setSpan(Object what, int start, int end, int flags) { 61 super.setSpan(what, start, end, flags); 62 } 63 removeSpan(Object what)64 public void removeSpan(Object what) { 65 super.removeSpan(what); 66 } 67 subSequence(int start, int end)68 public final CharSequence subSequence(int start, int end) { 69 return new SpannableString(this, start, end); 70 } 71 } 72