Skip to content

Commit

Permalink
Merge pull request #11722 from keymanapp/fix/android/split-layout-and…
Browse files Browse the repository at this point in the history
…-rescale

fix(android): fix keyboard size after rotation and restore via onSizeChanged, after layout
  • Loading branch information
jahorton authored Jun 10, 2024
2 parents 3ac7aa4 + d868337 commit b8943ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/KMEA/app/src/main/assets/android-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function setOskHeight(h) {

function setOskWidth(w) {
if(w > 0) {
oskWidth = w;
oskWidth = w / window.devicePixelRatio;
}
}

Expand Down
38 changes: 27 additions & 11 deletions android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ protected boolean updateSelectionRange() {
int selMin = icText.selectionStart, selMax = icText.selectionEnd;

int textLength = rawText.length();

if (selMin < 0 || selMax < 0) {
// There is no selection or cursor
// Reference https://developer.android.com/reference/android/text/Selection#getSelectionEnd(java.lang.CharSequence)
return false;
} else if (selMin > textLength || selMax > textLength) {
// Selection is past end of existing text -- should not be possible but we
// Selection is past end of existing text -- should not be possible but we
// are seeing it happen; #11506
return false;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ protected boolean updateSelectionRange() {
selMin -= pairsAtStart;
selMax -= (pairsAtStart + pairsSelected);
this.loadJavascript(KMString.format("updateKMSelectionRange(%d,%d)", selMin, selMax));

return true;
}

Expand Down Expand Up @@ -262,7 +262,7 @@ public void initKMKeyboard(final Context context) {
// When `.isTestMode() == true`, the setWebContentsDebuggingEnabled method is not available
// and thus will trigger unit-test failures.
if (!KMManager.isTestMode() && (
(context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 ||
(context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 ||
KMManager.getTier(null) != KMManager.Tier.STABLE
)) {
// Enable debugging of WebView via adb. Not used during unit tests
Expand Down Expand Up @@ -443,26 +443,42 @@ public void onDestroy() {
dismissHelpBubble();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

RelativeLayout.LayoutParams params = KMManager.getKeyboardLayoutParams();
// I suspect this is the part we should actually be calling directly...
this.setLayoutParams(params);
this.invalidate();
this.requestLayout();

this.dismissHelpBubble();

if(this.getShouldShowHelpBubble()) {
this.showHelpBubbleAfterDelay(2000);
}
}

@Override
public void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
int bannerHeight = KMManager.getBannerHeight(context);
int oskHeight = KMManager.getKeyboardHeight(context);

if(bannerHeight + oskHeight != height) {
// We'll proceed, but cautiously and with logging.
KMLog.LogInfo(TAG, "Height mismatch: onSizeChanged = " + height + ", our version = " + (bannerHeight + oskHeight));
}

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("setOskWidth(%d)", width));
// Must be last - it's the one that triggers a Web-engine layout refresh.
loadJavascript(KMString.format("setOskHeight(%d)", oskHeight));

this.dismissHelpBubble();

if(this.getShouldShowHelpBubble()) {
this.showHelpBubbleAfterDelay(2000);
}
}

public void dismissSuggestionMenuWindow() {
Expand Down

0 comments on commit b8943ea

Please sign in to comment.