florinzaicu / FloatingOverlay

Android application that displays a set of floating controls over other apps
MIT License
0 stars 0 forks source link

Investigate: M3 Dynamic Colors for Overlay #8

Closed florinzaicu closed 7 months ago

florinzaicu commented 8 months ago

The overlay currently uses a static colour for the background. After a bit of investigation, it seems that there is no easy way to use a dynamic colour that does not consistently breaks on older Android versions.

Investigate a way to detect colour changes.

florinzaicu commented 7 months ago

It seems that it's not as straight forward to get dynamic colours on the floating overlay as it is to do so on the Activity. While Google provides a method to apply dynamic colours to the activity, this does not trickle down to any services or views they spawn. Instead, you have to directly reference the m3 system colour keys and apply them to the overlay.

This isn't necessarily a problem (even when you need to account for day/light mode manually), but the issue arises when trying to deal with colour changes, which at the time of writing this seems like it is not possible to always detect from a service. The only real option you have is to listen for theme/colour changes on the main activity and broadcast a refresh message to the service so it can update its UI and implicitly applied colours.

The flaw with this approach, however, is that if the activity is minimised (such as in the case when you go to the system settings to change colours) and the service is running, the overlay will not update its colours until the activity is resumed.

A small price to pay for now! Maybe Compose will be a saving grace for this feature. For now, the functionality is working (dynamic colours are applied to the overlay), minus auto-change when the activity is minimised being a tad broken.