Skip to content

fix(android): check current orientation when redisplaying system keyboard#11604

Merged
jahorton merged 2 commits intomasterfrom
fix/android/sys-keyboard-orientation
Jun 10, 2024
Merged

fix(android): check current orientation when redisplaying system keyboard#11604
jahorton merged 2 commits intomasterfrom
fix/android/sys-keyboard-orientation

Conversation

@jahorton
Copy link
Copy Markdown
Contributor

@jahorton jahorton commented May 29, 2024

Replaces #11484.

Noting two different comments from #11484, I now suspect the issue is that the system keyboard simply lacked "on resume"-style orientation checking. After some investigation, I think I've identified the correct place for it.

The new code essentially duplicates the following in-app block for handling orientation changes when the app is restored:

// onConfigurationChanged() only triggers when device is rotated while app is in foreground
// This handles when device is rotated while app is in background
// using KMManager.getOrientation() since getConfiguration().orientation is unreliable #10241
int newOrientation = KMManager.getOrientation(context);
if (newOrientation != lastOrientation) {
lastOrientation = newOrientation;
Configuration newConfig = this.getResources().getConfiguration();
KMManager.onConfigurationChanged(newConfig);
}

While a bit WET, note that a special state variable is needed for tracking. Both would lie within "app" space, so I suppose I could DRY it out if this approach is in fact the solution.

User Testing

TEST_KEYBOARD_REPEATED_RESTORE

  1. Install the PR build of Keyman for Android on an Android device/emulator Android 13 (SDK 33)
  2. Ensure the keyboard may be used as the system keyboard.
  3. Pick any application and start editing text via the Keyman system keyboard (without changing orientation).
  4. Dismiss the keyboard (by finishing your input and selecting something that doesn't need the keyboard).
  5. Change your device's orientation: if in 'portrait', go to 'landscape' mode and vice-versa.
  6. Re-activate the keyboard.
  7. Repeat steps 3 through 6 at least five times, verifying that the OSK always displays with the correct width for the device's orientation.

Sadly, just this isn't enough to get a repro with the current state of master for me within Android Studio's emulator.

@keymanapp-test-bot keymanapp-test-bot bot added has-user-test user-test-required User tests have not been completed labels May 29, 2024
@keymanapp-test-bot
Copy link
Copy Markdown

keymanapp-test-bot bot commented May 29, 2024

User Test Results

Test specification and instructions

  • TEST_KEYBOARD_REPEATED_RESTORE (PASSED): ): I tested this issue with the attached "Keyman 18.0.45-alpha-test-11604" build on an Android 13.0 (emulator and physical) environment: Here is my observation. (notes)

Test Artifacts

@keymanapp-test-bot keymanapp-test-bot bot added this to the A18S3 milestone May 29, 2024
@jahorton jahorton marked this pull request as ready for review May 29, 2024 06:00
@mcdurdin
Copy link
Copy Markdown
Member

ref #10054

@dinakaranr
Copy link
Copy Markdown

Test Results

  • TEST_KEYBOARD_REPEATED_RESTORE (FAILED): I tested this issue with the attached "Keyman 18.0.45-alpha-test-11604" build on an Android 13.0 (emulator and physical) environment: Here is my observation.
  1. Installed the "Keyman 18.0.45.apk" file and gave all permissions to the application.

  2. Checked the "Enable Keyman as system-wide keyboard" and set the keyboard as the default keyboard box on the settings page.

  3. Message/Note/Browser/Google_Docs application and enter some text.

  4. Cleared the background applications.Change your device's orientation from 'portrait' to 'landscape' mode and vice versa.
    Here, A) I observed that the half keyboard screen appears when switching the mobile viewport from 'portrait' to 'landscape' mode.
    This behavior happens consistently in the emulator for 5 seconds, but the mobile device shows 1 to 2 seconds.

  5. B) On the 'portrait' view, Change the keyboard size from default to maximum size.

  6. On the 'landscape' view, open any app and click in the search or text box.

  7. Here, the keyboard does not appear for the first time. or the keyboard size appears on full screen or in large size.

If the above problem does not appear, then repeat any other app on the landscape view. Please refer to the video file.
https://github.com/keymanapp/keyman/assets/19683059/9787d1e7-bf98-48ce-b8e9-2de6d5c67a47
https://github.com/keymanapp/keyman/assets/19683059/c23220f4-2d24-4b16-a25b-01280fc4a9fb

@jahorton
Copy link
Copy Markdown
Contributor Author

jahorton commented May 30, 2024

Following up on @dinakaranr's previous comment:

FullScreenKeyboard_TrailOne.mp4

