diff --git a/app/build.gradle b/app/build.gradle index 1661b02..479c4eb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -74,6 +74,9 @@ dependencies { annotationProcessor "io.noties:prism4j-bundler:2.0.0" implementation "com.caverock:androidsvg:1.4" + // Utils for compat + compileOnly "org.robolectric:android-all:11-robolectric-6757853" + // Test testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' diff --git a/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java b/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java index a7031b8..0df73eb 100644 --- a/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java +++ b/app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java @@ -10,6 +10,7 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.os.SystemProperties; import android.util.Log; import android.util.TypedValue; import android.view.KeyCharacterMap; @@ -88,8 +89,7 @@ public class CompatActivity extends AppCompatActivity { if (!this.onCreateCalled) { this.getLayoutInflater().setFactory2(new LayoutInflaterFactory(this.getDelegate()) .addOnViewCreatedListener(WindowInsetsHelper.Companion.getLISTENER())); - this.hasHardwareNavBar = ViewConfiguration.get(this).hasPermanentMenuKey() || - KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); + this.hasHardwareNavBar = this.hasHardwareNavBar0(); this.onCreateCalledOnce = true; } Application application = this.getApplication(); @@ -104,6 +104,7 @@ public class CompatActivity extends AppCompatActivity { @Override protected void onResume() { + this.hasHardwareNavBar = this.hasHardwareNavBar0(); super.onResume(); this.refreshUI(); } @@ -287,9 +288,13 @@ public class CompatActivity extends AppCompatActivity { public boolean hasHardwareNavBar() { // If onCreate has not been called yet, cached value is not valid - return this.onCreateCalledOnce ? this.hasHardwareNavBar : - ViewConfiguration.get(this).hasPermanentMenuKey() || - KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); + return this.onCreateCalledOnce ? this.hasHardwareNavBar : this.hasHardwareNavBar0(); + } + + private boolean hasHardwareNavBar0() { + return (ViewConfiguration.get(this).hasPermanentMenuKey() || + KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)) && + !"0".equals(SystemProperties.get("qemu.hw.mainkeys")); } public void setActionBarExtraMenuButton(@DrawableRes int drawableResId,