Loading core/java/android/text/Html.java +21 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading graphics/java/android/graphics/Color.java +0 −24 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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<String, Integer> sColorNameMap; static { sColorNameMap = new HashMap<>(); Loading Loading
core/java/android/text/Html.java +21 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading
graphics/java/android/graphics/Color.java +0 −24 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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<String, Integer> sColorNameMap; static { sColorNameMap = new HashMap<>(); Loading