Last active
April 24, 2024 14:01
-
-
Save atebit/8aa23a731532a71d3fc42162ed3f571e to your computer and use it in GitHub Desktop.
Android Color Contrast Algo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void exportColor(int flags) { | |
| if ((flags & leaveValue) == 0 && valueElement != null) { | |
| // Implement your logic for handling valueElement | |
| } | |
| String value = toString(); | |
| if (caps) { | |
| value = value.toUpperCase(); | |
| } | |
| if (hash) { | |
| value = "#" + value; | |
| } | |
| if (valueElement != null) { | |
| valueElement.setText(value); | |
| } | |
| if ((flags & leaveStyle) == 0 && styleElement != null) { | |
| styleElement.setBackgroundResource(0); | |
| styleElement.setBackgroundColor(Color.parseColor("#" + toString())); | |
| double luminance = 0.213 * rgb[0] + 0.715 * rgb[1] + 0.072 * rgb[2]; | |
| int textColor = luminance < 0.5 ? Color.WHITE : Color.BLACK; | |
| styleElement.setTextColor(textColor); | |
| } | |
| if ((flags & leavePad) == 0 && isPickerOwner()) { | |
| redrawPad(); | |
| } | |
| if ((flags & leaveSld) == 0 && isPickerOwner()) { | |
| redrawSld(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment