Merge "Remove @hide from android.graphics.Color"
This commit is contained in:
committed by
Android (Google) Code Review
commit
dde48febd6
@@ -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) {
|
||||
|
||||
@@ -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<>();
|
||||
|
||||
Reference in New Issue
Block a user