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

Commit 9c8eb722 authored by Willie Koomson's avatar Willie Koomson
Browse files

Write Spanned strings to proto

Adds code to serialize Spanned strings to proto. All the spans that
implement ParcelableSpan are supported.

This is to facilitate serializing RemoteViews actions that contain Spanned
strings.

Test: RemoteViewsSerializersTest
Bug: 345800969
Flag: android.appwidget.flags.remote_views_proto
Change-Id: I4497f5ae10140f58771a7d8f915d994af9eecc0f
parent daa08602
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -156,4 +156,12 @@ public class AccessibilityClickableSpan extends ClickableSpan
                    return new AccessibilityClickableSpan[size];
                }
            };

    /**
     * @return the ID of the original clickable span that this is applied to.
     * @hide
     */
    public int getOriginalClickableSpanId() {
        return mOriginalClickableSpanId;
    }
}
+12 −1
Original line number Diff line number Diff line
@@ -119,7 +119,10 @@ public class BulletSpan implements LeadingMarginSpan, ParcelableSpan {
        this(gapWidth, color, true, bulletRadius);
    }

    private BulletSpan(int gapWidth, @ColorInt int color, boolean wantColor,
    /**
     * @hide
     */
    public BulletSpan(int gapWidth, @ColorInt int color, boolean wantColor,
            @IntRange(from = 0) int bulletRadius) {
        mGapWidth = gapWidth;
        mBulletRadius = bulletRadius;
@@ -199,6 +202,14 @@ public class BulletSpan implements LeadingMarginSpan, ParcelableSpan {
        return mColor;
    }

    /**
     * @return true if the bullet should apply the color.
     * @hide
     */
    public boolean getWantColor() {
        return mWantColor;
    }

    @Override
    public void drawLeadingMargin(@NonNull Canvas canvas, @NonNull Paint paint, int x, int dir,
            int top, int baseline, int bottom,
+74 −13
Original line number Diff line number Diff line
@@ -248,21 +248,42 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
    }

    public SuggestionSpan(Parcel src) {
        mSuggestions = src.readStringArray();
        mFlags = src.readInt();
        mLocaleStringForCompatibility = src.readString();
        mLanguageTag = src.readString();
        mHashCode = src.readInt();
        mEasyCorrectUnderlineColor = src.readInt();
        mEasyCorrectUnderlineThickness = src.readFloat();
        mMisspelledUnderlineColor = src.readInt();
        mMisspelledUnderlineThickness = src.readFloat();
        mAutoCorrectionUnderlineColor = src.readInt();
        mAutoCorrectionUnderlineThickness = src.readFloat();
        mGrammarErrorUnderlineColor = src.readInt();
        mGrammarErrorUnderlineThickness = src.readFloat();
        this(/* suggestions= */ src.readStringArray(), /* flags= */ src.readInt(),
                /* localStringForCompatibility= */ src.readString(),
                /* languageTag= */ src.readString(), /* hashCode= */ src.readInt(),
                /* easyCorrectUnderlineColor= */ src.readInt(),
                /* easyCorrectUnderlineThickness= */ src.readFloat(),
                /* misspelledUnderlineColor= */ src.readInt(),
                /* misspelledUnderlineThickness= */ src.readFloat(),
                /* autoCorrectionUnderlineColor= */ src.readInt(),
                /* autoCorrectionUnderlineThickness= */ src.readFloat(),
                /* grammarErrorUnderlineColor= */ src.readInt(),
                /* grammarErrorUnderlineThickness= */ src.readFloat());
    }

    /** @hide */
    public SuggestionSpan(String[] suggestions, int flags, String localeStringForCompatibility,
            String languageTag, int hashCode, int easyCorrectUnderlineColor,
            float easyCorrectUnderlineThickness, int misspelledUnderlineColor,
            float misspelledUnderlineThickness, int autoCorrectionUnderlineColor,
            float autoCorrectionUnderlineThickness, int grammarErrorUnderlineColor,
            float grammarErrorUnderlineThickness) {
        mSuggestions = suggestions;
        mFlags = flags;
        mLocaleStringForCompatibility = localeStringForCompatibility;
        mLanguageTag = languageTag;
        mHashCode = hashCode;
        mEasyCorrectUnderlineColor = easyCorrectUnderlineColor;
        mEasyCorrectUnderlineThickness = easyCorrectUnderlineThickness;
        mMisspelledUnderlineColor = misspelledUnderlineColor;
        mMisspelledUnderlineThickness = misspelledUnderlineThickness;
        mAutoCorrectionUnderlineColor = autoCorrectionUnderlineColor;
        mAutoCorrectionUnderlineThickness = autoCorrectionUnderlineThickness;
        mGrammarErrorUnderlineColor = grammarErrorUnderlineColor;
        mGrammarErrorUnderlineThickness = grammarErrorUnderlineThickness;
    }


    /**
     * @return an array of suggestion texts for this span
     */
@@ -452,4 +473,44 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
    public void notifySelection(Context context, String original, int index) {
        Log.w(TAG, "notifySelection() is deprecated.  Does nothing.");
    }

    /** @hide */
    public float getEasyCorrectUnderlineThickness() {
        return mEasyCorrectUnderlineThickness;
    }

    /** @hide */
    public int getEasyCorrectUnderlineColor() {
        return mEasyCorrectUnderlineColor;
    }

    /** @hide */
    public float getMisspelledUnderlineThickness() {
        return mMisspelledUnderlineThickness;
    }

    /** @hide */
    public int getMisspelledUnderlineColor() {
        return mMisspelledUnderlineColor;
    }

    /** @hide */
    public float getAutoCorrectionUnderlineThickness() {
        return mAutoCorrectionUnderlineThickness;
    }

    /** @hide */
    public int getAutoCorrectionUnderlineColor() {
        return mAutoCorrectionUnderlineColor;
    }

    /** @hide */
    public float getGrammarErrorUnderlineThickness() {
        return mGrammarErrorUnderlineThickness;
    }

    /** @hide */
    public int getGrammarErrorUnderlineColor() {
        return mGrammarErrorUnderlineColor;
    }
}
+59 −26
Original line number Diff line number Diff line
@@ -233,36 +233,59 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
    }

    public TextAppearanceSpan(Parcel src) {
        mFamilyName = src.readString();
        mStyle = src.readInt();
        mTextSize = src.readInt();
        if (src.readInt() != 0) {
            mTextColor = ColorStateList.CREATOR.createFromParcel(src);
        } else {
            mTextColor = null;
        }
        if (src.readInt() != 0) {
            mTextColorLink = ColorStateList.CREATOR.createFromParcel(src);
        } else {
            mTextColorLink = null;
        this(/* familyName= */ src.readString(),
                /* style= */ src.readInt(),
                /* textSize= */ src.readInt(),
                /* textColor= */ (src.readInt() != 0)
                        ? ColorStateList.CREATOR.createFromParcel(src) : null,
                /* textColorLink= */ (src.readInt() != 0)
                        ? ColorStateList.CREATOR.createFromParcel(src) : null,
                /* typeface= */ LeakyTypefaceStorage.readTypefaceFromParcel(src),
                /* textFontWeight= */ src.readInt(),
                /* textLocales= */
                src.readParcelable(LocaleList.class.getClassLoader(), LocaleList.class),
                /* shadowRadius= */ src.readFloat(),
                /* shadowDx= */ src.readFloat(),
                /* shadowDy= */ src.readFloat(),
                /* shadowColor= */ src.readInt(),
                /* hasElegantTextHeight= */ src.readBoolean(),
                /* elegantTextHeight= */ src.readBoolean(),
                /* hasLetterSpacing= */ src.readBoolean(),
                /* letterSpacing= */ src.readFloat(),
                /* fontFeatureSettings= */ src.readString(),
                /* fontVariationSettings= */ src.readString());
    }
        mTypeface = LeakyTypefaceStorage.readTypefaceFromParcel(src);

        mTextFontWeight = src.readInt();
        mTextLocales = src.readParcelable(LocaleList.class.getClassLoader(), android.os.LocaleList.class);
    /** @hide */
    public TextAppearanceSpan(@Nullable String familyName, int style, int textSize,
            @Nullable ColorStateList textColor, @Nullable ColorStateList textColorLink,
            @Nullable Typeface typeface,
            int textFontWeight, @Nullable LocaleList textLocales, float shadowRadius,
            float shadowDx, float shadowDy, int shadowColor, boolean hasElegantTextHeight,
            boolean elegantTextHeight, boolean hasLetterSpacing, float letterSpacing,
            @Nullable String fontFeatureSettings, @Nullable String fontVariationSettings) {
        mFamilyName = familyName;
        mStyle = style;
        mTextSize = textSize;
        mTextColor = textColor;
        mTextColorLink = textColorLink;
        mTypeface = typeface;

        mTextFontWeight = textFontWeight;
        mTextLocales = textLocales;

        mShadowRadius = src.readFloat();
        mShadowDx = src.readFloat();
        mShadowDy = src.readFloat();
        mShadowColor = src.readInt();
        mShadowRadius = shadowRadius;
        mShadowDx = shadowDx;
        mShadowDy = shadowDy;
        mShadowColor = shadowColor;

        mHasElegantTextHeight = src.readBoolean();
        mElegantTextHeight = src.readBoolean();
        mHasLetterSpacing = src.readBoolean();
        mLetterSpacing = src.readFloat();
        mHasElegantTextHeight = hasElegantTextHeight;
        mElegantTextHeight = elegantTextHeight;
        mHasLetterSpacing = hasLetterSpacing;
        mLetterSpacing = letterSpacing;

        mFontFeatureSettings = src.readString();
        mFontVariationSettings = src.readString();
        mFontFeatureSettings = fontFeatureSettings;
        mFontVariationSettings = fontVariationSettings;
    }

    public int getSpanTypeId() {
@@ -564,4 +587,14 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
                + ", fontVariationSettings='" + getFontVariationSettings() + '\''
                + '}';
    }

    /** @hide */
    public boolean hasElegantTextHeight() {
        return mHasElegantTextHeight;
    }

    /** @hide */
    public boolean hasLetterSpacing() {
        return mHasLetterSpacing;
    }
}
+1340 −11

File changed.

Preview size limit exceeded, changes collapsed.

Loading