rkkr / simple-keyboard

Apache License 2.0
1.09k stars 222 forks source link

Incorrect landscape width when the NavBar is hidden #89

Open edwardxdx opened 5 years ago

edwardxdx commented 5 years ago

In landscape mode, when the navbar is hidden (by Navigation Gestures app) the keyboard is displayed as if the navbar is still present on the right side. The keyboard does not see that the navbar is hidden.

The other content is correctly displayed to fit the entire window space to the right.

There are no issues in portrait mode!

I tried it on Mi Max 3 and Redmi Note 5 plus, Lineage OS 15 and AOSP 9.0 v110

(I checked other keyboards like Gboard and SwiftKey and they are working as expected but Simple Keyboard is what I really need.)

Any idea?

I can help with testing if that will make it easier.

Screenshot_20190310-203144

rkkr commented 5 years ago

Finally managed to set this up. That "Navigation Gestures" app is a horrible hack. It doesn't hide the nav bar, it sets the screen resolution to 2063x1080, so the navbar appears below the visible screen. All android APIs still say that you resolution is 1920x1080 and that navbar height is till the same and navbar is still "visible". I've checked AnySoftKeyboard and HackersKeyboard and they both use the same API (as they're both based on AOSP).

Now the reason this works in non AOSP based keyboards is probably the layout logic. In AOSP everything is drawn programmatically to the screen by calculating pixels. This is why you see what you see, as the screen is still reported as 1920x1080. An alternate method would be to allow OS to render all the layout, but this means rewriting all the rendering logic, which I'll probably not do. And there isn't an opensource keyboard to copy this from.

edwardxdx commented 5 years ago

Thank you very much for your time spent on researching and reproducing the issue!!! It is more complex than I anticipated.

One thing, because you said that there aren't any open source keyboards to have a look at, I tried them all on F-Droid and I think I've found one, only one. It is called Sophia Keyboard.

It hasn't been updated for many years but it works as intended in landscape mode. (minus a single extreme right line)

Furthermore, the author mentioned that it is also based on AOSP (Latin IME).

If you have time maybe you can have a look at it,

https://github.com/htruong/sophia_oss

Again, I can help with testing on multiple devices if needed.

Thank you!

edwardxdx commented 5 years ago

Sorry, it does not work entirely as intended. I was quick to reply. The keys layout is not mapped up to the right margin. But still, the keyboard frame is indeed all right to the margin and the remaining space is touch sensitive. I think it is still worth looking at it.

rkkr commented 5 years ago

It uses the same getDisplayMetrics().widthPixels method which has a bug https://stackoverflow.com/questions/10991194/android-displaymetrics-returns-incorrect-screen-size-in-pixels-on-ics . There is another method getRealMetrics(), but it returns the physical display resolution, not a usable space and it also doesn't include any scaling.

The background being drawn is just a question of the layer in which it's set in. The base frame has android:layout_width="match_parent" so it always takes full width.

ghost commented 2 years ago

Is this still relevant or should this issue be closed?

rkkr commented 2 years ago

This has not been fixed, so it is relevant.