davidtakac/prognoza

Widget text doesn't respond to system night mode

TwSphinx54 opened this issue ยท 5 comments

When the system is set to 'follow the system', font color in the widget won't change automatically. So there will be black characters above dark background when the system automatically changes to dark mode.
Only click the widget manually can refresh the font and icon color in the widget.

Thanks very much for your work. :)

Hello :) Unfortunately, this is a known bug with the Android widget API - it just doesn't work as nicely on some launchers. Could you please tell me your Android version, device and launcher? Thanks for the issue!

  • Android 11
  • Samsung Galaxy A70s
  • Microsoft Luncher

Thank you for the explanation. That gives me a new reason to buy a phone with higher android version.

Haha, any reason is good enough when you want to buy a new phone ๐Ÿ˜‰ Thank you for the details, I'll check it out when I get the chance.

This can be recreated on any Android 11 device with the following steps:

  1. Put Widget on home screen
  2. Kill the app (swipe it from recents)
  3. Change system theme

Expected:

  1. Widget background, text and weather icons update to new colors

Actual:

  1. Widget background updates, but the text and icons don't

The issue seems to be that R.drawable.widget_bg applies the correct background color because it's present in drawable and drawable-night, but the Glance widget does not update itself with the correct text and icon colors. To fix this, I tried:

  1. Creating a custom Bitmap and setting it as the widget background with ImageProvider(customBitmap). The reasoning was that if Glance does not update the text and icon colors, this would prevent it from updating the background as well, which would just ignore the device theme change. This did not work because a Bitmap needs a width and height to be drawn. I tried using LocalSize, but this is not the actual size of the widget, so the Bitmap ends up with stretched corners as it tries to fill the entire widget background.
  2. Creating a widget_text_color value in values/colors.xml and values-night/colors.xml and using it if SDK < 31. The reasoning was if it pulls the background resource correctly, it should pull the color resource too. It didn't work, and I don't know why. Probably a bug or oversight in the library.
  3. Creating a ColorProvider(day = Color.Black, night = Color.White) and using it as text color if SDK < 31. This did not work, but it's not much different from the original implementation, so it somewhat makes sense.

I'll revisit this when they push a new version of the Glance Widget library. If they don't drop support for it altogether, since it was last updated Oct 2022 ๐Ÿ˜