1. Android Color Contrast
/** calculates the constrast between the colors, using the algorithm provided by the WCAG v2. */public static float computecontrastbetweencolors (int bg, int fg) {Float BgR = color.red (BG)/255f; float BgG = color.green (BG)/255f; float BgB = color.blue (BG)/255f; BgR = (BgR < 0.03928f)? BGR/12.92F: (float) Math.pow ((BgR + 0.055f)/1.055f, 2.4f); BgG = (BgG < 0.03928f)? BGG/12.92F: (float) Math.pow ((BgG + 0.055f)/1.055f, 2.4f); BGB = (BGB < 0.03928f)? BGB/12.92F: (float) Math.pow ((BgB + 0.055f)/1.055f, 2.4f); float BgL = 0.2126f * BgR + 0.7152f * bgG + 0.0722f * BgB; float FgR = color.red (FG)/255f; float FgG = Color.green (FG)/255f; float FgB = Color.Blue (FG)/255f; FgR = (FgR < 0.03928f)? FGR/12.92F: (float) Math.pow ((FgR + 0.055f)/1.055f, 2.4f); FgG = (FgG < 0.03928f)? FGG/12.92F: (float) Math.pow ((FgG + 0.055f)/1.055f, 2.4f); FGB = (FgB < 0.03928f)? FGB/12.92F: (float) Math.pow ((FgB + 0.055f)/1.055f, 2.4f); float FgL = 0.2126f * FgR + 0.7152f * fgG + 0.0722f * FgB; Return Math.Abs ((FgL + 0.05f)/(BgL + 0.05f)); }
Android color Contrast