See timestamp 2:01 - the keyboard launches far too tall (portrait height) in landscape mode. (Upon opening a different app than was previously hosting the system keyboard.)

That's the only (related) erroneous timestamp I recognize in that video - did I miss anything?

I did notice that at earlier timestamps, re-entering the main app didn't relaunch the keyboard, but that's unrelated - I didn't touch any main-app code in this PR.


FullScreenKeyboard1_TrailTwo.mp4

See timestamp 2:09-2:22 - (triggers at 2:22) after force-killing all apps that were hosting a system keyboard instance, launching a new one in landscape had the same issue - the keyboard was far too tall.

Also see timestamp 1:34 - 1:47 - an earlier point in the test sequence where the same force-kill was applied, but things worked normally afterward. The behavior should have been the same for both timestamps, I'd think.

@jahorton
Copy link
Copy Markdown
Contributor Author

jahorton commented May 30, 2024

Finally got one locally, after setting up an identical emulated device target to what was in those videos + also setting a very tall portrait height.

I decided to locally insert the following logging line within onStartInput, right after the int newOrientation = [...] line. Here's the most recent set of logs:

SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: true, new: 1, last: 2
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 1, last: 1
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: true, new: 1, last: 1
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: true, new: 1, last: 2
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 1, last: 1
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: true, new: 1, last: 1
SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2

For clarity, 1 = portrait, 2 = landscape. (Starting value: 0, for "unknown".) They're the internal values used here; the int form of the defined constants. It was with this logging state that I got the repro. (I've also omitted significant history where it didn't trigger.)

restarting is simply the value of the onStartInput parameter. It doesn't seem to match a fully terminated + restarted keyboard to me, noting its behavior through the logs - we're hardly ever seeing the initial-state of 0 for "unknown orientation".

It's also worth noting some observations here:

SystemKeyboard.onStartInput is not only called when first loading up within an app. It's actually called every time the activity changes or the orientation changes! Keyboard not active? Doesn't matter! In landscape and returning to the home screen (which is forced portrait)? Yep, that's an "orientation change" and will trigger onStartInput, despite no visible keyboard. That said, actually displaying the keyboard is such a change and will also trigger onStartInput.

I was originally testing with a "Nexus 5 API 32" target. With that device, I never saw a skip from new: 1, last: 1 to new: 2, last: 2 or vice-versa. Apparently Nexus 5s call onStartInput more proactively - there were always intermediate reports where we could see the transition.

Also note that such a skip does not guarantee that the wrong layout will happen. I've seen similar "skipping" transitions on the emulated Nexus 5 where the keyboard still showed up properly in the intended orientation.

Finally... note that the keyboard did at least detect the correct orientation - it just erroneously thought it was already in that orientation and so didn't bother updating.

@jahorton
Copy link
Copy Markdown
Contributor Author

Got another one, this time with landscape height in portrait (via portrait-locked app):

image

I added in temp-logging in the onConfigurationChanged handler this time, so it'll show up in the "recent logs".

2024-05-30 10:38:18.225 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 1, last: 1
2024-05-30 10:38:19.243 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: true, new: 2, last: 1
2024-05-30 10:38:19.441 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  change-event - new: 2, old: 2
2024-05-30 10:38:19.860 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2
2024-05-30 10:38:20.850 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2
2024-05-30 10:38:21.396 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: true, new: 2, last: 2
2024-05-30 10:38:21.435 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  change-event - new: 1, old: 2
2024-05-30 10:38:21.747 17763-17763 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 1, last: 1

I kept the timestamps this time, since that highlights how close in succession the last three logging messages were. No guarantees that it's significant, but I figured that highlighting the info helps here more than it hurts (log simplicity/readability).

@jahorton
Copy link
Copy Markdown
Contributor Author

Ooh, managed to retrigger that one fairly quickly this time... and I added in one extra bit into the logs. Same pattern as before, but now we're also logging the JS calls being passed to KMW.

