| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.text; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
@Deprecated |
| 27 |
public class AlteredCharSequence |
| 28 |
implements CharSequence, GetChars |
| 29 |
{ |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public static AlteredCharSequence make(CharSequence source, char[] sub, |
| 37 |
int substart, int subend) { |
| 38 |
if (source instanceof Spanned) |
| 39 |
return new AlteredSpanned(source, sub, substart, subend); |
| 40 |
else |
| 41 |
return new AlteredCharSequence(source, sub, substart, subend); |
| 42 |
} |
| 43 |
|
| 44 |
private AlteredCharSequence(CharSequence source, char[] sub, |
| 45 |
int substart, int subend) { |
| 46 |
mSource = source; |
| 47 |
mChars = sub; |
| 48 |
mStart = substart; |
| 49 |
mEnd = subend; |
| 50 |
} |
| 51 |
|
| 52 |
void update(char[] sub, int substart, int subend) { |
| 53 |
mChars = sub; |
| 54 |
mStart = substart; |
| 55 |
mEnd = subend; |
| 56 |
} |
| 57 |
|
| 58 |
private static class AlteredSpanned |
| 59 |
extends AlteredCharSequence |
| 60 |
implements Spanned |
| 61 |
{ |
| 62 |
private AlteredSpanned(CharSequence source, char[] sub, |
| 63 |
int substart, int subend) { |
| 64 |
super(source, sub, substart, subend); |
| 65 |
mSpanned = (Spanned) source; |
| 66 |
} |
| 67 |
|
| 68 |
public <T> T[] getSpans(int start, int end, Class<T> kind) { |
| 69 |
return mSpanned.getSpans(start, end, kind); |
| 70 |
} |
| 71 |
|
| 72 |
public int getSpanStart(Object span) { |
| 73 |
return mSpanned.getSpanStart(span); |
| 74 |
} |
| 75 |
|
| 76 |
public int getSpanEnd(Object span) { |
| 77 |
return mSpanned.getSpanEnd(span); |
| 78 |
} |
| 79 |
|
| 80 |
public int getSpanFlags(Object span) { |
| 81 |
return mSpanned.getSpanFlags(span); |
| 82 |
} |
| 83 |
|
| 84 |
public int nextSpanTransition(int start, int end, Class kind) { |
| 85 |
return mSpanned.nextSpanTransition(start, end, kind); |
| 86 |
} |
| 87 |
|
| 88 |
private Spanned mSpanned; |
| 89 |
} |
| 90 |
|
| 91 |
public char charAt(int off) { |
| 92 |
if (off >= mStart && off < mEnd) |
| 93 |
return mChars[off - mStart]; |
| 94 |
else |
| 95 |
return mSource.charAt(off); |
| 96 |
} |
| 97 |
|
| 98 |
public int length() { |
| 99 |
return mSource.length(); |
| 100 |
} |
| 101 |
|
| 102 |
public CharSequence subSequence(int start, int end) { |
| 103 |
return AlteredCharSequence.make(mSource.subSequence(start, end), |
| 104 |
mChars, mStart - start, mEnd - start); |
| 105 |
} |
| 106 |
|
| 107 |
public void getChars(int start, int end, char[] dest, int off) { |
| 108 |
TextUtils.getChars(mSource, start, end, dest, off); |
| 109 |
|
| 110 |
start = Math.max(mStart, start); |
| 111 |
end = Math.min(mEnd, end); |
| 112 |
|
| 113 |
if (start > end) |
| 114 |
System.arraycopy(mChars, start - mStart, dest, off, end - start); |
| 115 |
} |
| 116 |
|
| 117 |
public String toString() { |
| 118 |
int len = length(); |
| 119 |
|
| 120 |
char[] ret = new char[len]; |
| 121 |
getChars(0, len, ret, 0); |
| 122 |
return String.valueOf(ret); |
| 123 |
} |
| 124 |
|
| 125 |
private int mStart; |
| 126 |
private int mEnd; |
| 127 |
private char[] mChars; |
| 128 |
private CharSequence mSource; |
| 129 |
} |