Skip to content

Commit 779e7f0

Browse files
committed
Issue apache#110 fix
Statusbar overlay view resize with keyboard added StatusBarViewHelper in plugin.xml
1 parent adcee9f commit 779e7f0

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
<platform name="android">
4040
<source-file src="src/android/StatusBar.java" target-dir="src/org/apache/cordova/statusbar" />
41+
<source-file src="src/android/StatusBarViewHelper.java" target-dir="src/org/apache/cordova/statusbar" />
4142

4243
<config-file target="res/xml/config.xml" parent="/*">
4344
<feature name="StatusBar">

src/android/StatusBar.java

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
5454
this.cordova.getActivity().runOnUiThread(new Runnable() {
5555
@Override
5656
public void run() {
57+
//https://github.com/apache/cordova-plugin-statusbar/issues/110
58+
//This corrects keyboard behaviour when overlaysWebView is true
59+
StatusBarViewHelper.assistActivity(cordova.getActivity());
60+
5761
// Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially
5862
// by the Cordova.
5963
Window window = cordova.getActivity().getWindow();

src/android/StatusBarViewHelper.java

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.apache.cordova.statusbar;
2+
3+
import android.app.Activity;
4+
import android.graphics.Rect;
5+
import android.util.Log;
6+
import android.view.View;
7+
import android.view.ViewTreeObserver;
8+
import android.widget.FrameLayout;
9+
10+
public class StatusBarViewHelper {
11+
12+
// For more information, see https://issuetracker.google.com/issues/36911528
13+
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
14+
15+
//This solution was based off of
16+
//https://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#answer-42261118
17+
18+
private View mChildOfContent;
19+
private int usableHeightPrevious;
20+
private FrameLayout.LayoutParams frameLayoutParams;
21+
private Activity activity;
22+
23+
static void assistActivity(Activity activity) {
24+
new StatusBarViewHelper(activity);
25+
}
26+
27+
private StatusBarViewHelper(Activity a) {
28+
activity = a;
29+
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
30+
mChildOfContent = content.getChildAt(0);
31+
32+
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
33+
public void onGlobalLayout() {
34+
possiblyResizeChildOfContent();
35+
}
36+
});
37+
38+
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
39+
}
40+
41+
private void possiblyResizeChildOfContent() {
42+
int usableHeightNow = computeUsableHeight();
43+
if (usableHeightNow != usableHeightPrevious) {
44+
frameLayoutParams.height = usableHeightNow;
45+
mChildOfContent.requestLayout();
46+
usableHeightPrevious = usableHeightNow;
47+
}
48+
}
49+
50+
private int computeUsableHeight() {
51+
Rect r = new Rect();
52+
mChildOfContent.getWindowVisibleDisplayFrame(r);
53+
int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility();
54+
boolean isFullscreen = ((uiOptions | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == uiOptions);
55+
56+
//If not fullscreen, then we have to take the status bar into consideration (represented by r.top)
57+
//r.bottom defines the keyboard, or navigation bar, or both.
58+
59+
return isFullscreen ? r.bottom : r.bottom - r.top;
60+
}
61+
}

0 commit comments

Comments
 (0)