2024-05-30 10:50:13.736 20916-20916 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2
2024-05-30 10:50:13.847 20916-20916 KMKeyboard              com.tavultesoft.kmapro.debug         I  new: JS calls to KMW - resetContext();setBannerOptions(true);
2024-05-30 10:50:14.402 20916-20916 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: true, new: 2, last: 2
2024-05-30 10:50:14.436 20916-20916 SystemKeyboard          com.tavultesoft.kmapro.debug         I  change-event - new: 1, old: 2
2024-05-30 10:50:16.906 20916-20916 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 1, last: 1
2024-05-30 10:50:17.206 20916-20916 KMKeyboard              com.tavultesoft.kmapro.debug         I  new: JS calls to KMW - setBannerHTML("<!-- Custom banner theme --><div style=\"background: white; width: 100%; height: 100%; position: absolute; left: 0; top: 0; display: flex\">  <!-- svg path is relative to assets\/ folder -->  <img src=\"banner\/keyman_banner.svg\" style=\"height:60%; background: white; display: block; margin: auto 2%;\">  <!-- Tri-color line -->  <div style='height: 7%; left: 0; position: absolute; bottom: 0; width: 56%; background: #F68924'><\/div>  <div style='height: 7%; left: 56%; position: absolute; bottom: 0; width: 23%; background: #CC3846'><\/div>  <div style='height: 7%; left: 79%; position: absolute; bottom: 0; width: 21%; background: #79C3DA'><\/div><\/div>");showBanner(true);resetContext();setBannerOptions(true);setBannerHTML("<!-- Custom banner theme --><div style=\"background: white; width: 100%; height: 100%; position: absolute; left: 0; top: 0; display: flex\">  <!-- svg path is relative to assets\/ folder -->  <img src=\"banner\/keyman_banner.svg\" style=\"height:60%; background: white; display: block; margin: auto 2%;\">  <!-- Tri-color line -->  <div style='height: 7%; left: 0; position: absolute; bottom: 0; width: 56%; background: #F68924'><\/div>  <div style='height: 7%; left: 56%; position: absolute; bottom: 0; width: 23%; background: #CC3846'><\/div>  <div style='height: 7%; left: 79%; position: absolute; bottom: 0; width: 21%; background: #79C3DA'><\/div><\/div>");setBannerHeight(110);setOskWidth(393);setOskHeight(275);keyman.hideGlobeHint();;resetContext();setBannerOptions(true);updateKMText({"text":""});updateKMText({"text":""});updateKMSelectionRange(0,0);

The concatenated JS line is a bit of a beast, so here's a prettification of its contents:

setBannerHTML("<!-- Custom banner theme --><div style=\"background: white; width: 100%; height: 100%; position: absolute; left: 0; top: 0; display: flex\">  <!-- svg path is relative to assets\/ folder -->  <img src=\"banner\/keyman_banner.svg\" style=\"height:60%; background: white; display: block; margin: auto 2%;\">  <!-- Tri-color line -->  <div style='height: 7%; left: 0; position: absolute; bottom: 0; width: 56%; background: #F68924'><\/div>  <div style='height: 7%; left: 56%; position: absolute; bottom: 0; width: 23%; background: #CC3846'><\/div>  <div style='height: 7%; left: 79%; position: absolute; bottom: 0; width: 21%; background: #79C3DA'><\/div><\/div>");
showBanner(true);
resetContext();
setBannerOptions(true);
setBannerHTML("<!-- Custom banner theme --><div style=\"background: white; width: 100%; height: 100%; position: absolute; left: 0; top: 0; display: flex\">  <!-- svg path is relative to assets\/ folder -->  <img src=\"banner\/keyman_banner.svg\" style=\"height:60%; background: white; display: block; margin: auto 2%;\">  <!-- Tri-color line -->  <div style='height: 7%; left: 0; position: absolute; bottom: 0; width: 56%; background: #F68924'><\/div>  <div style='height: 7%; left: 56%; position: absolute; bottom: 0; width: 23%; background: #CC3846'><\/div>  <div style='height: 7%; left: 79%; position: absolute; bottom: 0; width: 21%; background: #79C3DA'><\/div><\/div>");
setBannerHeight(110);
setOskWidth(393);
setOskHeight(275);
keyman.hideGlobeHint();
;
resetContext();
setBannerOptions(true);
updateKMText({"text":""});
updateKMText({"text":""});
updateKMSelectionRange(0,0);

The values do line up within the WebView when accounting for window.devicePixelRatio, which is 2.75. (Oddly, that's not explicitly applied to width, but that doesn't seem to matter?)

@jahorton
Copy link
Copy Markdown
Contributor Author

jahorton commented May 30, 2024

Well, I went and added even more logging before this next trigger:

2024-05-30 12:04:33.933 32032-32032 SystemKeyboard          com.tavultesoft.kmapro.debug         I  change-event - new: 2, old: 1
2024-05-30 12:04:33.933 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:33.934 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:33.934 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:33.935 32032-32032 KMKeyboard              com.tavultesoft.kmapro.debug         I  new: setting kbd config with width: 829, osk-height: 1102, banner-height: 137
2024-05-30 12:04:33.938 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:33.939 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:33.939 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:33.940 32032-32032 KMKeyboard              com.tavultesoft.kmapro.debug         I  new: setting kbd config with width: 829, osk-height: 1102, banner-height: 137
2024-05-30 12:04:33.999 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:33.999 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 1
2024-05-30 12:04:34.002 32032-32032 KMKeyboard              com.tavultesoft.kmapro.debug         I  new: setting kbd config with width: 829, osk-height: 1102, banner-height: 137
2024-05-30 12:04:34.055 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 2

