int alpha = Integer.decode(s.substring(0, 3));
int rgb = Integer.decode("#" + s.substring(3));
color = new Color(alpha << 24 | rgb, true);
break;
default:
throw new ResourceConverterException("invalid #RRGGBB or #AARRGGBB color string", s);
}
}
else {
String[] parts = s.split(",");
if (parts.length < 3 || parts.length > 4) {
throw new ResourceConverterException("invalid R, G, B[, A] color string", s);
}
try {
// with alpha component
if (parts.length == 4) {
int r = Integer.parseInt(parts[0].trim());
int g = Integer.parseInt(parts[1].trim());
int b = Integer.parseInt(parts[2].trim());
int a = Integer.parseInt(parts[3].trim());
color = new Color(r, g, b, a);
} else {
int r = Integer.parseInt(parts[0].trim());
int g = Integer.parseInt(parts[1].trim());
int b = Integer.parseInt(parts[2].trim());
color = new Color(r, g, b);
}
}
catch (NumberFormatException e) {
throw new ResourceConverterException("invalid R, G, B[, A] color string", s, e);
}
}
return color;
}