Skip to content

fix: calculate the better contrasting color#308

Merged
naveensingh merged 1 commit intoFossifyOrg:mainfrom
rros:fix/calculate-better-contrasting-color
Feb 12, 2026
Merged

fix: calculate the better contrasting color#308
naveensingh merged 1 commit intoFossifyOrg:mainfrom
rros:fix/calculate-better-contrasting-color

Conversation

@rros
Copy link
Contributor

@rros rros commented Feb 11, 2026

…he contrast of both foreground colors against the background color.

Type of change(s)

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

What changed and why

Fixed the way the contrast color is calculated. The old method uses the current color DARK_GREY and WHITE. The new overload allows for arbitrary colors, so we can i.e. also compare BLACK and WHITE in the consuming app without changing the colors for every consumer.

Tests performed

I tested this implementation in the Calendar app at a single location.

Before & after preview

Before with a background #66C791:
afbeelding

After with the same background:
afbeelding

Closes the following issue(s)

This change is needed to properly address: FossifyOrg/Calendar#992

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.

…he contrast of both foreground colors against the background color.
@rros rros requested a review from naveensingh as a code owner February 11, 2026 20:50
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.

Looks good. Commons will be updated soon.

@naveensingh naveensingh merged commit d0577f8 into FossifyOrg:main Feb 12, 2026
7 checks passed
@rros
Copy link
Contributor Author

rros commented Feb 12, 2026

@naveensingh I just realised two things that might have some impact:

  1. for calculateContrast() to work, the background must be opaque. When the alpha channel for a background color is not opaque. The method will throw an IllegalArgumentException. It seem to break at least the Calendar widget, because the background of those widgets are partially transparant. I'll look into a solution for this.
  2. The calculation might be heavier than the old calculation. This might have an impact if the method is called many times without caching any result.

@naveensingh
Copy link
Member

for calculateContrast() to work, the background must be opaque. When the alpha channel for a background color is not opaque. The method will throw an IllegalArgumentException. It seem to break at least the Calendar widget, because the background of those widgets are partially transparant. I'll look into a solution for this.

Sadly, I found out about that after the merge.

The calculation might be heavier than the old calculation. This might have an impact if the method is called many times without caching any result.

It should be light enough. We'll see.

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