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