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

Commit f9e9559

Browse files
committed
Fix detecting software navbar height on emulator.
1 parent cab76ed commit f9e9559

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ dependencies {
7474
annotationProcessor "io.noties:prism4j-bundler:2.0.0"
7575
implementation "com.caverock:androidsvg:1.4"
7676

77+
// Utils for compat
78+
compileOnly "org.robolectric:android-all:11-robolectric-6757853"
79+
7780
// Test
7881
testImplementation 'junit:junit:4.+'
7982
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.graphics.drawable.Drawable;
1111
import android.os.Build;
1212
import android.os.Bundle;
13+
import android.os.SystemProperties;
1314
import android.util.Log;
1415
import android.util.TypedValue;
1516
import android.view.KeyCharacterMap;
@@ -88,8 +89,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8889
if (!this.onCreateCalled) {
8990
this.getLayoutInflater().setFactory2(new LayoutInflaterFactory(this.getDelegate())
9091
.addOnViewCreatedListener(WindowInsetsHelper.Companion.getLISTENER()));
91-
this.hasHardwareNavBar = ViewConfiguration.get(this).hasPermanentMenuKey() ||
92-
KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
92+
this.hasHardwareNavBar = this.hasHardwareNavBar0();
9393
this.onCreateCalledOnce = true;
9494
}
9595
Application application = this.getApplication();
@@ -104,6 +104,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
104104

105105
@Override
106106
protected void onResume() {
107+
this.hasHardwareNavBar = this.hasHardwareNavBar0();
107108
super.onResume();
108109
this.refreshUI();
109110
}
@@ -287,9 +288,13 @@ public int getNavigationBarHeight() {
287288

288289
public boolean hasHardwareNavBar() {
289290
// If onCreate has not been called yet, cached value is not valid
290-
return this.onCreateCalledOnce ? this.hasHardwareNavBar :
291-
ViewConfiguration.get(this).hasPermanentMenuKey() ||
292-
KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
291+
return this.onCreateCalledOnce ? this.hasHardwareNavBar : this.hasHardwareNavBar0();
292+
}
293+
294+
private boolean hasHardwareNavBar0() {
295+
return (ViewConfiguration.get(this).hasPermanentMenuKey() ||
296+
KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)) &&
297+
!"0".equals(SystemProperties.get("qemu.hw.mainkeys"));
293298
}
294299

295300
public void setActionBarExtraMenuButton(@DrawableRes int drawableResId,

0 commit comments

Comments
 (0)