List of usage examples for android.graphics Color parseColor
@ColorInt public static int parseColor(@Size(min = 1) String colorString)
From source file:Main.java
/** * converts int value to color/*from w w w. ja va 2s.c o m*/ * * @param value The integer value of service layer * @return The parsed color from input int */ public static int getColorInt(int value) { return Color.parseColor("#" + doublePrecision(value) + "000000"); }
From source file:Main.java
public static int getNearestResColor(int color, String[] resColors) { int[] colors = new int[resColors.length]; for (int i = 0; i < resColors.length; i++) colors[i] = Color.parseColor(resColors[i]); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); int nearest = colors[0]; int minDistance = 3 * 255; int distance; for (int col : colors) { int r2 = Color.red(col); int g2 = Color.green(col); int b2 = Color.blue(col); distance = Math.abs(r - r2) + Math.abs(g - g2) + Math.abs(b - b2); if (distance < minDistance) { minDistance = distance;// ww w . jav a 2 s . co m nearest = col; } } return nearest; }
From source file:Main.java
public static int colorForString(String string) { try {/*from ww w. ja v a 2 s . c o m*/ String colorString = "#" + string; int color = Color.parseColor(colorString); return color; } catch (NumberFormatException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { Log.w(TAG, "Color parsing error from string: " + string); e.printStackTrace(); } return 0; }
From source file:Main.java
public static int HextoColor(String color) { // #00000000 - #ffffffff String reg = "#[a-f0-9A-F]{8}"; if (!Pattern.matches(reg, color)) { color = "#ffffffff"; }// w w w.j a v a 2 s .com return Color.parseColor(color); }
From source file:Main.java
public static ColorStateList getNavIconColorState() { return createColorStateList(Color.parseColor(NAV_ICON_COLOR_CHECKED), Color.parseColor(NAV_ICON_COLOR_NORMAL)); }
From source file:Main.java
public static ColorStateList getNavTextColorState() { return createColorStateList(Color.parseColor(NAV_TEXT_COLOR_CHECKED), Color.parseColor(NAV_TEXT_COLOR_NORMAL)); }
From source file:Main.java
/** * Will parse a color and set it as text color * @param color a string that can be converted into a hex color e.g #000fff * @param v textview//ww w.java 2 s. c o m */ public static void setTextColor(String color, TextView v) { v.setTextColor(Color.parseColor(color.isEmpty() ? "#000000" : color)); }
From source file:Main.java
public static int hex2color(String color) { if (TextUtils.isEmpty(color)) { color = "#ffffff"; }//from w w w. jav a 2s . co m int result; if (color.charAt(0) != '#') { color = "#" + color; } result = Color.parseColor(color); return result; }
From source file:Main.java
public static ColorDrawable getRandomColor() { return new ColorDrawable(Color.parseColor(colors[random.nextInt(8)])); }
From source file:Main.java
/** * This function returns a hashmap which contains the colors for each face of the cube *//* w w w . j a v a 2 s . c o m*/ public static HashMap<Character, Integer> getColorLetterHashMap(SharedPreferences sp) { HashMap<Character, Integer> hashMap = new HashMap<>(7); hashMap.put('Y', Color.parseColor("#" + sp.getString("cubeDown", "FDD835"))); hashMap.put('R', Color.parseColor("#" + sp.getString("cubeRight", "EC0000"))); hashMap.put('G', Color.parseColor("#" + sp.getString("cubeFront", "02D040"))); hashMap.put('B', Color.parseColor("#" + sp.getString("cubeBack", "304FFE"))); hashMap.put('O', Color.parseColor("#" + sp.getString("cubeLeft", "FF8B24"))); hashMap.put('W', Color.parseColor("#" + sp.getString("cubeTop", "FFFFFF"))); hashMap.put('N', Color.parseColor("#9E9E9E")); return hashMap; }