1111import android .util .DisplayMetrics ;
1212import android .view .Display ;
1313import android .view .DisplayCutout ;
14- import android .view .View ;
1514import android .view .WindowInsets ;
1615import android .view .WindowManager ;
1716import android .view .WindowMetrics ;
@@ -77,9 +76,9 @@ private static SafeAreaDimensions calculateSafeAreaDimensionsR(@NonNull Context
7776 L .d ("[SafeAreaCalculator] calculateSafeAreaDimensionsR, mapped orientation dimensions (px) - Portrait: [" + portraitWidth + "x" + portraitHeight + "] Landscape: [" + landscapeWidth + "x" + landscapeHeight + "]" );
7877
7978 SafeAreaInsets portraitInsets = calculateInsetsForOrientation (
80- context , windowInsets , true , density , portraitWidth , portraitHeight , L );
79+ windowInsets , true , density , portraitWidth , portraitHeight , L );
8180 SafeAreaInsets landscapeInsets = calculateInsetsForOrientation (
82- context , windowInsets , false , density , landscapeWidth , landscapeHeight , L );
81+ windowInsets , false , density , landscapeWidth , landscapeHeight , L );
8382
8483 SafeAreaDimensions result = new SafeAreaDimensions (
8584 portraitInsets .width ,
@@ -144,8 +143,7 @@ private static SafeAreaDimensions calculateSafeAreaDimensionsLegacy(@NonNull Con
144143 }
145144
146145 @ TargetApi (Build .VERSION_CODES .R )
147- private static SafeAreaInsets calculateInsetsForOrientation (@ NonNull Context context ,
148- @ NonNull WindowInsets windowInsets , boolean isPortrait , float density ,
146+ private static SafeAreaInsets calculateInsetsForOrientation (@ NonNull WindowInsets windowInsets , boolean isPortrait , float density ,
149147 int widthForOrientation , int heightForOrientation , @ NonNull ModuleLog L ) {
150148
151149 String orientationStr = isPortrait ? "portrait" : "landscape" ;
@@ -159,15 +157,13 @@ private static SafeAreaInsets calculateInsetsForOrientation(@NonNull Context con
159157 int cutoutInset = 0 ;
160158 int navBarInset = 0 ;
161159
162- boolean isActivity = context instanceof Activity ;
163-
164160 boolean statusBarVisible = windowInsets .isVisible (WindowInsets .Type .statusBars ());
165161 boolean navBarVisible = windowInsets .isVisible (WindowInsets .Type .navigationBars ());
166162 boolean cutoutVisible = windowInsets .isVisible (WindowInsets .Type .displayCutout ());
167163
168- L .d ("[SafeAreaCalculator] calculateInsetsForOrientation [" + orientationStr + "], context type: [" + ( isActivity ? "Activity" : "Non-Activity" ) + "], visibility - statusBar=[" + statusBarVisible + "], navBar=[" + navBarVisible + "], cutout=[" + cutoutVisible + "]" );
164+ L .d ("[SafeAreaCalculator] calculateInsetsForOrientation [" + orientationStr + "], visibility - statusBar=[" + statusBarVisible + "], navBar=[" + navBarVisible + "], cutout=[" + cutoutVisible + "]" );
169165
170- if (statusBarVisible && isActivity ) {
166+ if (statusBarVisible ) {
171167 Insets statusBarInsets = windowInsets .getInsets (WindowInsets .Type .statusBars ());
172168 statusBarInset = statusBarInsets .top ;
173169 topInset = Math .max (topInset , statusBarInset );
@@ -194,12 +190,12 @@ private static SafeAreaInsets calculateInsetsForOrientation(@NonNull Context con
194190
195191 if (navBarVisible ) {
196192 Insets navBarInsets = windowInsets .getInsets (WindowInsets .Type .navigationBars ());
197-
193+
198194 boolean isGestureNav = isGestureNavigation (navBarInsets , density );
199195 String navType = isGestureNav ? "gesture" : "button" ;
200-
196+
201197 L .d ("[SafeAreaCalculator] calculateInsetsForOrientation [" + orientationStr + "], nav bar type: [" + navType + "], raw insets (px) - top=[" + navBarInsets .top + "], bottom=[" + navBarInsets .bottom + "], left=[" + navBarInsets .left + "], right=[" + navBarInsets .right + "]" );
202-
198+
203199 if (isPortrait ) {
204200 navBarInset = navBarInsets .bottom ;
205201 if (navBarInset == 0 ) {
@@ -237,7 +233,7 @@ private static SafeAreaInsets calculateInsetsForOrientation(@NonNull Context con
237233 if (!isPortrait ) {
238234 Insets navBarInsets = navBarVisible ? windowInsets .getInsets (WindowInsets .Type .navigationBars ()) : Insets .NONE ;
239235 Insets cutoutInsets = cutoutVisible ? windowInsets .getInsets (WindowInsets .Type .displayCutout ()) : Insets .NONE ;
240-
236+
241237 if (navBarInsets .left > 0 ) {
242238 leftOffset = navBarInsets .left ;
243239 L .d ("[SafeAreaCalculator] calculateInsetsForOrientation [" + orientationStr + "], nav bar at left - leftOffset=[" + leftOffset + "] (navBar=" + navBarInsets .left + ")" );
@@ -296,26 +292,26 @@ private static SafeAreaInsets calculateInsetsLegacy(@NonNull Context context,
296292 L .d ("[SafeAreaCalculator] calculateInsetsLegacy [" + orientationStr + "], top inset (px) - using MAX(statusBar=" + statusBarInset + ", cutout=" + cutoutInset + ") = [" + topInset + "]" );
297293
298294 int navBarHeightFromResource = getNavigationBarHeight (context , isPortrait );
299-
295+
300296 boolean navBarVisible = isNavigationBarVisible (context );
301297 L .d ("[SafeAreaCalculator] calculateInsetsLegacy [" + orientationStr + "], nav bar visible: [" + navBarVisible + "], resource height (px): [" + navBarHeightFromResource + "]" );
302-
298+
303299 if (navBarVisible ) {
304300 boolean isGestureNav = navBarHeightFromResource < (int ) (density * 40 ); // < 40dp likely gesture
305301 String navType = isGestureNav ? "gesture" : "button" ;
306-
302+
307303 navBarInset = navBarHeightFromResource ;
308304 if (navBarInset == 0 ) {
309305 navBarInset = getDefaultNavBarInset (isGestureNav , density );
310306 L .d ("[SafeAreaCalculator] calculateInsetsLegacy [" + orientationStr + "], nav bar height is 0, using default [" + navType + "] value (px): [" + navBarInset + "]" );
311307 } else {
312308 L .d ("[SafeAreaCalculator] calculateInsetsLegacy [" + orientationStr + "], nav bar type: [" + navType + "], height (px): [" + navBarInset + "]" );
313309 }
314-
310+
315311 if (isPortrait ) {
316312 bottomInset = Math .max (bottomInset , navBarInset );
317313 } else {
318- bottomInset = Math .max (bottomInset , navBarInset );
314+ bottomInset = Math .min (bottomInset , navBarInset );
319315 }
320316 }
321317
0 commit comments