@Test public void getColorInt_with_black_3() throws Exception { assertEquals(0xFF000000, Utils.getColorInt("#000")); }
public static int getColorInt(String colorValue) { Matcher m = COLOR_VALUE_PATTERN.matcher(colorValue); if (!m.find()) { throw new NumberFormatException(); } colorValue = m.group(1); int colorLength = colorValue.length(); if (colorLength == 3) { int raw = Integer.parseInt(colorValue, 16); int first = (raw & 0xF00) >> 8; int second = (raw & 0x0F0) >> 4; int third = raw & 0x00F; return (0xFF << 24) | (first << 20) | (first << 16) | (second << 12) | (second << 8) | (third << 4) | third; } else if (colorLength == 6) { return (0xFF << 24) | Integer.parseInt(colorValue, 16); } else if (colorLength == 8) { return (int) Long.parseLong(colorValue, 16); } throw new BadParameterException("could not parse color value: "+colorValue); }
Utils { public static int getColorInt(String colorValue) { Matcher m = COLOR_VALUE_PATTERN.matcher(colorValue); if (!m.find()) { throw new NumberFormatException(); } colorValue = m.group(1); int colorLength = colorValue.length(); if (colorLength == 3) { int raw = Integer.parseInt(colorValue, 16); int first = (raw & 0xF00) >> 8; int second = (raw & 0x0F0) >> 4; int third = raw & 0x00F; return (0xFF << 24) | (first << 20) | (first << 16) | (second << 12) | (second << 8) | (third << 4) | third; } else if (colorLength == 6) { return (0xFF << 24) | Integer.parseInt(colorValue, 16); } else if (colorLength == 8) { return (int) Long.parseLong(colorValue, 16); } throw new BadParameterException("could not parse color value: "+colorValue); } }
Utils { public static int getColorInt(String colorValue) { Matcher m = COLOR_VALUE_PATTERN.matcher(colorValue); if (!m.find()) { throw new NumberFormatException(); } colorValue = m.group(1); int colorLength = colorValue.length(); if (colorLength == 3) { int raw = Integer.parseInt(colorValue, 16); int first = (raw & 0xF00) >> 8; int second = (raw & 0x0F0) >> 4; int third = raw & 0x00F; return (0xFF << 24) | (first << 20) | (first << 16) | (second << 12) | (second << 8) | (third << 4) | third; } else if (colorLength == 6) { return (0xFF << 24) | Integer.parseInt(colorValue, 16); } else if (colorLength == 8) { return (int) Long.parseLong(colorValue, 16); } throw new BadParameterException("could not parse color value: "+colorValue); } private  Utils(); }
Utils { public static int getColorInt(String colorValue) { Matcher m = COLOR_VALUE_PATTERN.matcher(colorValue); if (!m.find()) { throw new NumberFormatException(); } colorValue = m.group(1); int colorLength = colorValue.length(); if (colorLength == 3) { int raw = Integer.parseInt(colorValue, 16); int first = (raw & 0xF00) >> 8; int second = (raw & 0x0F0) >> 4; int third = raw & 0x00F; return (0xFF << 24) | (first << 20) | (first << 16) | (second << 12) | (second << 8) | (third << 4) | third; } else if (colorLength == 6) { return (0xFF << 24) | Integer.parseInt(colorValue, 16); } else if (colorLength == 8) { return (int) Long.parseLong(colorValue, 16); } throw new BadParameterException("could not parse color value: "+colorValue); } private  Utils(); static String join(CharSequence divider, CharSequence[] parts); static int getIdentifier(Context context, String identifierStr); static void setImageLoader(SRMLImageLoader imageLoader); static Bitmap loadImage(Context context, String url, int width, int height); static int getPixelSize(Context context, String size); static int getColorInt(String colorValue); static int getColorInt(Context context, String colorValueOrResource); }
Utils { public static int getColorInt(String colorValue) { Matcher m = COLOR_VALUE_PATTERN.matcher(colorValue); if (!m.find()) { throw new NumberFormatException(); } colorValue = m.group(1); int colorLength = colorValue.length(); if (colorLength == 3) { int raw = Integer.parseInt(colorValue, 16); int first = (raw & 0xF00) >> 8; int second = (raw & 0x0F0) >> 4; int third = raw & 0x00F; return (0xFF << 24) | (first << 20) | (first << 16) | (second << 12) | (second << 8) | (third << 4) | third; } else if (colorLength == 6) { return (0xFF << 24) | Integer.parseInt(colorValue, 16); } else if (colorLength == 8) { return (int) Long.parseLong(colorValue, 16); } throw new BadParameterException("could not parse color value: "+colorValue); } private  Utils(); static String join(CharSequence divider, CharSequence[] parts); static int getIdentifier(Context context, String identifierStr); static void setImageLoader(SRMLImageLoader imageLoader); static Bitmap loadImage(Context context, String url, int width, int height); static int getPixelSize(Context context, String size); static int getColorInt(String colorValue); static int getColorInt(Context context, String colorValueOrResource);  }