Move maximum weight constant from Typeface to Font and make it public
Now we have Font class. It is good to move max weight constant from
Typeface to Font.
Bug: 112327179
Test: atest FontTest
Change-Id: I3946ac150a02bf0cafa0fc81e61e69c31b45ed1d
diff --git a/api/current.txt b/api/current.txt
index 6051a26..4ff3d6b 100755
--- a/api/current.txt
+++ b/api/current.txt
@@ -15229,7 +15229,9 @@
field public static final int FONT_WEIGHT_EXTRA_BOLD = 800; // 0x320
field public static final int FONT_WEIGHT_EXTRA_LIGHT = 200; // 0xc8
field public static final int FONT_WEIGHT_LIGHT = 300; // 0x12c
+ field public static final int FONT_WEIGHT_MAX = 1000; // 0x3e8
field public static final int FONT_WEIGHT_MEDIUM = 500; // 0x1f4
+ field public static final int FONT_WEIGHT_MIN = 1; // 0x1
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
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 1b412a7..0645a16 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -63,6 +63,7 @@
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
+import android.graphics.fonts.Font;
import android.graphics.fonts.FontVariationAxis;
import android.icu.text.DecimalFormatSymbols;
import android.os.AsyncTask;
@@ -2068,7 +2069,7 @@
*/
private void setTypefaceFromAttrs(@Nullable Typeface typeface, @Nullable String familyName,
@XMLTypefaceAttr int typefaceIndex, @Typeface.Style int style,
- @IntRange(from = -1, to = Typeface.MAX_WEIGHT) int weight) {
+ @IntRange(from = -1, to = Font.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);
@@ -2095,9 +2096,9 @@
}
private void resolveStyleAndSetTypeface(@NonNull Typeface typeface, @Typeface.Style int style,
- @IntRange(from = -1, to = Typeface.MAX_WEIGHT) int weight) {
+ @IntRange(from = -1, to = Font.FONT_WEIGHT_MAX) int weight) {
if (weight >= 0) {
- weight = Math.min(Typeface.MAX_WEIGHT, weight);
+ weight = Math.min(Font.FONT_WEIGHT_MAX, weight);
final boolean italic = (style & Typeface.ITALIC) != 0;
setTypeface(Typeface.create(typeface, weight, italic));
} else {
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index 5280642..ed8824f 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -148,13 +148,7 @@
@UnsupportedAppUsage
private @Style int mStyle = 0;
- /**
- * A maximum value for the weight value.
- * @hide
- */
- public static final int MAX_WEIGHT = 1000;
-
- private @IntRange(from = 0, to = MAX_WEIGHT) int mWeight = 0;
+ private @IntRange(from = 0, to = android.graphics.fonts.Font.FONT_WEIGHT_MAX) int mWeight = 0;
// Value for weight and italic. Indicates the value is resolved by font metadata.
// Must be the same as the C++ constant in core/jni/android/graphics/FontFamily.cpp
diff --git a/graphics/java/android/graphics/fonts/Font.java b/graphics/java/android/graphics/fonts/Font.java
index a99d297..8aa4845 100644
--- a/graphics/java/android/graphics/fonts/Font.java
+++ b/graphics/java/android/graphics/fonts/Font.java
@@ -51,6 +51,11 @@
private static final int STYLE_NORMAL = 0;
/**
+ * A minimum weight value for the font
+ */
+ public static final int FONT_WEIGHT_MIN = 1;
+
+ /**
* A font weight value for the thin weight
*/
public static final int FONT_WEIGHT_THIN = 100;
@@ -96,6 +101,11 @@
public static final int FONT_WEIGHT_BLACK = 900;
/**
+ * A maximum weight value for the font
+ */
+ public static final int FONT_WEIGHT_MAX = 1000;
+
+ /**
* A builder class for creating new Font.
*/
public static class Builder {
@@ -322,8 +332,9 @@
* @param weight a weight value
* @return this builder
*/
- public @NonNull Builder setWeight(@IntRange(from = 1, to = 1000) int weight) {
- Preconditions.checkArgument(1 <= weight && weight <= 1000);
+ public @NonNull Builder setWeight(
+ @IntRange(from = FONT_WEIGHT_MIN, to = FONT_WEIGHT_MAX) int weight) {
+ Preconditions.checkArgument(FONT_WEIGHT_MIN <= weight && weight <= FONT_WEIGHT_MAX);
mWeight = weight;
return this;
}
@@ -403,6 +414,7 @@
mItalic = STYLE_NORMAL;
}
}
+ mWeight = Math.max(FONT_WEIGHT_MIN, Math.min(FONT_WEIGHT_MAX, mWeight));
final boolean italic = (mItalic == STYLE_ITALIC);
final long builderPtr = nInitBuilder();
if (mAxes != null) {