Skip to content

Commit 4d23674

Browse files
committed
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 ionic-team#156, ionic-team#117, ionic-team#132, ionic-team#134
1 parent 0408e72 commit 4d23674

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/android/CDVIonicKeyboard.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import android.view.View;
1616
import android.view.ViewTreeObserver;
1717
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
18+
import android.view.Window;
1819
import android.view.inputmethod.InputMethodManager;
1920

2021
// import additionally required classes for calculating screen height
@@ -125,13 +126,7 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH
125126
private void possiblyResizeChildOfContent() {
126127
int usableHeightNow = computeUsableHeight();
127128
if (usableHeightNow != usableHeightPrevious) {
128-
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
129-
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
130-
if (heightDifference > (usableHeightSansKeyboard/4)) {
131-
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
132-
} else {
133-
frameLayoutParams.height = usableHeightSansKeyboard;
134-
}
129+
frameLayoutParams.height = usableHeightNow;
135130
mChildOfContent.requestLayout();
136131
usableHeightPrevious = usableHeightNow;
137132
}
@@ -140,7 +135,14 @@ private void possiblyResizeChildOfContent() {
140135
private int computeUsableHeight() {
141136
Rect r = new Rect();
142137
mChildOfContent.getWindowVisibleDisplayFrame(r);
143-
return (r.bottom - r.top);
138+
return isFullScreen() ? r.bottom - r.top : r.height();
139+
}
140+
141+
private boolean isFullScreen() {
142+
final Window window = cordova.getActivity().getWindow();
143+
// Flag set by status bar plugin to make content full screen
144+
int fullScreenFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
145+
return (window.getDecorView().getSystemUiVisibility() & fullScreenFlag) == fullScreenFlag;
144146
}
145147
};
146148

0 commit comments

Comments
 (0)