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