diff --git a/core/java/android/text/Html.java b/core/java/android/text/Html.java
index 55af087ca5b81..e3cb382256ae2 100644
--- a/core/java/android/text/Html.java
+++ b/core/java/android/text/Html.java
@@ -41,6 +41,8 @@ import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
+import com.android.internal.util.XmlUtils;
+
import org.ccil.cowan.tagsoup.HTMLSchema;
import org.ccil.cowan.tagsoup.Parser;
import org.xml.sax.Attributes;
@@ -1188,7 +1190,25 @@ class HtmlToSpannedConverter implements ContentHandler {
return i;
}
}
- return Color.getHtmlColor(color);
+
+ // If |color| is the name of a color, pass it to Color to convert it. Otherwise,
+ // it may start with "#", "0", "0x", "+", or a digit. All of these cases are
+ // handled below by XmlUtils. (Note that parseColor accepts colors starting
+ // with "#", but it treats them differently from XmlUtils.)
+ if (Character.isLetter(color.charAt(0))) {
+ try {
+ return Color.parseColor(color);
+ } catch (IllegalArgumentException e) {
+ return -1;
+ }
+ }
+
+ try {
+ return XmlUtils.convertValueToInt(color, -1);
+ } catch (NumberFormatException nfe) {
+ return -1;
+ }
+
}
public void setDocumentLocator(Locator locator) {
diff --git a/graphics/java/android/graphics/Color.java b/graphics/java/android/graphics/Color.java
index c4bf9d3123bfd..87a805379b56a 100644
--- a/graphics/java/android/graphics/Color.java
+++ b/graphics/java/android/graphics/Color.java
@@ -26,7 +26,6 @@ import android.annotation.Nullable;
import android.annotation.Size;
import android.annotation.SuppressAutoDoc;
import android.util.Half;
-import com.android.internal.util.XmlUtils;
import java.util.Arrays;
import java.util.HashMap;
@@ -1476,29 +1475,6 @@ public class Color {
private static native void nativeRGBToHSV(int red, int greed, int blue, float hsv[]);
private static native int nativeHSVToColor(int alpha, float hsv[]);
- /**
- * Converts an HTML color (named or numeric) to an integer RGB value.
- *
- * @param color Non-null color string.
- *
- * @return A color value, or {@code -1} if the color string could not be interpreted.
- *
- * @hide
- */
- @ColorInt
- public static int getHtmlColor(@NonNull String color) {
- Integer i = sColorNameMap.get(color.toLowerCase(Locale.ROOT));
- if (i != null) {
- return i;
- } else {
- try {
- return XmlUtils.convertValueToInt(color, -1);
- } catch (NumberFormatException nfe) {
- return -1;
- }
- }
- }
-
private static final HashMap sColorNameMap;
static {
sColorNameMap = new HashMap<>();