Merge "Add textLocale attributes to TextView and TextAppearanceSpan"
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user