ColorUtils { public static int calculateCtaOnTapColor(final int ctaBackgroundColor) { if (isLightColor(ctaBackgroundColor, ON_TAP_LIGHTNESS_THRESHOLD)) { return calculateDarkerColor(ctaBackgroundColor, CTA_ON_TAP_DARKNESS_FACTOR); } else { return calculateLighterColor(ctaBackgroundColor, CTA_ON_TAP_LIGHTNESS_FACTOR); } } private  ColorUtils(); static int calculateCtaTextColor(final int ctaBackgroundColor); static int calculateCtaOnTapColor(final int ctaBackgroundColor); static boolean isLightColor(final int color); static int calculateDarkerColor(final int color, final float factor); static int calculateLighterColor(final int color, final float factor); static int calculateContrastingColor(final int color); static boolean isLightColor(final int color, final float factor);  }
@Test public void testCTAOnTapColorIsLighterForDarkBgColor() { final int darkColor = Color.BLACK; final int originalRed = Color.red(darkColor); final int originalGreen = Color.green(darkColor); final int originalBlue = Color.blue(darkColor); final int lighterColor = ColorUtils.calculateCtaOnTapColor(darkColor); final int lighterRed = Color.red(lighterColor); final int lighterGreen = Color.green(lighterColor); final int lighterBlue = Color.blue(lighterColor); assertTrue(lighterRed > originalRed && lighterGreen > originalGreen && lighterBlue > originalBlue); }
@Test public void testCTAOnTapColorIsDarkerForLightBgColor() { final int lightColor = Color.WHITE; final int originalRed = Color.red(lightColor); final int originalGreen = Color.green(lightColor); final int originalBlue = Color.blue(lightColor); final int darkerColor = ColorUtils.calculateCtaOnTapColor(lightColor); final int darkerRed = Color.red(darkerColor); final int darkerGreen = Color.green(darkerColor); final int darkerBlue = Color.blue(darkerColor); assertTrue(originalRed > darkerRed && originalGreen > darkerGreen && originalBlue > darkerBlue); }