From e74815874922134ca3852a033badf001640f025e Mon Sep 17 00:00:00 2001 From: Howard Wu Date: Thu, 2 Nov 2023 15:20:16 +0800 Subject: [PATCH] Fix custom nav always disable (#14) --- .../fragment/systemui/NavigationSettings.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/systemui/NavigationSettings.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/systemui/NavigationSettings.java index f1a32da947..8d36c81404 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/systemui/NavigationSettings.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/systemui/NavigationSettings.java @@ -1,12 +1,17 @@ package com.sevtinge.hyperceiler.ui.fragment.systemui; +import android.provider.Settings; import android.view.View; import com.sevtinge.hyperceiler.R; import com.sevtinge.hyperceiler.ui.base.BaseSettingsActivity; import com.sevtinge.hyperceiler.ui.fragment.base.SettingsPreferenceFragment; +import moralnorm.preference.SwitchPreference; + public class NavigationSettings extends SettingsPreferenceFragment { + SwitchPreference customNav; + @Override public int getContentResId() { return R.xml.system_ui_navigation; @@ -14,9 +19,26 @@ public int getContentResId() { @Override public View.OnClickListener addRestartListener() { - return view -> ((BaseSettingsActivity)getActivity()).showRestartDialog( + return view -> ((BaseSettingsActivity) getActivity()).showRestartDialog( getResources().getString(R.string.system_ui), "com.android.systemui" ); } + + private boolean isGestureNavigationEnabled() { + var defaultNavigationMode = 0; + var gestureNavigationMode = 2; + + return Settings.Secure.getInt(requireContext().getContentResolver(), "navigation_mode", defaultNavigationMode) == gestureNavigationMode; + } + + @Override + public void initPrefs() { + customNav = findPreference("prefs_key_system_ui_navigation_custom"); + if (customNav != null) { + customNav.setEnabled(!isGestureNavigationEnabled()); + customNav.setVisible(customNav.isEnabled()); + } + + } }