From 4d23674036efa37f176c52ab88b7cb819bb61cf5 Mon Sep 17 00:00:00 2001 From: David Martin Date: Tue, 21 Sep 2021 12:38:24 +0800 Subject: [PATCH] Correct Android Screen Size (resizeOnFullScreen true - not in full screen) If you set the preference for resizeOnFullScreen and you do not have your app running in either fullscreen mode (via StatusBar) or Immersive fullscreen mode (via cordova-plugin-fullscreen) the height is calculated wrong and some content between 8 and 40 pixels dependant on device will be off the bottom of the screen. This update looks for isFullScreen Based on and fixes #156, #117, #132, #134 --- src/android/CDVIonicKeyboard.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/android/CDVIonicKeyboard.java b/src/android/CDVIonicKeyboard.java index b7ec455..544d0ae 100644 --- a/src/android/CDVIonicKeyboard.java +++ b/src/android/CDVIonicKeyboard.java @@ -15,6 +15,7 @@ import android.view.View; import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.view.Window; import android.view.inputmethod.InputMethodManager; // import additionally required classes for calculating screen height @@ -125,13 +126,7 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH private void possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevious) { - int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); - int heightDifference = usableHeightSansKeyboard - usableHeightNow; - if (heightDifference > (usableHeightSansKeyboard/4)) { - frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; - } else { - frameLayoutParams.height = usableHeightSansKeyboard; - } + frameLayoutParams.height = usableHeightNow; mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } @@ -140,7 +135,14 @@ private void possiblyResizeChildOfContent() { private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); - return (r.bottom - r.top); + return isFullScreen() ? r.bottom - r.top : r.height(); + } + + private boolean isFullScreen() { + final Window window = cordova.getActivity().getWindow(); + // Flag set by status bar plugin to make content full screen + int fullScreenFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + return (window.getDecorView().getSystemUiVisibility() & fullScreenFlag) == fullScreenFlag; } };