Merge "Introduce FontStyle.FONT_WEIGHT_UNSPECIFIED constant"
This commit is contained in:
@@ -16597,6 +16597,7 @@ package android.graphics.fonts {
|
||||
field public static final int FONT_WEIGHT_NORMAL = 400; // 0x190
|
||||
field public static final int FONT_WEIGHT_SEMI_BOLD = 600; // 0x258
|
||||
field public static final int FONT_WEIGHT_THIN = 100; // 0x64
|
||||
field public static final int FONT_WEIGHT_UNSPECIFIED = -1; // 0xffffffff
|
||||
}
|
||||
|
||||
public final class FontVariationAxis {
|
||||
|
||||
@@ -149,7 +149,7 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
|
||||
}
|
||||
|
||||
mTextFontWeight = a.getInt(com.android.internal.R.styleable
|
||||
.TextAppearance_textFontWeight, -1);
|
||||
.TextAppearance_textFontWeight, /*defValue*/ FontStyle.FONT_WEIGHT_UNSPECIFIED);
|
||||
|
||||
final String localeString = a.getString(com.android.internal.R.styleable
|
||||
.TextAppearance_textLocale);
|
||||
@@ -215,7 +215,7 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
|
||||
mTextColorLink = linkColor;
|
||||
mTypeface = null;
|
||||
|
||||
mTextFontWeight = -1;
|
||||
mTextFontWeight = FontStyle.FONT_WEIGHT_UNSPECIFIED;
|
||||
mTextLocales = null;
|
||||
|
||||
mShadowRadius = 0.0f;
|
||||
@@ -359,8 +359,8 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text font weight specified by this span, or <code>-1</code>
|
||||
* if it does not specify one.
|
||||
* Returns the text font weight specified by this span, or
|
||||
* <code>FontStyle.FONT_WEIGHT_UNSPECIFIED</code> if it does not specify one.
|
||||
*/
|
||||
public int getTextFontWeight() {
|
||||
return mTextFontWeight;
|
||||
|
||||
@@ -2289,11 +2289,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
* @param familyName family name string, e.g. "serif"
|
||||
* @param typefaceIndex an index of the typeface enum, e.g. SANS, SERIF.
|
||||
* @param style a typeface style
|
||||
* @param weight a weight value for the Typeface or -1 if not specified.
|
||||
* @param weight a weight value for the Typeface or {@code FontStyle.FONT_WEIGHT_UNSPECIFIED}
|
||||
* if not specified.
|
||||
*/
|
||||
private void setTypefaceFromAttrs(@Nullable Typeface typeface, @Nullable String familyName,
|
||||
@XMLTypefaceAttr int typefaceIndex, @Typeface.Style int style,
|
||||
@IntRange(from = -1, to = FontStyle.FONT_WEIGHT_MAX) int weight) {
|
||||
@IntRange(from = FontStyle.FONT_WEIGHT_UNSPECIFIED, to = FontStyle.FONT_WEIGHT_MAX)
|
||||
int weight) {
|
||||
if (typeface == null && familyName != null) {
|
||||
// Lookup normal Typeface from system font map.
|
||||
final Typeface normalTypeface = Typeface.create(familyName, Typeface.NORMAL);
|
||||
@@ -2320,7 +2322,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
}
|
||||
|
||||
private void resolveStyleAndSetTypeface(@NonNull Typeface typeface, @Typeface.Style int style,
|
||||
@IntRange(from = -1, to = FontStyle.FONT_WEIGHT_MAX) int weight) {
|
||||
@IntRange(from = FontStyle.FONT_WEIGHT_UNSPECIFIED, to = FontStyle.FONT_WEIGHT_MAX)
|
||||
int weight) {
|
||||
if (weight >= 0) {
|
||||
weight = Math.min(FontStyle.FONT_WEIGHT_MAX, weight);
|
||||
final boolean italic = (style & Typeface.ITALIC) != 0;
|
||||
@@ -4021,7 +4024,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
boolean mFontFamilyExplicit = false;
|
||||
int mTypefaceIndex = -1;
|
||||
int mTextStyle = 0;
|
||||
int mFontWeight = -1;
|
||||
int mFontWeight = FontStyle.FONT_WEIGHT_UNSPECIFIED;
|
||||
boolean mAllCaps = false;
|
||||
int mShadowColor = 0;
|
||||
float mShadowDx = 0, mShadowDy = 0, mShadowRadius = 0;
|
||||
@@ -6946,18 +6949,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
if (isPassword) {
|
||||
setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||
setTypefaceFromAttrs(null/* fontTypeface */, null /* fontFamily */, MONOSPACE,
|
||||
Typeface.NORMAL, -1 /* weight, not specifeid */);
|
||||
Typeface.NORMAL, FontStyle.FONT_WEIGHT_UNSPECIFIED);
|
||||
} else if (isVisiblePassword) {
|
||||
if (mTransformation == PasswordTransformationMethod.getInstance()) {
|
||||
forceUpdate = true;
|
||||
}
|
||||
setTypefaceFromAttrs(null/* fontTypeface */, null /* fontFamily */, MONOSPACE,
|
||||
Typeface.NORMAL, -1 /* weight, not specified */);
|
||||
Typeface.NORMAL, FontStyle.FONT_WEIGHT_UNSPECIFIED);
|
||||
} else if (wasPassword || wasVisiblePassword) {
|
||||
// not in password mode, clean up typeface and transformation
|
||||
setTypefaceFromAttrs(null/* fontTypeface */, null /* fontFamily */,
|
||||
DEFAULT_TYPEFACE /* typeface index */, Typeface.NORMAL,
|
||||
-1 /* weight, not specified */);
|
||||
FontStyle.FONT_WEIGHT_UNSPECIFIED);
|
||||
if (mTransformation == PasswordTransformationMethod.getInstance()) {
|
||||
forceUpdate = true;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@ import java.util.Objects;
|
||||
public final class FontStyle {
|
||||
private static final String TAG = "FontStyle";
|
||||
|
||||
/**
|
||||
* A default value when font weight is unspecified
|
||||
*/
|
||||
public static final int FONT_WEIGHT_UNSPECIFIED = -1;
|
||||
/**
|
||||
* A minimum weight value for the font
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user