Skip to content

Instantly share code, notes, and snippets.

@paddyzab
Created January 28, 2015 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paddyzab/7ef3d9506d3a5d0b7b73 to your computer and use it in GitHub Desktop.
Save paddyzab/7ef3d9506d3a5d0b7b73 to your computer and use it in GitHub Desktop.
testing_colors
private static void assertIsColorClose(TextView label, int textColor) {
int currentTextColor = label.getCurrentTextColor();
int currentRed = (currentTextColor >> 16) & 0xFF;
int currentGreen = (currentTextColor >> 8) & 0xFF;
int currentBlue = (currentTextColor >> 0) & 0xFF;
int expectedRed = (textColor >> 16) & 0xFF;
int expectedGreen = (textColor >> 8) & 0xFF;
int expectedBlue = (textColor >> 0) & 0xFF;
assertTrue(((expectedRed - COLOR_TOLERANCE) <= currentRed) && (expectedRed + COLOR_TOLERANCE) >= currentRed);
assertTrue(((expectedGreen - COLOR_TOLERANCE) <= currentGreen) && (expectedGreen + COLOR_TOLERANCE) >= currentGreen);
assertTrue(((expectedBlue - COLOR_TOLERANCE) <= currentBlue) && (expectedBlue + COLOR_TOLERANCE) >= currentBlue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment