Skip to content

fix: calculate contrast for translucent backgrounds using heuristic to prevent crashes#309

Merged
naveensingh merged 3 commits intoFossifyOrg:mainfrom
rros:fix/calculate-contrast-translucent-background
Feb 13, 2026
Merged

fix: calculate contrast for translucent backgrounds using heuristic to prevent crashes#309
naveensingh merged 3 commits intoFossifyOrg:mainfrom
rros:fix/calculate-contrast-translucent-background

Conversation

@rros
Copy link
Contributor

@rros rros commented Feb 12, 2026

First of all, I'm sorry I introduced a bug with my previous PR.

Type of change(s)

  • Bug fix
  • Feature / enhancement
  • Infrastructure / tooling (CI, build, deps, tests)
  • Documentation

What changed and why

The previous PR changed the way the better contrasting color is calculated. However this didn't work for translucent backgrounds. The code would throw an InvalidArgumentException.
This PR fixes that by reverting to a heuristic to calculate the better contrasting color for translucent backgrounds. It uses a similar approach to the old code, but instead of depending on a hard coded threshold for DARK_GREY and WHITE, this code determines a threshold based on the relative luminance of any two colors calculated based on the WCAG standard (https://www.w3.org/WAI/WCAG22/Techniques/general/G17#procedure)

Tests performed

Tested it with the Calendar Widget, which was crashing after the last PR was applied and it did work again after this PR.

Closes the following issue(s)

Checklist

  • I read the contribution guidelines.
  • I manually tested my changes on device/emulator (if applicable).
  • I updated the "Unreleased" section in CHANGELOG.md (if applicable).
  • I have self-reviewed my pull request (no typos, formatting errors, etc.).
  • I understand every change in this pull request.

@rros rros requested a review from naveensingh as a code owner February 12, 2026 20:26
Copy link
Member

@naveensingh naveensingh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@naveensingh naveensingh merged commit acfd352 into FossifyOrg:main Feb 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants