@@ -265,31 +265,30 @@ public void setActionBarBackground(Drawable drawable) {
265265 }
266266
267267 @ Dimension @ Px
268- public int getStatusBarHeight () { // How to improve this?
268+ public int getStatusBarHeight () {
269269 int height = WindowInsetsCompat .CONSUMED .getInsets (
270270 WindowInsetsCompat .Type .statusBars ()).top ;
271- if (height == 0 ) { // Fallback to system resources
272- int id = Resources .getSystem ().getIdentifier (
273- "status_bar_height" , "dimen" , "android" );
274- if (id > 0 ) return Resources .getSystem ().getDimensionPixelSize (id );
275- }
276- return height ;
271+ // Check system resources
272+ int id = Resources .getSystem ().getIdentifier (
273+ "status_bar_height" , "dimen" , "android" );
274+ return id <= 0 ? height : Math .max (height ,
275+ Resources .getSystem ().getDimensionPixelSize (id ));
277276 }
278277
279278 public int getNavigationBarHeight () {
280279 int height = WindowInsetsCompat .CONSUMED .getInsets (
281280 WindowInsetsCompat .Type .navigationBars ()).bottom ;
282- if ( height == 0 ) { // Fallback to system resources
283- int id = Resources .getSystem ().getIdentifier (
284- "config_showNavigationBar" , "bool" , "android" );
285- Log .d (TAG , "Nav 1: " + id );
286- if ((id > 0 && Resources .getSystem ().getBoolean (id ))
287- || !this .hasHardwareNavBar ()) {
288- id = Resources .getSystem ().getIdentifier (
289- "navigation_bar_height" , "dimen" , "android" );
290- Log .d (TAG , "Nav 2: " + id );
291- if ( id > 0 ) return Resources . getSystem (). getDimensionPixelSize ( id );
292- }
281+ // Check system resources
282+ int id = Resources .getSystem ().getIdentifier (
283+ "config_showNavigationBar" , "bool" , "android" );
284+ Log .d (TAG , "Nav 1: " + id );
285+ if ((id > 0 && Resources .getSystem ().getBoolean (id ))
286+ || !this .hasHardwareNavBar ()) {
287+ id = Resources .getSystem ().getIdentifier (
288+ "navigation_bar_height" , "dimen" , "android" );
289+ Log .d (TAG , "Nav 2: " + id );
290+ return id <= 0 ? height : Math . max ( height ,
291+ Resources . getSystem (). getDimensionPixelSize ( id ));
293292 }
294293 return height ;
295294 }
0 commit comments