2024-05-30 12:04:34.349 32032-32032 KMKeyboard              com.tavultesoft.kmapro.debug         I  new: JS calls to KMW - setBannerHTML("<!-- Custom banner theme --><div style=\"background: white; width: 100%; height: 100%; position: absolute; left: 0; top: 0; display: flex\">  <!-- svg path is relative to assets\/ folder -->  <img src=\"banner\/keyman_banner.svg\" style=\"height:60%; background: white; display: block; margin: auto 2%;\">  <!-- Tri-color line -->  <div style='height: 7%; left: 0; position: absolute; bottom: 0; width: 56%; background: #F68924'><\/div>  <div style='height: 7%; left: 56%; position: absolute; bottom: 0; width: 23%; background: #CC3846'><\/div>  <div style='height: 7%; left: 79%; position: absolute; bottom: 0; width: 21%; background: #79C3DA'><\/div><\/div>");showBanner(true);resetContext();setBannerOptions(true);updateKMText({"text":""});updateKMText({"text":""});updateKMSelectionRange(0,0);setBannerHTML("<!-- Custom banner theme --><div style=\"background: white; width: 100%; height: 100%; position: absolute; left: 0; top: 0; display: flex\">  <!-- svg path is relative to assets\/ folder -->  <img src=\"banner\/keyman_banner.svg\" style=\"height:60%; background: white; display: block; margin: auto 2%;\">  <!-- Tri-color line -->  <div style='height: 7%; left: 0; position: absolute; bottom: 0; width: 56%; background: #F68924'><\/div>  <div style='height: 7%; left: 56%; position: absolute; bottom: 0; width: 23%; background: #CC3846'><\/div>  <div style='height: 7%; left: 79%; position: absolute; bottom: 0; width: 21%; background: #79C3DA'><\/div><\/div>");setBannerHeight(137);setOskWidth(829);setOskHeight(1102);keyman.hideGlobeHint();;setBannerHTML("<!-- Custom banner theme --><div style=\"background: white; width: 100%; height: 100%; position: absolute; left: 0; top: 0; display: flex\">  <!-- svg path is relative to assets\/ folder -->  <img src=\"banner\/keyman_banner.svg\" style=\"height:60%; background: white; display: block; margin: auto 2%;\">  <!-- Tri-color line -->  <div style='height: 7%; left: 0; position: absolute; bottom: 0; width: 56%; background: #F68924'><\/div>  <div style='height: 7%; left: 56%; position: absolute; bottom: 0; width: 23%; background: #CC3846'><\/div>  <div style='height: 7%; left: 79%; position: absolute; bottom: 0; width: 21%; background: #79C3DA'><\/div><\/div>");setBannerHeight(137);setOskWidth(829);setOskHeight(1102);keyman.hideGlobeHint();;

2024-05-30 12:04:34.586 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 2
2024-05-30 12:04:34.842 32032-32032 SystemKeyboard          com.tavultesoft.kmapro.debug         I  restarting: false, new: 2, last: 2
2024-05-30 12:04:34.947 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 2
2024-05-30 12:04:35.201 32032-32032 KMKeyboard              com.tavultesoft.kmapro.debug         I  new: JS calls to KMW - resetContext();setBannerOptions(true);updateKMText({"text":""});updateKMText({"text":""});updateKMSelectionRange(0,0);
2024-05-30 12:04:35.221 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 2
2024-05-30 12:04:35.281 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 2
2024-05-30 12:04:35.364 32032-32032 KMManager               com.tavultesoft.kmapro.debug         I  new: getOrientation during getKeyboardHeight: 2

(newlines added for emphasis)

That's... a surprising number of getOrientation calls after the passing of keyboard-dimension data to KMW. It would appear that the SystemKeyboard.java getConfigurationChanged signals when a change will happen but hasn't yet processed?

Also, the calls just before the JS stuff passes through, before the first newline... is interestingly placed. The one spot where that's referred to outside of the orientation flow I've been tracing otherwise... is in onComputeInsets.

