Merge "Remove @hide from android.graphics.Color"

This commit is contained in:
Leon Scroggins
2020-05-18 14:14:54 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 25 deletions

View File

@@ -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) {

View File

@@ -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<String, Integer> sColorNameMap;
static {
sColorNameMap = new HashMap<>();