Settings: Implement hide gestural navigation hint bar [2/3]

[Linux4: Make it use a PreferenceController instead of custom Preference class]

Change-Id: I14dd73414c9f7ee1b01f315c9eeae0fd3ac4f859
Signed-off-by: Jesse Chan <jc@lineageos.org>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 2f1dd56..f5549bc 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -22,4 +22,8 @@
     <!-- High touch sensitivity -->
     <string name="high_touch_sensitivity_title">High touch sensitivity</string>
     <string name="high_touch_sensitivity_summary">Increase touchscreen sensitivity so it can be used while wearing gloves</string>
+
+    <!-- Navigation bar hint -->
+    <string name="show_navbar_gesture_bar_title">Gesture bar</string>
+    <string name="show_navbar_gesture_bar_summary">Show gesture bar at the bottom of the screen</string>
 </resources>
diff --git a/res/xml/gesture_navigation_settings.xml b/res/xml/gesture_navigation_settings.xml
index a4b5af9..26fdf65 100644
--- a/res/xml/gesture_navigation_settings.xml
+++ b/res/xml/gesture_navigation_settings.xml
@@ -57,6 +57,13 @@
             settings:textEnd="@string/high_label"/>
     </PreferenceCategory>
 
+    <SwitchPreference
+        android:key="navigation_bar_hint"
+        android:title="@string/show_navbar_gesture_bar_title"
+        android:summary="@string/show_navbar_gesture_bar_summary"
+        android:defaultValue="true"
+        settings:controller="org.leafos.settings.gestures.NavigationHintPreferenceController" />
+
     <com.android.settingslib.widget.FooterPreference
         android:key="gesture_navigation_settings_footer"
         android:title="@string/back_sensitivity_dialog_message"
diff --git a/src/org/leafos/settings/controller/BaseSecureSwitchPreferenceController.java b/src/org/leafos/settings/controller/BaseSecureSwitchPreferenceController.java
new file mode 100644
index 0000000..6616aa2
--- /dev/null
+++ b/src/org/leafos/settings/controller/BaseSecureSwitchPreferenceController.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2022 The LeafOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.leafos.settings.controller;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+
+public class BaseSecureSwitchPreferenceController extends TogglePreferenceController implements
+        Preference.OnPreferenceChangeListener  {
+
+    private SwitchPreference mPreference;
+
+    public BaseSecureSwitchPreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        mPreference = (SwitchPreference)preference;
+        super.updateState(preference);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public boolean isSliceable() {
+        return mPreference != null;
+    }
+
+    @Override
+    public boolean isPublicSlice() {
+        return true;
+    }
+
+    @Override
+    public int getSliceHighlightMenuRes() {
+        return R.string.menu_key_display;
+    }
+
+    @Override
+    public boolean isChecked() {
+        return Settings.Secure.getInt(mContext.getContentResolver(), getPreferenceKey(),
+            mPreference.isChecked() ? 1 : 0) != 0;
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        Settings.Secure.putInt(mContext.getContentResolver(), getPreferenceKey(), isChecked ? 1 : 0);
+        return true;
+    }
+}
diff --git a/src/org/leafos/settings/gestures/NavigationHintPreferenceController.java b/src/org/leafos/settings/gestures/NavigationHintPreferenceController.java
new file mode 100644
index 0000000..756f295
--- /dev/null
+++ b/src/org/leafos/settings/gestures/NavigationHintPreferenceController.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2022 The LeafOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.leafos.settings.gestures;
+
+import android.content.Context;
+
+import org.leafos.settings.controller.BaseSecureSwitchPreferenceController;
+
+public class NavigationHintPreferenceController extends BaseSecureSwitchPreferenceController {
+
+    public NavigationHintPreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+}