public void onComputeInsets(InputMethodService.Insets outInsets) {

int bannerHeight = KMManager.getBannerHeight(this);
int kbHeight = KMManager.getKeyboardHeight(this);

@jahorton
Copy link
Copy Markdown
Contributor Author

jahorton commented May 30, 2024

@keymanapp-test-bot retest all

Noting the system-keyboard order of operations, it seems that the best approach may be to nix the onConfigurationChanged handler in SystemKeyboard in favor of just the one in onStartInput. I'm having trouble getting a repro afterward, with both the Pixel 4 and the Nexus 5. (Since they behaved a bit differently, I wanted to check if fixing one broke the other.)

The latest commit makes this change, so it's time for another round of testing.

@keymanapp-test-bot keymanapp-test-bot bot added user-test-required User tests have not been completed and removed user-test-failed labels May 30, 2024
@mcdurdin
Copy link
Copy Markdown
Member

I've got the latest build installed. Will report back as I use it.

@dinakaranr
Copy link
Copy Markdown

Test Results

TEST_KEYBOARD_REPEATED_RESTORE (PASSED): I tested this issue with the attached "Keyman 18.0.45-alpha-test-11604" build on an Android 13.0 (emulator and physical) environment: Here is my observation.

  1. Installed the "Keyman 18.0.45.apk" file and gave all permissions to the application.
  2. Checked the "Enable Keyman as system-wide keyboard" and set the keyboard as the default keyboard box on the settings page.
  3. Message/Note/Browser/Google_Docs application and enter some text.
  4. Cleared the background applications.Change your device's orientation from 'portrait' to 'landscape' mode and vice versa.
    Here, A) No half keyboard screen appears when switching the mobile viewport from 'portrait' to 'landscape' mode.
    B) On the 'landscape' view, the keyboard appears for the first time. the keyboard size does not appear in large size. It looks better performance as of now. It works fine. Thank you.

@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-required User tests have not been completed label May 30, 2024
@mcdurdin
Copy link
Copy Markdown
Member

So far I have not experienced any keyboard sizing issues with this build. Continuing to use it on my phone.

@mcdurdin
Copy link
Copy Markdown
Member

If this works as well as it seems to be so far, we need to update KMSample2 in the same way, pass this knowledge on to the Keyboard App Builder team, and publish this as a release note for other Keyman Engine for Android integrators.

Comment on lines +150 to +151
// This method (likely) includes the IME equivalent to `onResume` for `Activity`-based classes,
// making it an important time to detect orientation changes.
Copy link
Copy Markdown
Contributor Author

@jahorton jahorton May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This method (likely) includes the IME equivalent to `onResume` for `Activity`-based classes,
// making it an important time to detect orientation changes.
// This method (likely) includes the IME equivalent to `onResume` for `Activity`-based classes,
// making it an important time to detect orientation changes.
//
// In fact, it appears to be called whenever the view / activity layout changes, after any
// orientation changes have fully resolved.

@mcdurdin
Copy link
Copy Markdown
Member

mcdurdin commented Jun 2, 2024

Screenshot_20240602_085919_Slack.jpg

well it happened again... Restoring the keyboard after not using it for a while. Only this time, height is good and width is bad... I was never seeing wrong width on 17.0.325

Comment on lines -203 to -209
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation != lastOrientation) {
lastOrientation = newConfig.orientation;
KMManager.onConfigurationChanged(newConfig);
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds as if this part of the code may be needed for getting proper landscape width, based upon #11604 (comment). But, with it here, it's possible for an update to lastOrientation here to block proper height-setting in onStartInput.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:

public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
RelativeLayout.LayoutParams params = KMManager.getKeyboardLayoutParams();
this.setLayoutParams(params);
int bannerHeight = KMManager.getBannerHeight(context);
int oskHeight = KMManager.getKeyboardHeight(context);
if (this.htmlBannerString != null && !this.htmlBannerString.isEmpty()) {
setHTMLBanner(this.htmlBannerString);
}
loadJavascript(KMString.format("setBannerHeight(%d)", bannerHeight));
loadJavascript(KMString.format("setOskWidth(%d)", newConfig.screenWidthDp));
loadJavascript(KMString.format("setOskHeight(%d)", oskHeight));

The Configuration object we get here sources the keyboard width as seen in the code block linked above.

Meanwhile, the height values there are determined via our orientation-detection code:

public static int getKeyboardHeight(Context context) {
int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height);
SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
int orientation = getOrientation(context);
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight);
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight);
}

Copy link
Copy Markdown
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved together with #11722

@mcdurdin mcdurdin modified the milestones: A18S3, A18S4 Jun 7, 2024
jahorton added a commit that referenced this pull request Jun 10, 2024
@jahorton jahorton merged commit 3ac7aa4 into master Jun 10, 2024
@jahorton jahorton deleted the fix/android/sys-keyboard-orientation branch June 10, 2024 05:15
@keyman-server
Copy link
Copy Markdown
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.53-alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants