mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-22 23:29:10 +00:00
remove duplicate code, keep alpha when adjusting luminosity, comments
This commit is contained in:
parent
146231dcb0
commit
50921ef8cd
1 changed files with 14 additions and 9 deletions
|
@ -11,6 +11,7 @@ import androidx.core.graphics.ColorUtils;
|
||||||
|
|
||||||
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme;
|
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme;
|
||||||
|
|
||||||
|
// todo: maybe kotlin? would make it much shorter and more readable
|
||||||
public class Colors {
|
public class Colors {
|
||||||
|
|
||||||
public final boolean isCustom;
|
public final boolean isCustom;
|
||||||
|
@ -131,6 +132,7 @@ public class Colors {
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: move static functions to some utility class?
|
||||||
public static boolean isBrightColor(final int color) {
|
public static boolean isBrightColor(final int color) {
|
||||||
if (android.R.color.transparent == color) {
|
if (android.R.color.transparent == color) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -160,20 +162,23 @@ public class Colors {
|
||||||
return (int) (rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068);
|
return (int) (rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ColorInt
|
private static int adjustLuminosityAndKeepAlpha(@ColorInt final int color, final float amount) {
|
||||||
public static int brighten(@ColorInt int color) {
|
final int alpha = Color.alpha(color);
|
||||||
float[] hsl = new float[3];
|
float[] hsl = new float[3];
|
||||||
ColorUtils.colorToHSL(color, hsl);
|
ColorUtils.colorToHSL(color, hsl);
|
||||||
hsl[2] += 0.05f;
|
hsl[2] += amount;
|
||||||
return ColorUtils.HSLToColor(hsl);
|
final int newColor = ColorUtils.HSLToColor(hsl);
|
||||||
|
return Color.argb(alpha, Color.red(newColor), Color.green(newColor), Color.blue(newColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
public static int darken(@ColorInt int color) {
|
public static int brighten(@ColorInt final int color) {
|
||||||
float[] hsl = new float[3];
|
return adjustLuminosityAndKeepAlpha(color, 0.05f);
|
||||||
ColorUtils.colorToHSL(color, hsl);
|
}
|
||||||
hsl[2] -= 0.05f;
|
|
||||||
return ColorUtils.HSLToColor(hsl);
|
@ColorInt
|
||||||
|
public static int darken(@ColorInt final int color) {
|
||||||
|
return adjustLuminosityAndKeepAlpha(color, -0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue