Fix TtmlColorParser test.
Also simplify the implementation slightly.
This commit is contained in:
parent
afafd08346
commit
7974a61476
@ -24,10 +24,12 @@ import android.test.InstrumentationTestCase;
|
|||||||
public class TtmlColorParserTest extends InstrumentationTestCase {
|
public class TtmlColorParserTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
public void testHexCodeParsing() {
|
public void testHexCodeParsing() {
|
||||||
assertEquals(Color.WHITE, TtmlColorParser.parseColor("#ffffff"));
|
assertEquals(Color.WHITE, TtmlColorParser.parseColor("#FFFFFF"));
|
||||||
assertEquals(Color.WHITE, TtmlColorParser.parseColor("#ffffffff"));
|
assertEquals(Color.WHITE, TtmlColorParser.parseColor("#FFFFFFFF"));
|
||||||
assertEquals(Color.parseColor("#00ffffff"), TtmlColorParser.parseColor("#00ffffff"));
|
assertEquals(Color.parseColor("#FF123456"), TtmlColorParser.parseColor("#123456"));
|
||||||
assertEquals(Color.parseColor("#12341234"), TtmlColorParser.parseColor("#12341234"));
|
// Hex colors in TTML are RGBA, where-as {@link Color#parseColor} takes ARGB.
|
||||||
|
assertEquals(Color.parseColor("#00FFFFFF"), TtmlColorParser.parseColor("#FFFFFF00"));
|
||||||
|
assertEquals(Color.parseColor("#78123456"), TtmlColorParser.parseColor("#12345678"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testColorNameParsing() {
|
public void testColorNameParsing() {
|
||||||
|
@ -40,7 +40,6 @@ import java.util.regex.Pattern;
|
|||||||
private static final Pattern RGBA_PATTERN = Pattern.compile(
|
private static final Pattern RGBA_PATTERN = Pattern.compile(
|
||||||
"^rgba\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),(\\d{1,3})\\)$");
|
"^rgba\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),(\\d{1,3})\\)$");
|
||||||
|
|
||||||
|
|
||||||
static final int TRANSPARENT = 0x00000000;
|
static final int TRANSPARENT = 0x00000000;
|
||||||
static final int BLACK = 0xFF000000;
|
static final int BLACK = 0xFF000000;
|
||||||
static final int SILVER = 0xFFC0C0C0;
|
static final int SILVER = 0xFFC0C0C0;
|
||||||
@ -93,12 +92,10 @@ import java.util.regex.Pattern;
|
|||||||
long color = Long.parseLong(colorExpression.substring(1), 16);
|
long color = Long.parseLong(colorExpression.substring(1), 16);
|
||||||
if (colorExpression.length() == 7) {
|
if (colorExpression.length() == 7) {
|
||||||
// Set the alpha value
|
// Set the alpha value
|
||||||
color |= 0x00000000FF000000;
|
color |= 0xFF000000L;
|
||||||
} else if (colorExpression.length() == 9) {
|
} else if (colorExpression.length() == 9) {
|
||||||
// We have #RRGGBBAA, but we need #AARRGGBB
|
// We have #RRGGBBAA, but we need #AARRGGBB
|
||||||
int alpha = (int) color & 0x00000000000000FF;
|
color = ((color & 0xFF) << 24) | (color >> 8);
|
||||||
color >>= 8;
|
|
||||||
color |= alpha << 24;
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user