Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit c3d8213

Browse files
committed
Always check resources for getStatusBarHeight and getNavigationBarHeight
1 parent 709a0a4 commit c3d8213

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)