You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
refactor source tree organization, switch to meson
This commit is contained in:
5
src/api-impl/android/text/ClipboardManager.java
Normal file
5
src/api-impl/android/text/ClipboardManager.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package android.text;
|
||||
|
||||
public class ClipboardManager {
|
||||
|
||||
}
|
||||
33
src/api-impl/android/text/GetChars.java
Normal file
33
src/api-impl/android/text/GetChars.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
/**
|
||||
* Please implement this interface if your CharSequence has a
|
||||
* getChars() method like the one in String that is faster than
|
||||
* calling charAt() multiple times.
|
||||
*/
|
||||
public interface GetChars
|
||||
extends CharSequence
|
||||
{
|
||||
/**
|
||||
* Exactly like String.getChars(): copy chars <code>start</code>
|
||||
* through <code>end - 1</code> from this CharSequence into <code>dest</code>
|
||||
* beginning at offset <code>destoff</code>.
|
||||
*/
|
||||
public void getChars(int start, int end, char[] dest, int destoff);
|
||||
}
|
||||
7
src/api-impl/android/text/Html.java
Normal file
7
src/api-impl/android/text/Html.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package android.text;
|
||||
|
||||
public class Html {
|
||||
public static Spanned fromHtml(String source) {
|
||||
return new SpannableString(source.replace("<br/>", "\n")); // TODO when JTidy is in use: s/<br \/>//g
|
||||
}
|
||||
}
|
||||
12
src/api-impl/android/text/InputFilter.java
Normal file
12
src/api-impl/android/text/InputFilter.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package android.text;
|
||||
|
||||
public interface InputFilter {
|
||||
public static class LengthFilter extends Object implements InputFilter {
|
||||
public LengthFilter(int max) {
|
||||
}
|
||||
|
||||
public CharSequence filter (CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/api-impl/android/text/NoCopySpan.java
Normal file
31
src/api-impl/android/text/NoCopySpan.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
/**
|
||||
* This interface should be added to a span object that should not be copied
|
||||
* into a new Spenned when performing a slice or copy operation on the original
|
||||
* Spanned it was placed in.
|
||||
*/
|
||||
public interface NoCopySpan {
|
||||
/**
|
||||
* Convenience equivalent for when you would just want a new Object() for
|
||||
* a span but want it to be no-copy. Use this instead.
|
||||
*/
|
||||
public class Concrete implements NoCopySpan {
|
||||
}
|
||||
}
|
||||
42
src/api-impl/android/text/SpanWatcher.java
Normal file
42
src/api-impl/android/text/SpanWatcher.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
/**
|
||||
* When an object of this type is attached to a Spannable, its methods
|
||||
* will be called to notify it that other markup objects have been
|
||||
* added, changed, or removed.
|
||||
*/
|
||||
public interface SpanWatcher extends NoCopySpan {
|
||||
/**
|
||||
* This method is called to notify you that the specified object
|
||||
* has been attached to the specified range of the text.
|
||||
*/
|
||||
public void onSpanAdded(Spannable text, Object what, int start, int end);
|
||||
/**
|
||||
* This method is called to notify you that the specified object
|
||||
* has been detached from the specified range of the text.
|
||||
*/
|
||||
public void onSpanRemoved(Spannable text, Object what, int start, int end);
|
||||
/**
|
||||
* This method is called to notify you that the specified object
|
||||
* has been relocated from the range <code>ostart…oend</code>
|
||||
* to the new range <code>nstart…nend</code> of the text.
|
||||
*/
|
||||
public void onSpanChanged(Spannable text, Object what, int ostart, int oend,
|
||||
int nstart, int nend);
|
||||
}
|
||||
70
src/api-impl/android/text/Spannable.java
Normal file
70
src/api-impl/android/text/Spannable.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
/**
|
||||
* This is the interface for text to which markup objects can be
|
||||
* attached and detached. Not all Spannable classes have mutable text;
|
||||
* see {@link Editable} for that.
|
||||
*/
|
||||
public interface Spannable
|
||||
extends Spanned
|
||||
{
|
||||
/**
|
||||
* Attach the specified markup object to the range <code>start…end</code>
|
||||
* of the text, or move the object to that range if it was already
|
||||
* attached elsewhere. See {@link Spanned} for an explanation of
|
||||
* what the flags mean. The object can be one that has meaning only
|
||||
* within your application, or it can be one that the text system will
|
||||
* use to affect text display or behavior. Some noteworthy ones are
|
||||
* the subclasses of {@link android.text.style.CharacterStyle} and
|
||||
* {@link android.text.style.ParagraphStyle}, and
|
||||
* {@link android.text.TextWatcher} and
|
||||
* {@link android.text.SpanWatcher}.
|
||||
*/
|
||||
public void setSpan(Object what, int start, int end, int flags);
|
||||
|
||||
/**
|
||||
* Remove the specified object from the range of text to which it
|
||||
* was attached, if any. It is OK to remove an object that was never
|
||||
* attached in the first place.
|
||||
*/
|
||||
public void removeSpan(Object what);
|
||||
|
||||
/**
|
||||
* Factory used by TextView to create new Spannables. You can subclass
|
||||
* it to provide something other than SpannableString.
|
||||
*/
|
||||
public static class Factory {
|
||||
private static Spannable.Factory sInstance = new Spannable.Factory();
|
||||
|
||||
/**
|
||||
* Returns the standard Spannable Factory.
|
||||
*/
|
||||
public static Spannable.Factory getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new SpannableString from the specified CharSequence.
|
||||
* You can override this to provide a different kind of Spannable.
|
||||
*/
|
||||
public Spannable newSpannable(CharSequence source) {
|
||||
return new SpannableString(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
56
src/api-impl/android/text/SpannableString.java
Normal file
56
src/api-impl/android/text/SpannableString.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
|
||||
/**
|
||||
* This is the class for text whose content is immutable but to which
|
||||
* markup objects can be attached and detached.
|
||||
* For mutable text, see {@link SpannableStringBuilder}.
|
||||
*/
|
||||
public class SpannableString
|
||||
extends SpannableStringInternal
|
||||
implements CharSequence, GetChars, Spannable
|
||||
{
|
||||
public SpannableString(CharSequence source) {
|
||||
super(source, 0, source.length());
|
||||
}
|
||||
|
||||
private SpannableString(CharSequence source, int start, int end) {
|
||||
super(source, start, end);
|
||||
}
|
||||
|
||||
public static SpannableString valueOf(CharSequence source) {
|
||||
if (source instanceof SpannableString) {
|
||||
return (SpannableString) source;
|
||||
} else {
|
||||
return new SpannableString(source);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpan(Object what, int start, int end, int flags) {
|
||||
super.setSpan(what, start, end, flags);
|
||||
}
|
||||
|
||||
public void removeSpan(Object what) {
|
||||
super.removeSpan(what);
|
||||
}
|
||||
|
||||
public final CharSequence subSequence(int start, int end) {
|
||||
return new SpannableString(this, start, end);
|
||||
}
|
||||
}
|
||||
421
src/api-impl/android/text/SpannableStringInternal.java
Normal file
421
src/api-impl/android/text/SpannableStringInternal.java
Normal file
@@ -0,0 +1,421 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
/* package */ abstract class SpannableStringInternal
|
||||
{
|
||||
/* package */ SpannableStringInternal(CharSequence source,
|
||||
int start, int end) {
|
||||
if (start == 0 && end == source.length())
|
||||
mText = source.toString();
|
||||
else
|
||||
mText = source.toString().substring(start, end);
|
||||
|
||||
int initial = ArrayUtils.idealIntArraySize(0);
|
||||
mSpans = new Object[initial];
|
||||
mSpanData = new int[initial * 3];
|
||||
|
||||
if (source instanceof Spanned) {
|
||||
Spanned sp = (Spanned) source;
|
||||
Object[] spans = sp.getSpans(start, end, Object.class);
|
||||
|
||||
for (int i = 0; i < spans.length; i++) {
|
||||
int st = sp.getSpanStart(spans[i]);
|
||||
int en = sp.getSpanEnd(spans[i]);
|
||||
int fl = sp.getSpanFlags(spans[i]);
|
||||
|
||||
if (st < start)
|
||||
st = start;
|
||||
if (en > end)
|
||||
en = end;
|
||||
|
||||
setSpan(spans[i], st - start, en - start, fl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final int length() {
|
||||
return mText.length();
|
||||
}
|
||||
|
||||
public final char charAt(int i) {
|
||||
return mText.charAt(i);
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return mText;
|
||||
}
|
||||
|
||||
/* subclasses must do subSequence() to preserve type */
|
||||
|
||||
public final void getChars(int start, int end, char[] dest, int off) {
|
||||
mText.getChars(start, end, dest, off);
|
||||
}
|
||||
|
||||
/* package */ void setSpan(Object what, int start, int end, int flags) {
|
||||
int nstart = start;
|
||||
int nend = end;
|
||||
|
||||
checkRange("setSpan", start, end);
|
||||
|
||||
if ((flags & Spannable.SPAN_PARAGRAPH) == Spannable.SPAN_PARAGRAPH) {
|
||||
if (start != 0 && start != length()) {
|
||||
char c = charAt(start - 1);
|
||||
|
||||
if (c != '\n')
|
||||
throw new RuntimeException(
|
||||
"PARAGRAPH span must start at paragraph boundary" +
|
||||
" (" + start + " follows " + c + ")");
|
||||
}
|
||||
|
||||
if (end != 0 && end != length()) {
|
||||
char c = charAt(end - 1);
|
||||
|
||||
if (c != '\n')
|
||||
throw new RuntimeException(
|
||||
"PARAGRAPH span must end at paragraph boundary" +
|
||||
" (" + end + " follows " + c + ")");
|
||||
}
|
||||
}
|
||||
|
||||
int count = mSpanCount;
|
||||
Object[] spans = mSpans;
|
||||
int[] data = mSpanData;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (spans[i] == what) {
|
||||
int ostart = data[i * COLUMNS + START];
|
||||
int oend = data[i * COLUMNS + END];
|
||||
|
||||
data[i * COLUMNS + START] = start;
|
||||
data[i * COLUMNS + END] = end;
|
||||
data[i * COLUMNS + FLAGS] = flags;
|
||||
|
||||
sendSpanChanged(what, ostart, oend, nstart, nend);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mSpanCount + 1 >= mSpans.length) {
|
||||
int newsize = ArrayUtils.idealIntArraySize(mSpanCount + 1);
|
||||
Object[] newtags = new Object[newsize];
|
||||
int[] newdata = new int[newsize * 3];
|
||||
|
||||
System.arraycopy(mSpans, 0, newtags, 0, mSpanCount);
|
||||
System.arraycopy(mSpanData, 0, newdata, 0, mSpanCount * 3);
|
||||
|
||||
mSpans = newtags;
|
||||
mSpanData = newdata;
|
||||
}
|
||||
|
||||
mSpans[mSpanCount] = what;
|
||||
mSpanData[mSpanCount * COLUMNS + START] = start;
|
||||
mSpanData[mSpanCount * COLUMNS + END] = end;
|
||||
mSpanData[mSpanCount * COLUMNS + FLAGS] = flags;
|
||||
mSpanCount++;
|
||||
|
||||
if (this instanceof Spannable)
|
||||
sendSpanAdded(what, nstart, nend);
|
||||
}
|
||||
|
||||
/* package */ void removeSpan(Object what) {
|
||||
int count = mSpanCount;
|
||||
Object[] spans = mSpans;
|
||||
int[] data = mSpanData;
|
||||
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
if (spans[i] == what) {
|
||||
int ostart = data[i * COLUMNS + START];
|
||||
int oend = data[i * COLUMNS + END];
|
||||
|
||||
int c = count - (i + 1);
|
||||
|
||||
System.arraycopy(spans, i + 1, spans, i, c);
|
||||
System.arraycopy(data, (i + 1) * COLUMNS,
|
||||
data, i * COLUMNS, c * COLUMNS);
|
||||
|
||||
mSpanCount--;
|
||||
|
||||
sendSpanRemoved(what, ostart, oend);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getSpanStart(Object what) {
|
||||
int count = mSpanCount;
|
||||
Object[] spans = mSpans;
|
||||
int[] data = mSpanData;
|
||||
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
if (spans[i] == what) {
|
||||
return data[i * COLUMNS + START];
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getSpanEnd(Object what) {
|
||||
int count = mSpanCount;
|
||||
Object[] spans = mSpans;
|
||||
int[] data = mSpanData;
|
||||
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
if (spans[i] == what) {
|
||||
return data[i * COLUMNS + END];
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getSpanFlags(Object what) {
|
||||
int count = mSpanCount;
|
||||
Object[] spans = mSpans;
|
||||
int[] data = mSpanData;
|
||||
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
if (spans[i] == what) {
|
||||
return data[i * COLUMNS + FLAGS];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public <T> T[] getSpans(int queryStart, int queryEnd, Class<T> kind) {
|
||||
int count = 0;
|
||||
|
||||
int spanCount = mSpanCount;
|
||||
Object[] spans = mSpans;
|
||||
int[] data = mSpanData;
|
||||
Object[] ret = null;
|
||||
Object ret1 = null;
|
||||
|
||||
for (int i = 0; i < spanCount; i++) {
|
||||
if (kind != null && !kind.isInstance(spans[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int spanStart = data[i * COLUMNS + START];
|
||||
int spanEnd = data[i * COLUMNS + END];
|
||||
|
||||
if (spanStart > queryEnd) {
|
||||
continue;
|
||||
}
|
||||
if (spanEnd < queryStart) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spanStart != spanEnd && queryStart != queryEnd) {
|
||||
if (spanStart == queryEnd) {
|
||||
continue;
|
||||
}
|
||||
if (spanEnd == queryStart) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
ret1 = spans[i];
|
||||
count++;
|
||||
} else {
|
||||
if (count == 1) {
|
||||
ret = (Object[]) Array.newInstance(kind, spanCount - i + 1);
|
||||
ret[0] = ret1;
|
||||
}
|
||||
|
||||
int prio = data[i * COLUMNS + FLAGS] & Spanned.SPAN_PRIORITY;
|
||||
if (prio != 0) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < count; j++) {
|
||||
int p = getSpanFlags(ret[j]) & Spanned.SPAN_PRIORITY;
|
||||
|
||||
if (prio > p) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.arraycopy(ret, j, ret, j + 1, count - j);
|
||||
ret[j] = spans[i];
|
||||
count++;
|
||||
} else {
|
||||
ret[count++] = spans[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
return (T[]) ArrayUtils.emptyArray(kind);
|
||||
}
|
||||
if (count == 1) {
|
||||
ret = (Object[]) Array.newInstance(kind, 1);
|
||||
ret[0] = ret1;
|
||||
return (T[]) ret;
|
||||
}
|
||||
if (count == ret.length) {
|
||||
return (T[]) ret;
|
||||
}
|
||||
|
||||
Object[] nret = (Object[]) Array.newInstance(kind, count);
|
||||
System.arraycopy(ret, 0, nret, 0, count);
|
||||
return (T[]) nret;
|
||||
}
|
||||
|
||||
public int nextSpanTransition(int start, int limit, Class kind) {
|
||||
int count = mSpanCount;
|
||||
Object[] spans = mSpans;
|
||||
int[] data = mSpanData;
|
||||
|
||||
if (kind == null) {
|
||||
kind = Object.class;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int st = data[i * COLUMNS + START];
|
||||
int en = data[i * COLUMNS + END];
|
||||
|
||||
if (st > start && st < limit && kind.isInstance(spans[i]))
|
||||
limit = st;
|
||||
if (en > start && en < limit && kind.isInstance(spans[i]))
|
||||
limit = en;
|
||||
}
|
||||
|
||||
return limit;
|
||||
}
|
||||
|
||||
private void sendSpanAdded(Object what, int start, int end) {
|
||||
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
|
||||
int n = recip.length;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
recip[i].onSpanAdded((Spannable) this, what, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendSpanRemoved(Object what, int start, int end) {
|
||||
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
|
||||
int n = recip.length;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
recip[i].onSpanRemoved((Spannable) this, what, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendSpanChanged(Object what, int s, int e, int st, int en) {
|
||||
SpanWatcher[] recip = getSpans(Math.min(s, st), Math.max(e, en),
|
||||
SpanWatcher.class);
|
||||
int n = recip.length;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
recip[i].onSpanChanged((Spannable) this, what, s, e, st, en);
|
||||
}
|
||||
}
|
||||
|
||||
private static String region(int start, int end) {
|
||||
return "(" + start + " ... " + end + ")";
|
||||
}
|
||||
|
||||
private void checkRange(final String operation, int start, int end) {
|
||||
if (end < start) {
|
||||
throw new IndexOutOfBoundsException(operation + " " +
|
||||
region(start, end) +
|
||||
" has end before start");
|
||||
}
|
||||
|
||||
int len = length();
|
||||
|
||||
if (start > len || end > len) {
|
||||
throw new IndexOutOfBoundsException(operation + " " +
|
||||
region(start, end) +
|
||||
" ends beyond length " + len);
|
||||
}
|
||||
|
||||
if (start < 0 || end < 0) {
|
||||
throw new IndexOutOfBoundsException(operation + " " +
|
||||
region(start, end) +
|
||||
" starts before 0");
|
||||
}
|
||||
}
|
||||
|
||||
// Same as SpannableStringBuilder
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Spanned &&
|
||||
toString().equals(o.toString())) {
|
||||
Spanned other = (Spanned) o;
|
||||
// Check span data
|
||||
Object[] otherSpans = other.getSpans(0, other.length(), Object.class);
|
||||
if (mSpanCount == otherSpans.length) {
|
||||
for (int i = 0; i < mSpanCount; ++i) {
|
||||
Object thisSpan = mSpans[i];
|
||||
Object otherSpan = otherSpans[i];
|
||||
if (thisSpan == this) {
|
||||
if (other != otherSpan ||
|
||||
getSpanStart(thisSpan) != other.getSpanStart(otherSpan) ||
|
||||
getSpanEnd(thisSpan) != other.getSpanEnd(otherSpan) ||
|
||||
getSpanFlags(thisSpan) != other.getSpanFlags(otherSpan)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!thisSpan.equals(otherSpan) ||
|
||||
getSpanStart(thisSpan) != other.getSpanStart(otherSpan) ||
|
||||
getSpanEnd(thisSpan) != other.getSpanEnd(otherSpan) ||
|
||||
getSpanFlags(thisSpan) != other.getSpanFlags(otherSpan)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Same as SpannableStringBuilder
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = toString().hashCode();
|
||||
hash = hash * 31 + mSpanCount;
|
||||
for (int i = 0; i < mSpanCount; ++i) {
|
||||
Object span = mSpans[i];
|
||||
if (span != this) {
|
||||
hash = hash * 31 + span.hashCode();
|
||||
}
|
||||
hash = hash * 31 + getSpanStart(span);
|
||||
hash = hash * 31 + getSpanEnd(span);
|
||||
hash = hash * 31 + getSpanFlags(span);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
private String mText;
|
||||
private Object[] mSpans;
|
||||
private int[] mSpanData;
|
||||
private int mSpanCount;
|
||||
|
||||
/* package */ static final Object[] EMPTY = new Object[0];
|
||||
|
||||
private static final int START = 0;
|
||||
private static final int END = 1;
|
||||
private static final int FLAGS = 2;
|
||||
private static final int COLUMNS = 3;
|
||||
}
|
||||
198
src/api-impl/android/text/Spanned.java
Normal file
198
src/api-impl/android/text/Spanned.java
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
/**
|
||||
* This is the interface for text that has markup objects attached to
|
||||
* ranges of it. Not all text classes have mutable markup or text;
|
||||
* see {@link Spannable} for mutable markup and {@link Editable} for
|
||||
* mutable text.
|
||||
*/
|
||||
public interface Spanned
|
||||
extends CharSequence
|
||||
{
|
||||
/**
|
||||
* Bitmask of bits that are relevent for controlling point/mark behavior
|
||||
* of spans.
|
||||
*
|
||||
* MARK and POINT are conceptually located <i>between</i> two adjacent characters.
|
||||
* A MARK is "attached" to the character before, while a POINT will stick to the character
|
||||
* after. The insertion cursor is conceptually located between the MARK and the POINT.
|
||||
*
|
||||
* As a result, inserting a new character between a MARK and a POINT will leave the MARK
|
||||
* unchanged, while the POINT will be shifted, now located after the inserted character and
|
||||
* still glued to the same character after it.
|
||||
*
|
||||
* Depending on whether the insertion happens at the beginning or the end of a span, the span
|
||||
* will hence be expanded to <i>include</i> the new character (when the span is using a MARK at
|
||||
* its beginning or a POINT at its end) or it will be <i>excluded</i>.
|
||||
*
|
||||
* Note that <i>before</i> and <i>after</i> here refer to offsets in the String, which are
|
||||
* independent from the visual representation of the text (left-to-right or right-to-left).
|
||||
*/
|
||||
public static final int SPAN_POINT_MARK_MASK = 0x33;
|
||||
|
||||
/**
|
||||
* 0-length spans with type SPAN_MARK_MARK behave like text marks:
|
||||
* they remain at their original offset when text is inserted
|
||||
* at that offset. Conceptually, the text is added after the mark.
|
||||
*/
|
||||
public static final int SPAN_MARK_MARK = 0x11;
|
||||
/**
|
||||
* SPAN_MARK_POINT is a synonym for {@link #SPAN_INCLUSIVE_INCLUSIVE}.
|
||||
*/
|
||||
public static final int SPAN_MARK_POINT = 0x12;
|
||||
/**
|
||||
* SPAN_POINT_MARK is a synonym for {@link #SPAN_EXCLUSIVE_EXCLUSIVE}.
|
||||
*/
|
||||
public static final int SPAN_POINT_MARK = 0x21;
|
||||
|
||||
/**
|
||||
* 0-length spans with type SPAN_POINT_POINT behave like cursors:
|
||||
* they are pushed forward by the length of the insertion when text
|
||||
* is inserted at their offset.
|
||||
* The text is conceptually inserted before the point.
|
||||
*/
|
||||
public static final int SPAN_POINT_POINT = 0x22;
|
||||
|
||||
/**
|
||||
* SPAN_PARAGRAPH behaves like SPAN_INCLUSIVE_EXCLUSIVE
|
||||
* (SPAN_MARK_MARK), except that if either end of the span is
|
||||
* at the end of the buffer, that end behaves like _POINT
|
||||
* instead (so SPAN_INCLUSIVE_INCLUSIVE if it starts in the
|
||||
* middle and ends at the end, or SPAN_EXCLUSIVE_INCLUSIVE
|
||||
* if it both starts and ends at the end).
|
||||
* <p>
|
||||
* Its endpoints must be the start or end of the buffer or
|
||||
* immediately after a \n character, and if the \n
|
||||
* that anchors it is deleted, the endpoint is pulled to the
|
||||
* next \n that follows in the buffer (or to the end of
|
||||
* the buffer).
|
||||
*/
|
||||
public static final int SPAN_PARAGRAPH = 0x33;
|
||||
|
||||
/**
|
||||
* Non-0-length spans of type SPAN_INCLUSIVE_EXCLUSIVE expand
|
||||
* to include text inserted at their starting point but not at their
|
||||
* ending point. When 0-length, they behave like marks.
|
||||
*/
|
||||
public static final int SPAN_INCLUSIVE_EXCLUSIVE = SPAN_MARK_MARK;
|
||||
|
||||
/**
|
||||
* Spans of type SPAN_INCLUSIVE_INCLUSIVE expand
|
||||
* to include text inserted at either their starting or ending point.
|
||||
*/
|
||||
public static final int SPAN_INCLUSIVE_INCLUSIVE = SPAN_MARK_POINT;
|
||||
|
||||
/**
|
||||
* Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand
|
||||
* to include text inserted at either their starting or ending point.
|
||||
* They can never have a length of 0 and are automatically removed
|
||||
* from the buffer if all the text they cover is removed.
|
||||
*/
|
||||
public static final int SPAN_EXCLUSIVE_EXCLUSIVE = SPAN_POINT_MARK;
|
||||
|
||||
/**
|
||||
* Non-0-length spans of type SPAN_EXCLUSIVE_INCLUSIVE expand
|
||||
* to include text inserted at their ending point but not at their
|
||||
* starting point. When 0-length, they behave like points.
|
||||
*/
|
||||
public static final int SPAN_EXCLUSIVE_INCLUSIVE = SPAN_POINT_POINT;
|
||||
|
||||
/**
|
||||
* This flag is set on spans that are being used to apply temporary
|
||||
* styling information on the composing text of an input method, so that
|
||||
* they can be found and removed when the composing text is being
|
||||
* replaced.
|
||||
*/
|
||||
public static final int SPAN_COMPOSING = 0x100;
|
||||
|
||||
/**
|
||||
* This flag will be set for intermediate span changes, meaning there
|
||||
* is guaranteed to be another change following it. Typically it is
|
||||
* used for {@link Selection} which automatically uses this with the first
|
||||
* offset it sets when updating the selection.
|
||||
*/
|
||||
public static final int SPAN_INTERMEDIATE = 0x200;
|
||||
|
||||
/**
|
||||
* The bits numbered SPAN_USER_SHIFT and above are available
|
||||
* for callers to use to store scalar data associated with their
|
||||
* span object.
|
||||
*/
|
||||
public static final int SPAN_USER_SHIFT = 24;
|
||||
/**
|
||||
* The bits specified by the SPAN_USER bitfield are available
|
||||
* for callers to use to store scalar data associated with their
|
||||
* span object.
|
||||
*/
|
||||
public static final int SPAN_USER = 0xFFFFFFFF << SPAN_USER_SHIFT;
|
||||
|
||||
/**
|
||||
* The bits numbered just above SPAN_PRIORITY_SHIFT determine the order
|
||||
* of change notifications -- higher numbers go first. You probably
|
||||
* don't need to set this; it is used so that when text changes, the
|
||||
* text layout gets the chance to update itself before any other
|
||||
* callbacks can inquire about the layout of the text.
|
||||
*/
|
||||
public static final int SPAN_PRIORITY_SHIFT = 16;
|
||||
/**
|
||||
* The bits specified by the SPAN_PRIORITY bitmap determine the order
|
||||
* of change notifications -- higher numbers go first. You probably
|
||||
* don't need to set this; it is used so that when text changes, the
|
||||
* text layout gets the chance to update itself before any other
|
||||
* callbacks can inquire about the layout of the text.
|
||||
*/
|
||||
public static final int SPAN_PRIORITY = 0xFF << SPAN_PRIORITY_SHIFT;
|
||||
|
||||
/**
|
||||
* Return an array of the markup objects attached to the specified
|
||||
* slice of this CharSequence and whose type is the specified type
|
||||
* or a subclass of it. Specify Object.class for the type if you
|
||||
* want all the objects regardless of type.
|
||||
*/
|
||||
public <T> T[] getSpans(int start, int end, Class<T> type);
|
||||
|
||||
/**
|
||||
* Return the beginning of the range of text to which the specified
|
||||
* markup object is attached, or -1 if the object is not attached.
|
||||
*/
|
||||
public int getSpanStart(Object tag);
|
||||
|
||||
/**
|
||||
* Return the end of the range of text to which the specified
|
||||
* markup object is attached, or -1 if the object is not attached.
|
||||
*/
|
||||
public int getSpanEnd(Object tag);
|
||||
|
||||
/**
|
||||
* Return the flags that were specified when {@link Spannable#setSpan} was
|
||||
* used to attach the specified markup object, or 0 if the specified
|
||||
* object has not been attached.
|
||||
*/
|
||||
public int getSpanFlags(Object tag);
|
||||
|
||||
/**
|
||||
* Return the first offset greater than or equal to <code>start</code>
|
||||
* where a markup object of class <code>type</code> begins or ends,
|
||||
* or <code>limit</code> if there are no starts or ends greater than or
|
||||
* equal to <code>start</code> but less than <code>limit</code>. Specify
|
||||
* <code>null</code> or Object.class for the type if you want every
|
||||
* transition regardless of type.
|
||||
*/
|
||||
public int nextSpanTransition(int start, int limit, Class type);
|
||||
}
|
||||
48
src/api-impl/android/text/SpannedString.java
Normal file
48
src/api-impl/android/text/SpannedString.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
|
||||
/**
|
||||
* This is the class for text whose content and markup are immutable.
|
||||
* For mutable markup, see {@link SpannableString}; for mutable text,
|
||||
* see {@link SpannableStringBuilder}.
|
||||
*/
|
||||
public final class SpannedString
|
||||
extends SpannableStringInternal
|
||||
implements CharSequence, GetChars, Spanned
|
||||
{
|
||||
public SpannedString(CharSequence source) {
|
||||
super(source, 0, source.length());
|
||||
}
|
||||
|
||||
private SpannedString(CharSequence source, int start, int end) {
|
||||
super(source, start, end);
|
||||
}
|
||||
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
return new SpannedString(this, start, end);
|
||||
}
|
||||
|
||||
public static SpannedString valueOf(CharSequence source) {
|
||||
if (source instanceof SpannedString) {
|
||||
return (SpannedString) source;
|
||||
} else {
|
||||
return new SpannedString(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
82
src/api-impl/android/text/TextPaint.java
Normal file
82
src/api-impl/android/text/TextPaint.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.text;
|
||||
|
||||
import android.graphics.Paint;
|
||||
|
||||
/**
|
||||
* TextPaint is an extension of Paint that leaves room for some extra
|
||||
* data used during text measuring and drawing.
|
||||
*/
|
||||
public class TextPaint extends Paint {
|
||||
|
||||
// Special value 0 means no background paint
|
||||
public int bgColor;
|
||||
public int baselineShift;
|
||||
public int linkColor;
|
||||
public int[] drawableState;
|
||||
public float density = 1.0f;
|
||||
/**
|
||||
* Special value 0 means no custom underline
|
||||
* @hide
|
||||
*/
|
||||
public int underlineColor = 0;
|
||||
/**
|
||||
* Defined as a multiplier of the default underline thickness. Use 1.0f for default thickness.
|
||||
* @hide
|
||||
*/
|
||||
public float underlineThickness;
|
||||
|
||||
public TextPaint() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TextPaint(int flags) {
|
||||
super(/*flags*/);
|
||||
}
|
||||
|
||||
public TextPaint(Paint p) {
|
||||
super(/*p*/);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the fields from tp into this TextPaint, including the
|
||||
* fields inherited from Paint.
|
||||
*/
|
||||
public void set(TextPaint tp) {
|
||||
// super.set(tp);
|
||||
|
||||
bgColor = tp.bgColor;
|
||||
baselineShift = tp.baselineShift;
|
||||
linkColor = tp.linkColor;
|
||||
drawableState = tp.drawableState;
|
||||
density = tp.density;
|
||||
underlineColor = tp.underlineColor;
|
||||
underlineThickness = tp.underlineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a custom underline for this Paint.
|
||||
* @param color underline solid color
|
||||
* @param thickness underline thickness
|
||||
* @hide
|
||||
*/
|
||||
public void setUnderlineText(int color, float thickness) {
|
||||
underlineColor = color;
|
||||
underlineThickness = thickness;
|
||||
}
|
||||
}
|
||||
64
src/api-impl/android/text/TextUtils.java
Normal file
64
src/api-impl/android/text/TextUtils.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package android.text;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TextUtils {
|
||||
// unchanged from android source
|
||||
|
||||
/* split */
|
||||
|
||||
private static String[] EMPTY_STRING_ARRAY = new String[]{};
|
||||
|
||||
public static String[] split(String text, String expression) {
|
||||
if (text.length() == 0) {
|
||||
return EMPTY_STRING_ARRAY;
|
||||
} else {
|
||||
return text.split(expression, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] split(String text, Pattern pattern) {
|
||||
if (text.length() == 0) {
|
||||
return EMPTY_STRING_ARRAY;
|
||||
} else {
|
||||
return pattern.split(text, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/* join */
|
||||
|
||||
|
||||
public static String join(CharSequence delimiter, Object[] tokens) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean firstTime = true;
|
||||
for (Object token: tokens) {
|
||||
if (firstTime) {
|
||||
firstTime = false;
|
||||
} else {
|
||||
sb.append(delimiter);
|
||||
}
|
||||
sb.append(token);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String join(CharSequence delimiter, Iterable tokens) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean firstTime = true;
|
||||
for (Object token: tokens) {
|
||||
if (firstTime) {
|
||||
firstTime = false;
|
||||
} else {
|
||||
sb.append(delimiter);
|
||||
}
|
||||
sb.append(token);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
// end of unchanged from android source
|
||||
|
||||
public static CharSequence join(Iterable<CharSequence> list) {
|
||||
final CharSequence delimiter = ","; // ????
|
||||
return join(delimiter, list);
|
||||
}
|
||||
}
|
||||
5
src/api-impl/android/text/TextWatcher.java
Normal file
5
src/api-impl/android/text/TextWatcher.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package android.text;
|
||||
|
||||
public interface TextWatcher {
|
||||
|
||||
}
|
||||
9
src/api-impl/android/text/util/Linkify.java
Normal file
9
src/api-impl/android/text/util/Linkify.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package android.text.util;
|
||||
|
||||
import android.text.Spannable;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Linkify {
|
||||
public static final boolean addLinks(Spannable text, int mask) { return true; }
|
||||
public static final boolean addLinks(TextView text, int mask) { return true; }
|
||||
}
|
||||
Reference in New Issue
Block a user