77import android .content .res .Configuration ;
88import android .graphics .Color ;
99import android .net .Uri ;
10+ import android .os .Build ;
1011import android .os .Bundle ;
1112import android .util .DisplayMetrics ;
1213import android .util .Log ;
@@ -53,16 +54,24 @@ protected void onCreate(Bundle savedInstanceState) {
5354 Log .v (Countly .TAG , "[TransparentActivity] onCreate, configPortrait x: [" + configPortrait .x + "] y: [" + configPortrait .y + "] width: [" + configPortrait .width + "] height: [" + configPortrait .height + "]" );
5455
5556 TransparentActivityConfig config ;
57+ int navBarHeight = 0 ;
5658 if (currentOrientation == Configuration .ORIENTATION_LANDSCAPE ) {
5759 config = configLandscape ;
5860 } else {
61+ // This is only needed for the portrait mode and
62+ // after android 35 the function that gives height gives the full height of the screen
63+ // so we need to subtract the height of the navigation bar
64+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
65+ navBarHeight = getNavigationBarHeight ();
66+ }
67+
5968 config = configPortrait ;
6069 }
6170
6271 config = setupConfig (config );
6372
6473 int width = config .width ;
65- int height = config .height ;
74+ int height = config .height - navBarHeight ;
6675
6776 configLandscape .listeners .add ((url , webView ) -> {
6877 if (url .startsWith (URL_START )) {
@@ -126,23 +135,23 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
126135 return config ;
127136 }
128137
129- private void changeOrientation (TransparentActivityConfig config ) {
138+ private void changeOrientation (TransparentActivityConfig config , int navBarHeight ) {
130139 Log .d (Countly .TAG , "[TransparentActivity] changeOrientation, config x: [" + config .x + "] y: [" + config .y + "] width: [" + config .width + "] height: [" + config .height + "]" );
131140 WindowManager .LayoutParams params = getWindow ().getAttributes ();
132141 params .x = config .x ;
133142 params .y = config .y ;
134- params .height = config .height ;
143+ params .height = config .height - navBarHeight ;
135144 params .width = config .width ;
136145 getWindow ().setAttributes (params );
137146
138147 ViewGroup .LayoutParams layoutParams = relativeLayout .getLayoutParams ();
139148 layoutParams .width = config .width ;
140- layoutParams .height = config .height ;
149+ layoutParams .height = config .height - navBarHeight ;
141150 relativeLayout .setLayoutParams (layoutParams );
142151
143152 ViewGroup .LayoutParams webLayoutParams = webView .getLayoutParams ();
144153 webLayoutParams .width = config .width ;
145- webLayoutParams .height = config .height ;
154+ webLayoutParams .height = config .height - navBarHeight ;
146155 webView .setLayoutParams (webLayoutParams );
147156 }
148157
@@ -163,13 +172,21 @@ private void changeOrientationInternal() {
163172 case Configuration .ORIENTATION_LANDSCAPE :
164173 if (configLandscape != null ) {
165174 configLandscape = setupConfig (configLandscape );
166- changeOrientation (configLandscape );
175+ changeOrientation (configLandscape , 0 );
167176 }
168177 break ;
169178 case Configuration .ORIENTATION_PORTRAIT :
170179 if (configPortrait != null ) {
171180 configPortrait = setupConfig (configPortrait );
172- changeOrientation (configPortrait );
181+ // This is only needed for the portrait mode and
182+ // after android 35 the function that gives height gives the full height of the screen
183+ // so we need to subtract the height of the navigation bar
184+ // this is implemented twice because in the future resize_me action will be able to change the height of the content
185+ int navBarHeight = 0 ;
186+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
187+ navBarHeight = getNavigationBarHeight ();
188+ }
189+ changeOrientation (configPortrait , navBarHeight );
173190 }
174191 break ;
175192 default :
@@ -368,4 +385,12 @@ private WebView createWebView(TransparentActivityConfig config) {
368385 webView .loadUrl (config .url );
369386 return webView ;
370387 }
388+
389+ private int getNavigationBarHeight () {
390+ int resourceId = getResources ().getIdentifier ("navigation_bar_height" , "dimen" , "android" );
391+ if (resourceId > 0 ) {
392+ return getResources ().getDimensionPixelSize (resourceId );
393+ }
394+ return 0 ;
395+ }
371396}
0 commit comments