Class ContrastAccessibility

java.lang.Object
cl.emilym.contrastaccessibility.ContrastAccessibility

public class ContrastAccessibility extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    luminance(long color)
    Calculates the relative luminance of a color as per WCAG 2.1 specifications.
    static double
    ratio(long color1, long color2)
    Calculates the contrast ratio between two colors.
    static boolean
    valid(long color1, long color2)
    Checks if the contrast ratio between two colors meets the accessibility threshold for text.
    static boolean
    valid(long color1, long color2, ContrastAccessibilityContext context)
    Checks if the contrast ratio between two colors meets the accessibility threshold for a specified context.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • valid

      public static boolean valid(long color1, long color2)
      Checks if the contrast ratio between two colors meets the accessibility threshold for text.
      Parameters:
      color1 - The first color as a long integer.
      color2 - The second color as a long integer.
      Returns:
      true if the contrast ratio is above the text accessibility threshold, false otherwise.
    • valid

      public static boolean valid(long color1, long color2, ContrastAccessibilityContext context)
      Checks if the contrast ratio between two colors meets the accessibility threshold for a specified context.
      Parameters:
      color1 - The first color as a long integer.
      color2 - The second color as a long integer.
      context - The context for which to check the accessibility threshold.
      Returns:
      true if the contrast ratio is above the specified accessibility threshold, false otherwise.
    • ratio

      public static double ratio(long color1, long color2)
      Calculates the contrast ratio between two colors.
      Parameters:
      color1 - The first color as a long integer.
      color2 - The second color as a long integer.
      Returns:
      The contrast ratio between the two colors.
      See Also:
    • luminance

      public static double luminance(long color)
      Calculates the relative luminance of a color as per WCAG 2.1 specifications.
      Parameters:
      color - The color as a long integer.
      Returns:
      The relative luminance of the color.
      See Also: