ColorUtils { public static int calculateCtaTextColor(final int ctaBackgroundColor) { if (isLightColor(ctaBackgroundColor)) { return calculateDarkerColor(ctaBackgroundColor, CTA_TEXT_LIGHTNESS_FACTOR); } else { return Color.WHITE; } } 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 testCtaTextColorIsLightForDarkBgColor() { assertEquals(Color.WHITE, ColorUtils.calculateCtaTextColor(R.color.tw__ad_cta_default)); assertEquals(Color.WHITE, ColorUtils.calculateCtaTextColor(Color.BLACK)); assertEquals(Color.WHITE, ColorUtils.calculateCtaTextColor(Color.DKGRAY)); }
@Test public void testCtaTextColorIsDarkForLightBgColor() { assertTrue(Color.WHITE != ColorUtils.calculateCtaTextColor(Color.WHITE)); assertTrue(Color.WHITE != ColorUtils.calculateCtaTextColor(Color.LTGRAY)); }