Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
il...@google.com <il...@google.com> #3
If the width or height is greater than 8191, left-shifting causes the sign bit to be lost, turning a '1' into a '0', which results in an incorrect width or height.
I agree there's a bug here, but I'm not sure this is quite a precise description of the problem. A quick experiment suggests that the left shift (<<
) works fine (if we are just looking at bits), but the right shift (>>
) is where the problem is introduced, because >>
does "sign extension" in Java - meaning if input value is negative (the MSB of the 32-bit int is 1
), then the result will be negative too. This can be fixed by using the unsigned right shift operator (>>>
).
You can see this in jshell
:
$ jshell
| Welcome to JShell -- Version 22
| For an introduction type: /help intro
jshell> int width = 5
width ==> 5
jshell> int height = 8192
height ==> 8192
jshell> int widthAndHeight = (width << 16) | height
widthAndHeight ==> 335872
jshell> (widthAndHeight << 18) >> 18
$8 ==> -8192
jshell> (widthAndHeight << 18) >>> 18
$9 ==> 8192
That said, I also agree that your change in
Description
Currently, the `Navigation` class has 2 signatures for `createNavigateOnClickListener`:
`createNavigateOnClickListener(final int resId)`
`createNavigateOnClickListener(final int resId, finalBundle args)`
I propose a third overload:
`createNavigateOnClickListener(NavDirections)`
This overload could trampoline to the other two, as necessary, but it would allow for users to avoid having to manually extract the ActionID and Bundle from the NavDirections. It would be a nicety on top of an already nice library :)