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

Commit 0a04650e authored by Haoyu Zhang's avatar Haoyu Zhang Committed by Android (Google) Code Review
Browse files

Merge "Add textLocale attributes to TextView and TextAppearanceSpan"

parents 4b281d58 1137512f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1403,6 +1403,7 @@ package android {
    field public static final int textFilterEnabled = 16843007; // 0x10100ff
    field public static final int textFontWeight = 16844165; // 0x1010585
    field public static final int textIsSelectable = 16843542; // 0x1010316
    field public static final int textLocale = 16844178; // 0x1010592
    field public static final int textOff = 16843045; // 0x1010125
    field public static final int textOn = 16843044; // 0x1010124
    field public static final int textScaleX = 16843089; // 0x1010151
@@ -45266,6 +45267,7 @@ package android.text.style {
    method public int getSpanTypeId();
    method public android.content.res.ColorStateList getTextColor();
    method public int getTextFontWeight();
    method public android.os.LocaleList getTextLocales();
    method public int getTextSize();
    method public int getTextStyle();
    method public android.graphics.Typeface getTypeface();
+31 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.res.TypedArray;
import android.graphics.LeakyTypefaceStorage;
import android.graphics.Typeface;
import android.graphics.fonts.Font;
import android.os.LocaleList;
import android.os.Parcel;
import android.text.ParcelableSpan;
import android.text.TextPaint;
@@ -66,6 +67,7 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
    private final Typeface mTypeface;

    private final int mTextFontWeight;
    private final LocaleList mTextLocales;

    private final float mShadowRadius;
    private final float mShadowDx;
@@ -149,6 +151,19 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
        mTextFontWeight = a.getInt(com.android.internal.R.styleable
                .TextAppearance_textFontWeight, -1);

        final String localeString = a.getString(com.android.internal.R.styleable
                .TextAppearance_textLocale);
        if (localeString != null) {
            LocaleList localeList = LocaleList.forLanguageTags(localeString);
            if (!localeList.isEmpty()) {
                mTextLocales = localeList;
            } else {
                mTextLocales = null;
            }
        } else {
            mTextLocales = null;
        }

        mShadowRadius = a.getFloat(com.android.internal.R.styleable
                .TextAppearance_shadowRadius, 0.0f);
        mShadowDx = a.getFloat(com.android.internal.R.styleable
@@ -201,6 +216,7 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
        mTypeface = null;

        mTextFontWeight = -1;
        mTextLocales = null;

        mShadowRadius = 0.0f;
        mShadowDx = 0.0f;
@@ -233,6 +249,7 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
        mTypeface = LeakyTypefaceStorage.readTypefaceFromParcel(src);

        mTextFontWeight = src.readInt();
        mTextLocales = src.readParcelable(LocaleList.class.getClassLoader());

        mShadowRadius = src.readFloat();
        mShadowDx = src.readFloat();
@@ -285,6 +302,7 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
        LeakyTypefaceStorage.writeTypefaceToParcel(mTypeface, dest);

        dest.writeInt(mTextFontWeight);
        dest.writeParcelable(mTextLocales, flags);

        dest.writeFloat(mShadowRadius);
        dest.writeFloat(mShadowDx);
@@ -348,6 +366,15 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
        return mTextFontWeight;
    }

    /**
     * Returns the {@link android.os.LocaleList} specified by this span, or <code>null</code>
     * if it does not specify one.
     */
    @Nullable
    public LocaleList getTextLocales() {
        return mTextLocales;
    }

    /**
     * Returns the typeface specified by this span, or <code>null</code>
     * if it does not specify one.
@@ -487,6 +514,10 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
            ds.setTextSize(mTextSize);
        }

        if (mTextLocales != null) {
            ds.setTextLocales(mTextLocales);
        }

        if (mHasElegantTextHeight) {
            ds.setElegantTextHeight(mElegantTextHeight);
        }
+17 −0
Original line number Diff line number Diff line
@@ -3517,6 +3517,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        ColorStateList mTextColorHint = null;
        ColorStateList mTextColorLink = null;
        int mTextSize = -1;
        LocaleList mTextLocales = null;
        String mFontFamily = null;
        Typeface mFontTypeface = null;
        boolean mFontFamilyExplicit = false;
@@ -3543,6 +3544,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    + "    mTextColorHint:" + mTextColorHint + "\n"
                    + "    mTextColorLink:" + mTextColorLink + "\n"
                    + "    mTextSize:" + mTextSize + "\n"
                    + "    mTextLocales:" + mTextLocales + "\n"
                    + "    mFontFamily:" + mFontFamily + "\n"
                    + "    mFontTypeface:" + mFontTypeface + "\n"
                    + "    mFontFamilyExplicit:" + mFontFamilyExplicit + "\n"
@@ -3579,6 +3581,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                com.android.internal.R.styleable.TextAppearance_textColorLink);
        sAppearanceValues.put(com.android.internal.R.styleable.TextView_textSize,
                com.android.internal.R.styleable.TextAppearance_textSize);
        sAppearanceValues.put(com.android.internal.R.styleable.TextView_textLocale,
                com.android.internal.R.styleable.TextAppearance_textLocale);
        sAppearanceValues.put(com.android.internal.R.styleable.TextView_typeface,
                com.android.internal.R.styleable.TextAppearance_typeface);
        sAppearanceValues.put(com.android.internal.R.styleable.TextView_fontFamily,
@@ -3652,6 +3656,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    attributes.mTextSize =
                            appearance.getDimensionPixelSize(attr, attributes.mTextSize);
                    break;
                case com.android.internal.R.styleable.TextAppearance_textLocale:
                    final String localeString = appearance.getString(attr);
                    if (localeString != null) {
                        final LocaleList localeList = LocaleList.forLanguageTags(localeString);
                        if (!localeList.isEmpty()) {
                            attributes.mTextLocales = localeList;
                        }
                    }
                    break;
                case com.android.internal.R.styleable.TextAppearance_typeface:
                    attributes.mTypefaceIndex = appearance.getInt(attr, attributes.mTypefaceIndex);
                    if (attributes.mTypefaceIndex != -1 && !attributes.mFontFamilyExplicit) {
@@ -3738,6 +3751,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            setRawTextSize(attributes.mTextSize, true /* shouldRequestLayout */);
        }

        if (attributes.mTextLocales != null) {
            setTextLocales(attributes.mTextLocales);
        }

        if (attributes.mTypefaceIndex != -1 && !attributes.mFontFamilyExplicit) {
            attributes.mFontFamily = null;
        }
