Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd5ca6bf authored by yingleiw's avatar yingleiw
Browse files

Make SuggestionRangeSpan public

when we have overlapped SuggestionSpans, the
range of text being replaced can change depends on
the number of suggestions in the SuggestionSpans, so
accessibility services need to know the text being replaced.
We send text change event with the before text doesn't have the
SuggestionRangeSpan and after text has the SuggestionRangeSpan,
so a11y services can inform the user about the text being
replaced.
Other ui toolkits like compose can convert their style indicating
text being replaced to SuggestionRangeSpan.

Bug: b/143378480

Test: tested the event is sent.

Change-Id: I6d0d33e46f7c8ac9dbcc177ab54718184e715fb6
parent fbfd7340
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -45687,6 +45687,17 @@ package android.text.style {
    method public void writeToParcel(android.os.Parcel, int);
  }
  public final class SuggestionRangeSpan extends android.text.style.CharacterStyle implements android.text.ParcelableSpan {
    ctor public SuggestionRangeSpan();
    method public int describeContents();
    method public int getBackgroundColor();
    method public int getSpanTypeId();
    method public void setBackgroundColor(int);
    method public void updateDrawState(@NonNull android.text.TextPaint);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.text.style.SuggestionRangeSpan> CREATOR;
  }
  public class SuggestionSpan extends android.text.style.CharacterStyle implements android.text.ParcelableSpan {
    ctor public SuggestionSpan(android.content.Context, String[], int);
    ctor public SuggestionSpan(java.util.Locale, String[], int);
+24 −10
Original line number Diff line number Diff line
@@ -16,8 +16,9 @@

package android.text.style;

import android.compat.annotation.UnsupportedAppUsage;
import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.ParcelableSpan;
import android.text.TextPaint;
import android.text.TextUtils;
@@ -25,30 +26,40 @@ import android.text.TextUtils;
/**
 * A SuggestionRangeSpan is used to show which part of an EditText is affected by a suggestion
 * popup window.
 *
 * @hide
 */
public class SuggestionRangeSpan extends CharacterStyle implements ParcelableSpan {
public final class SuggestionRangeSpan extends CharacterStyle implements ParcelableSpan {
    private int mBackgroundColor;

    @UnsupportedAppUsage
    public SuggestionRangeSpan() {
        // 0 is a fully transparent black. Has to be set using #setBackgroundColor
        mBackgroundColor = 0;
    }

    @UnsupportedAppUsage
    public SuggestionRangeSpan(Parcel src) {
    /** @hide */
    public SuggestionRangeSpan(@NonNull Parcel src) {
        mBackgroundColor = src.readInt();
    }

    public static final @NonNull Parcelable.Creator<SuggestionRangeSpan>
            CREATOR = new Parcelable.Creator<SuggestionRangeSpan>() {
                @Override
                public SuggestionRangeSpan createFromParcel(Parcel source) {
                    return new SuggestionRangeSpan(source);
                }

                @Override
                public SuggestionRangeSpan[] newArray(int size) {
                    return new SuggestionRangeSpan[size];
                }
            };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        writeToParcelInternal(dest, flags);
    }

@@ -67,13 +78,16 @@ public class SuggestionRangeSpan extends CharacterStyle implements ParcelableSpa
        return TextUtils.SUGGESTION_RANGE_SPAN;
    }

    @UnsupportedAppUsage
    public void setBackgroundColor(int backgroundColor) {
        mBackgroundColor = backgroundColor;
    }

    public int getBackgroundColor() {
        return mBackgroundColor;
    }

    @Override
    public void updateDrawState(TextPaint tp) {
    public void updateDrawState(@NonNull TextPaint tp) {
        tp.bgColor = mBackgroundColor;
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import android.text.SpanWatcher;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.StaticLayout;
import android.text.TextUtils;
import android.text.method.KeyListener;
@@ -4120,8 +4121,15 @@ public class Editor {
                mSuggestionRangeSpan.setBackgroundColor(
                        (underlineColor & 0x00FFFFFF) + (newAlpha << 24));
            }
            boolean sendAccessibilityEvent = mTextView.isVisibleToAccessibility();
            CharSequence beforeText = sendAccessibilityEvent
                    ? new SpannedString(spannable, true) : null;
            spannable.setSpan(mSuggestionRangeSpan, spanUnionStart, spanUnionEnd,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            if (sendAccessibilityEvent) {
                mTextView.sendAccessibilityEventTypeViewTextChanged(
                        beforeText, spanUnionStart, spanUnionEnd);
            }

            mSuggestionsAdapter.notifyDataSetChanged();
            return true;