Merge "Don't copy NoCopySpans for assist and autofill" into oc-dev

This commit is contained in:
Siyamed Sinir
2017-05-04 00:27:27 +00:00
committed by Android (Google) Code Review
3 changed files with 21 additions and 3 deletions

View File

@@ -1559,14 +1559,14 @@ public class AssistStructure implements Parcelable {
@Override
public void setText(CharSequence text) {
ViewNodeText t = getNodeText();
t.mText = text;
t.mText = TextUtils.trimNoCopySpans(text);
t.mTextSelectionStart = t.mTextSelectionEnd = -1;
}
@Override
public void setText(CharSequence text, int selectionStart, int selectionEnd) {
ViewNodeText t = getNodeText();
t.mText = text;
t.mText = TextUtils.trimNoCopySpans(text);
t.mTextSelectionStart = selectionStart;
t.mTextSelectionEnd = selectionEnd;
}

View File

@@ -1921,6 +1921,22 @@ public class TextUtils {
return false;
}
/**
* If the {@code charSequence} is instance of {@link Spanned}, creates a new copy and
* {@link NoCopySpan}'s are removed from the copy. Otherwise the given {@code charSequence} is
* returned as it is.
*
* @hide
*/
@Nullable
public static CharSequence trimNoCopySpans(@Nullable CharSequence charSequence) {
if (charSequence != null && charSequence instanceof Spanned) {
// SpannableStringBuilder copy constructor trims NoCopySpans.
return new SpannableStringBuilder(charSequence);
}
return charSequence;
}
private static Object sLock = new Object();
private static char[] sTemp = null;

View File

@@ -26,6 +26,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.View;
import com.android.internal.util.Preconditions;
@@ -257,7 +258,8 @@ public final class AutofillValue implements Parcelable {
* <p>See {@link View#AUTOFILL_TYPE_TEXT} for more info.
*/
public static AutofillValue forText(@Nullable CharSequence value) {
return value == null ? null : new AutofillValue(AUTOFILL_TYPE_TEXT, value);
return value == null ? null : new AutofillValue(AUTOFILL_TYPE_TEXT,
TextUtils.trimNoCopySpans(value));
}
/**