+12 −0
Original line number Diff line number Diff line
@@ -4551,6 +4551,11 @@
        <attr name="typeface" />
        <!-- Font family (named by string or as a font resource reference) for the text. -->
        <attr name="fontFamily" />
        <!-- Specifies the {@link android.os.LocaleList} for the text.
             May be a string value, which is a comma-separated language tag list, such as "ja-JP,zh-CN".
             When not specified or an empty string is given, it will fallback to the default one.
             {@see android.os.LocaleList#forLanguageTags(String)} -->
        <attr name="textLocale" format="string" />
        <!-- Color of the text selection highlight. -->
        <attr name="textColorHighlight" />
        <!-- Color of the hint text. -->
@@ -4642,6 +4647,13 @@
        <attr name="textFontWeight" />
        <!-- Font family (named by string or as a font resource reference) for the text. -->
        <attr name="fontFamily" />
        <!-- Specifies the {@link android.os.LocaleList} for the text in this TextView.
             If not given, the system default will be used.
             May be a string value, which is a comma-separated language tag list, such as "ja-JP,zh-CN".
             When not specified or an empty string is given, it will fallback to the default one.
             {@see android.os.LocaleList#forLanguageTags(String)}
             {@see android.text.TextView#setTextLocales(android.os.LocaleList)} -->
        <attr name="textLocale" format="string" />
        <!-- Text color for links. -->
        <attr name="textColorLink" />
        <!-- Makes the cursor visible (the default) or invisible. -->
+1 −0
Original line number Diff line number Diff line
@@ -2915,6 +2915,7 @@
        <public name="minimumUiTimeout" />
        <public name="isLightTheme" />
        <public name="isSplitRequired" />
        <public name="textLocale" />
    </public-group>

    <public-group type="drawable" first-id="0x010800b4">