B4A Library IME2 Library

I have been having a lot of trouble lately with layouts being corrupted when rotating a device with the soft keyboard open.

The problem stems from trying to use the IME library HeightChanged event. Unfortunately Android provides no direct way to determine whether the soft keyboard is shown or not so the IME.HeightChanged event uses a bit of a hack. to detect this. The problem that I have found is that, particularly when rotating a device with the keyboard is open, different soft keyboards and different devices produce different erroneous layouts after rotation, particularly in split mode. In some devices it works well, others produce poor results.

The IME2 library provides some extra methods to help sort this problem and the KeyboardTest app uses them to demonstrate obtaining the correct layout after device rotation with the keyboard open in all normal and split mode combinations in portrait and landscape. This app works on all my devices but may not work on yours.

Erel posted a different possible workaround here.
It is worth trying that first to see if it works for you but it didn't work for me in all circumstances - basically because you can get multiple spurious HeightChanged events during/after rotation and his solution just accepts the first one.

If anyone has something simpler to solve this problem I would welcome trying it.

From the XML for the IME2 library.

 

Attachments

  • IME2_V1.00.zip
    20.5 KB · Views: 932

JohnC

Expert
Licensed User
Longtime User
I had a hunch when there wasn't a clean solution for your test app bug last week, that you might create a lib to fix it
 

Star-Dust

Expert
Licensed User
Longtime User
The library is clean and just provides more information - but the HeightChanged event in B4A code that does the work is pretty gruesome
I don't understand much about Java, but I guess it depends on it being an old library. One of the first made. Today it would be done differently
 

agraham

Expert
Licensed User
Longtime User
I don't understand much about Java, but I guess it depends on it being an old library. One of the first made. Today it would be done differently
No it wouldn't, don't think I haven't tried to do it better. Android still sucks deeply in many respects and this is one of the most obvious.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
At last !
It's only taken them twelve years since first release to correct this omission!
 

Star-Dust

Expert
Licensed User
Longtime User

agraham

Expert
Licensed User
Longtime User
I do wonder, though without any evidence to back it up, whether this is a sign of Microsoft influence on Android. Keyboard handling on the Surface Duo must have needed some changes and I know that Microsoft has been posting Android code changes to the repository. I have noticed that the MIcrosoft SwiftKey keyboard causes the worst of these layout problems and I assume that an enhanced version of it will be the default keyboard on Duo.
 

AnandGupta

Expert
Licensed User
Longtime User
I think you are 100% right.

MS is better influencer than mere users.

Regards,

Anand
 

cxbs

Active Member
Licensed User
Longtime User
Hello agraham!

When set <item name="android:windowTranslucentStatus">true</item>
no work!

SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
<resources>
<style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FFFFFF</item>
<item name="colorPrimaryDark">#007CF5</item>
<item name="colorAccent">#07c160</item>
<item name="android:colorControlNormal">#aaaaaa</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowLightStatusBar">true</item>

<item name="android:windowTranslucentStatus">true</item>

<item name="android:windowTranslucentNavigation">false</item>
<item name="android:fitsSystemWindows">true</item>
</style>
</resources>
)
 

cxbs

Active Member
Licensed User
Longtime User
Whatever it is that "no work" it will not be due to the IME2 library.
Thank you for your reply. I'm not sure what caused it. Maybe it's incompatibility that makes me unable to work!
 

alimanam3386

Active Member
Licensed User
Longtime User
I have been having a lot of trouble lately with layouts being corrupted when rotating a device with the soft keyboard open.

I am just trying to run your attached source code however I get this error ( B4A Ver 10.7 )

in Manifest :
B4X:
AddManifestText(<edtSource android:imeOptions="flagNoExtractUi|flagNoFullscreen" />)


The error when compiling :
B4X:
AndroidManifest.xml:14: error: unexpected element <edtSource> found in <manifest>.
 

agraham

Expert
Licensed User
Longtime User
They affect the behaviour of the IME in landscape mode. The important one is flagNoFullscreen which stops the IME throwing up it's own EditText for input in landscape mode and allows the original EditText to be edited - important in my BasicIDE code editor - and it did work before.

I added flagNoExtractUi as I found it used in someone else's solution to similar problems with the IME as I was having (probably on Stack Overflow) together with flagNoFullscreen but from the description below iit s probably superfluous. However I don't remember the "it may become deprecated in the future" comment when I was originally researching this!

EditorInfo | Android Developers

 

Erel

B4X founder
Staff member
Licensed User
Longtime User

agraham

Expert
Licensed User
Longtime User
someone added an EditText named edtSource.
It was my EditText called edtSource that it was intended to affect. However you are probably correct that it was doing nothing as I looked into the demo source and found this ?
B4X:
    ' keep edtSource visible in landscape
    jo = edtSource
    jo.RunMethod("setImeOptions", Array(33554432)) ' IME_FLAG_NO_FULLSCREEN
So the manifest line was probably a hangover from earlier attempts that I should have removed but didn't. I can't remember things like I used to be able to when I was young(er)

@alimanam3386 Just remove the line from the manifest - as Erel said it was doing nothing useful.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…