Bug? IME HeightChanged returns NewHeigth greater than 100%y after turning off the screen

Alain75

Member
I used IME HeightChanged to detect the display of the keyboard and place the input field upper the keyboard as mentionned it in an old post. It works well except when the smartphone turned off the screen because of standby. In that case, event returns a NewHeight greater than Height of the screen. So you need to test NewHeight versus min(OldHeight,100%y) :

HeightChanged Event:
Sub KBOARD_HeightChanged(NewHeight As Int, OldHeight As Int)
    Log("100%y="&100%y& " New="&NewHeight&" Old="&OldHeight)
    Dim kbaff As Boolean
    kbaff = (NewHeight<OldHeight)
    Log("KO : Keyboard "&IIf(kbaff,"shown","hidden"))
    kbaff = (NewHeight<Min(OldHeight,100%y))
    Log("OK : Keyboard "&IIf(kbaff,"shown","hidden"))
End Sub
100%y) instead

Above the log in the IDE : I touch the input field to display the keyboard, then touch to hide it, then wait the standby and finally turns it on :

Logger connecté à : samsung SM-A405FN
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
100%y=1942 New=1017 Old=1942
KO : Keyboard shown
OK : Keyboard shown
100%y=1942 New=1942 Old=1017
KO : Keyboard hidden
OK : Keyboard hidden
** Activity (main) Pause, UserClosed = false **
Ignoring event: kboard_heightchanged
** Activity (main) Resume **
100%y=1942 New=1942 Old=2086
KO : Keyboard shown
OK : Keyboard hidden

@Erel, here is the code of a very simple test : just wait for the standby and then turns on screen to see the log.
 

Attachments

  • HeightChanged.zip
    11.2 KB · Views: 59

Erel

B4X founder
Staff member
Licensed User
Longtime User

agraham

Expert
Licensed User
Longtime User
IME handling in Android is a bit of a nightmare, it was badly designed from the start although recent API changes have made it a bit less bad. You could look at my IME2 library to see if there is anything there that helps your situation.
 

Alain75

Member
Thanks for your answers. I added the manifest option but it didn't change anything (and I think it is not surprising as I already received the event) : the height is still 2086 instead of 1942 on my Samsung A40. Perhaps the difference could be the title bar height when coming from standby on some OS/devices ?

I will try IME2 a bit later as I have an easy workaround but I will have a look !
 

Alain75

Member
As Promised, I did the test and the results seem to be the same (I am not sure of the interpretation as heights are not the same). But IME and IME2 seem to returns values in the same way.
The code with IME (the event) and IME2 (var KB2):
Sub KBOARD_HeightChanged(NewHeight As Int, OldHeight As Int)
    Dim k As Rect = KB2.GetKeyboardRect, d As Rect = KB2.GetDisplayRect, w As Rect = KB2.GetWindowRect
    Dim aff As Boolean = (NewHeight<Min(100%y,OldHeight))
    Dim status As String = "Keyboard "&IIf(aff,"displayed","hidden")
    
    Log(status&CRLF&"--> Old:"&OldHeight&" New:"&NewHeight)
    Log("--> KB2 heights Keyb:"&k.Height&" Disp:"&d.Height&" Win:"&w.Height)
End Sub

And the log resulting of running the application, showing and hidding the keyboard, waiting for standby and finally resuming :

Logger connecté à : samsung SM-A405FN
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **

** Activity (main) Resume **
Keyboard displayed
--> Old:1942 New:1017
--> KB2 heights Keyb:839 Disp:2110 Win:1185
Keyboard hidden
--> Old:1017 New:1942
--> KB2 heights Keyb:-86 Disp:2110 Win:2110
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Keyboard hidden
--> Old:1942 New:2086
--> KB2 heights : Keyb:-230 Disp:2110 Win:2254
Keyboard hidden
--> Old:2086 New:1942
--> KB2 heights Keyb:-86 Disp:2110 Win:2110

As you can see both, IME and IME2 return first 144 dip more : (2086 - 1942) = 144 (2254 - 2110) = 144 which is 48 pixels
 

mfstuart

Active Member
Licensed User
Longtime User
Hi,
I downloaded your demo app and added an EditText (EditText2) view to the lower part of the layout, making it to be covered by the keyboard when it is displayed.
I was expecting the EditText2 to "move up" above the keyboard (to become visible) when touching into this view, but it did not.

What would be the fix to this so that views that are placed lower on a layout to become visible when they get focus?

Thanx,
Mark Stuart
 
Top