Colors { @ColorInt public static int brighter(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float fraction) { if (fraction < 0.0f || fraction > 1.0f) { throw new IllegalArgumentException("Fraction(" + fraction + ") is out of [0.0, 1.0f] range."); } final int red = (int) Math.round(Color.red(color) * (1.0 + fraction)); final int green = (int) Math.round(Color.green(color) * (1.0 + fraction)); final int blue = (int) Math.round(Color.blue(color) * (1.0 + fraction)); return Color.argb( Color.alpha(color), ensureThatComponentValueIsInAllowedInterval(red), ensureThatComponentValueIsInAllowedInterval(green), ensureThatComponentValueIsInAllowedInterval(blue) ); } private  Colors(); @ColorInt static int withAlpha(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float alphaRatio); @ColorInt static int withAlpha(@ColorInt final int color, @IntRange(from = COMPONENT_VALUE_MIN, to = COMPONENT_VALUE_MAX) final int alpha); @ColorInt static int blend(@ColorInt final int first, @ColorInt final int second); @SuppressWarnings("UnnecessaryLocalVariable") @ColorInt static int blend(@ColorInt final int first, @ColorInt final int second, @FloatRange(from = 0, to = 1) final float blendingRatio); @ColorInt static int brighter(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float fraction); @ColorInt static int darker(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float fraction); @ColorInt static int random(final boolean randomAlpha); @NonNull static String hexName(@ColorInt final int color); @NonNull static String hexName(@ColorInt final int color, final boolean withAlpha);  }
@Test(expected = IllegalArgumentException.class) public void testBrighterWithFractionOutOfRangeOver() { Colors.brighter(0, 1.1f); }
@Test(expected = IllegalArgumentException.class) public void testBrighterWithFractionOutOfRangeUnder() { Colors.brighter(0, -0.1f); }
@Test public void testBrighter() { final int color = Color.parseColor("#FF3F51B5"); assertThat(Colors.brighter(color, 0f), is(color)); float fraction = 0.01f; while (fraction < 1.0f) { final int brighterColor = Colors.brighter(color, fraction); assertThat(brighterColor, greaterThan(color)); assertThat(Color.alpha(brighterColor), is(Color.alpha(color))); fraction += 0.01f; } }