-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Range alpha between 0 and 1 for android int color conversion #12210
Conversation
1f63293
to
c015102
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for running with that! A couple of comments below. Also, updating raw test would be great.
* | ||
* @param color Android color int | ||
* @return String rgba color | ||
*/ | ||
public static String colorToRgbaString(@ColorInt int color) { | ||
return String.format(Locale.US, "rgba(%d, %d, %d, %d)", | ||
(color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF, (color >> 24) & 0xFF); | ||
return String.format(Locale.US, "rgba(%d, %d, %d, %.1f)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think precision to only one decimal point will be enough in this case. What about increasing this to 3?
|
||
@Test | ||
public void testAlphaValueInStringConversion() { | ||
String color = PropertyFactory.colorToRgbaString(Color.parseColor("#80FF0000")); // 50% alpha red |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rewrite this test to include the issue mentioned above?
10089d4
to
2c4ab75
Compare
@Test | ||
public void testAlphaValueInStringConversion() { | ||
String color = PropertyFactory.colorToRgbaString(Color.parseColor("#80FF0000")); // 50% alpha red | ||
String alpha = color.split(" ")[3].substring(0, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case doesn't really test the implementation as we are cutting off the number on the first decimal point.
c837167
to
491416d
Compare
491416d
to
83328fb
Compare
83328fb
to
2edb0d2
Compare
Closes #12198