Delphi FMX - Virtual Keyboard in Android covers control (invalid keyboard height)
Asked Answered
P

0

6

I have created a simple FMX form (in Delphi Tokyo 10.2.1) with 3 controls on it:

  1. TLayout (LayoutKbd) - aligned to the bottom of the screen. Height 1.
  2. TRectangle - aligned to bottom (above the TLayout). Height 5.
  3. TMemo - aligned to client.

In the Form's OnVirtualKeyboardShown event, I have the following code:

procedure TForm1.FormVirtualKeyboardShown(Sender: TObject;
  KeyboardVisible: Boolean; const Bounds: TRect);
begin
  if KeyboardVisible then
  begin
    LayoutKbd.Height:=Bounds.Height;
  end;
end;

When I run it on my Android phone and touch inside the memo, the virtual keyboard is shown and the event is triggered. However the value of Bounds.Height is a random, large, negative number (see local var during debug) below.

enter image description here

As per the documentation:

The Bounds parameter of the event handler specifies the screen coordinates of the window of the virtual keyboard

I would expect the screen to show me the keyboard (overlapping my TLayout) and above it the TRectangle and above that my TMemo. But since the height of the layout is not being shown, the virtual keyboard covers part of the memo.

It is possible I am missing something very basic. My questions are:

  • How do I get the height of the virtual keyboard?
  • Am I doing something wrong with trying to get the height from the Bounds? (I have also tried getting the height from Bounds.Size.Height - which does not work either)
  • Is there a different/better way to reliably resize my memo so that none of it is obscured by the virtual keyboard.

Appreciate any help or guidance in this matter.

UPDATE 20170906: Given the generally poor experience I have had with 10.2.1 Tokyo, I decided to try the code in 10.1.2 Berlin. Interestingly, the code works in Berlin - but the height of the keyboard is reported to be exactly 25px more than it should be. So by using LayoutKbd.Height:=Bounds.Height - 25;, I get the exact height of the keyboard. While this is still an issue (related to RSP-14004), it is something that can be worked with.

So this does seem like a bug with Tokyo 10.2.1 - I have filed a ticket on Quality Portal (RSP-19001). I am growing increasingly frustrated with the quality issues surrounding Tokyo 10.2.1. We are spending a lot of money on Delphi and Embarcadero really needs to get its act together when pushing out major releases so that it is at least relatively bug-free. Tokyo seems to be very unreliable...

UPDATE 20171201: For Android, I would very highly recommend the KastriFree library by Dave Nottage which implements a simple and easy to use message based notification mechanism. I have been using it in my Android app, and it works flawlessly!

Probative answered 6/9, 2017 at 4:30 Comment(10)
Are you writing a keyboard? OR an app that's using a keyboard? Because there is no way to reliably know the height of the software keyboard in an app, there's no API to request that from the client. If Delphi is claiming they can tell you that, they're making guesses at it- there is no way to actually reliably detect it.Marijuana
I am writing an app that uses the keyboard already available in Android. Weird that the documentation indicates that the Bounds variable would have the bounds of the keyboard, if what you say is true...Probative
THere's also no way to reliably know when a virtual keyboard is being shown. There's ways to guess, but none of those ways are always right. It sounds like Delphi is trying to do things it can do on other platforms that it just can't do on Android. That will result in either it not working on this platform at all, or it working under only certain situations.Marijuana
@GabeSechan - the OnVirtualKeyboardShown event triggers correctly when the keyboard is shown and the KeyboardVisible variable is correctly set to True when the event is triggered. So that part works correctly...Probative
That seems to be reported as RSP-14004.Nyaya
@Nyaya - Thanks - that does seem to hint at a related issue. But they seem to be able to get valid values from Bounds. See the values for bounds I am showing during debug - they are essentially unusable...Probative
@Probative I wrote one of the most popular keyboards on Android. There is NO api that tells the app when the keyboard is shown. There's some hacks people use to try and guess it, but those hacks have both false negatives and false positives and should not be used. I would not expect this API to work reliably. The framework jsut does not provide this information.Marijuana
@GabeSechan - Thanks. BTW I was not questioning your expertise in this matter - was just reporting back facts as I see them :) Ultimately, I just want this functionality to work reliably.Probative
@Rohit, were you able to solve the keyboard problem? I'm using Delphi 10.2 which Embarcadero knows has this problem, but I don't know if there is a solution. Thanks!Putdown
@Putdown I have been using KastriFree by Dave Nottage which has been very effective in addressing this issue for Android. You can find the repository on GitHub. I have updated the question with this solution option.Probative

© 2022 - 2024 — McMap. All rights reserved.