ColorUtils

public class ColorUtils extends Object

Constants and utility functions for handling colors and color strings.

Constant Summary

int ALPHA_OPAQUE
int DEFAULT_BLOCK_HUE
float DEFAULT_BLOCK_SATURATION
float DEFAULT_BLOCK_VALUE

Field Summary

public static final int DEFAULT_BLOCK_COLOR
public static final Pattern SIX_DIGIT_HEX_PATTERN Regex pattern to match a standard six-digit color code.

Public Constructor Summary

Public Method Summary

static int
blendRGB(int a, int b, float ratio)
Linearly interpolate the RGB from color a to color b.
static int
getBlockColorForHue(int hue, float[] tempHsvArray)
Converts a hue number to a standard ARGB int, using DEFAULT_BLOCK_SATURATION and DEFAULT_BLOCK_VALUE.
static int
parseColor(String str, float[] tempHsvArray)
Parses a string as an opaque color, either as a decimal hue (example: 330) using a standard set of saturation and value) or as six digit hex code (example: #BB66FF).
static int
parseColor(String str, float[] tempHsvArray, int defaultColor)
Parses a string as an opaque color, either as a decimal hue (example: 330) using a standard set of saturation and value) or as six digit hex code (example: #BB66FF).

Inherited Method Summary

Constants

public static final int ALPHA_OPAQUE

Constant Value: 255

public static final int DEFAULT_BLOCK_HUE

Constant Value: 0

public static final float DEFAULT_BLOCK_SATURATION

Constant Value: 0.45

public static final float DEFAULT_BLOCK_VALUE

Constant Value: 0.65

Fields

public static final int DEFAULT_BLOCK_COLOR

public static final Pattern SIX_DIGIT_HEX_PATTERN

Regex pattern to match a standard six-digit color code.

Public Constructors

public ColorUtils ()

Public Methods

public static int blendRGB (int a, int b, float ratio)

Linearly interpolate the RGB from color a to color b. Alpha values are ignored, and the resulting alpha is always opaque.

Parameters
a The start color, or the result if the ratio is 0.0.
b The end color, or the result if the ratio is 1.0.
ratio The ratio of b's influence in the result, between 0.0 to 1.0.
Returns
  • The computed blend color as an integer.

public static int getBlockColorForHue (int hue, float[] tempHsvArray)

Converts a hue number to a standard ARGB int, using DEFAULT_BLOCK_SATURATION and DEFAULT_BLOCK_VALUE. The resulting color will always be opaque.

Parameters
hue The hue to convert.
tempHsvArray An optional previously allocated array for HSV calculations.
Returns
  • The color as an ARGB int.

public static int parseColor (String str, float[] tempHsvArray)

Parses a string as an opaque color, either as a decimal hue (example: 330) using a standard set of saturation and value) or as six digit hex code (example: #BB66FF). If the string cannot be parsed, a ParseException is thrown.

Parameters
str The input to parse.
tempHsvArray An optional previously allocated array for HSV calculations.
Returns
  • The parsed color, in int form.
Throws
ParseException

public static int parseColor (String str, float[] tempHsvArray, int defaultColor)

Parses a string as an opaque color, either as a decimal hue (example: 330) using a standard set of saturation and value) or as six digit hex code (example: #BB66FF). If the string is null or cannot otherwise be parsed, any error is logged and defaultColor is returned.

Parameters
str The input to parse.
tempHsvArray An optional previously allocated array for HSV calculations.
defaultColor The default color to return if the color cannot be parsed.
Returns
  • The parsed color, in int form.