exponea / exponea-flutter-sdk

MIT License
7 stars 9 forks source link

fix/Fix android pushAccentColor color decoding #9

Closed bshv-ciklum closed 1 year ago

bshv-ciklum commented 1 year ago

pushAccentColor holds a 32-bits color value.

When we perform a conversion from Double to signed Int (it.toInt()) and the value is bigger than Int.MAX_VALUE then Int.MAX_VALUE is returned. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/to-int.html

Let's consider the Black color - 0xFF000000: Binary representation: 11111111 00000000 00000000 00000000 Fist bit represents the number signature so when converting from 64-bits Double to 32-bits signed Int result will be: 01111111 00000000 00000000 00000000 (hex - 7F000000).

To avoid this behavior we need to convert through unsigned Int - it will not change the most significant bit as it will not be reserved for signature. And then unsigned Int to signed Int conversion will give us the same binary representation: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-u-int/to-int.html

Kotlin playground example: https://pl.kotl.in/8cRHCsinn

omegasoft7 commented 1 year ago

@adam1929 any update regarding this issue?

omegasoft7 commented 1 year ago

@adam1929 Any updates regarding this open issue?

adam1929 commented 1 year ago

Thank you @bshv-ciklum for your solution. We are currently working on flutter SDK release that will contains this fix. Please be aware that notification color will ignore alpha values as is written by docs: https://developer.android.com/reference/android/app/Notification#color