Skip to content

Commit cf8fd0c

Browse files
genoxci-devdrkphnx
authored andcommitted
Settings: Add back hide IME navbar functionality [1/3]
1 parent b82a1c6 commit cf8fd0c

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

res/values/custom_strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@
4343

4444
<string name="wellbeing_title">Digital Wellbeing &amp; parental controls</string>
4545
<string name="wellbeing_summary">Screen time, app timers, bedtime schedules</string>
46+
47+
<!-- hide IME navbar -->
48+
<string name="keyboard_no_navigation_title">Keyboard IME space</string>
49+
<string name="keyboard_no_navigation_summary">Show space below keyboard when using gesture navigation</string>
4650
</resources>

res/xml/gesture_navigation_settings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
android:summary="@string/show_navbar_hint_summary"
3535
android:defaultValue="true" />
3636

37+
<SwitchPreferenceCompat
38+
android:key="keyboard_no_navigation_bar"
39+
android:title="@string/keyboard_no_navigation_title"
40+
android:summary="@string/keyboard_no_navigation_summary"
41+
android:defaultValue="true"
42+
settings:controller="com.android.settings.navigationbar.KeyboardNoNavigationBarController" />
43+
3744
<com.android.settings.widget.LabeledSeekBarPreference
3845
android:key="gesture_navbar_length_preference"
3946
android:title="@string/gesture_navbar_length_title"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* SPDX-FileCopyrightText: DerpFest AOSP
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package com.android.settings.navigationbar;
7+
8+
import android.provider.Settings;
9+
import android.os.SystemProperties;
10+
import android.content.Context;
11+
import android.util.Log;
12+
13+
import androidx.preference.Preference;
14+
import androidx.preference.SwitchPreferenceCompat;
15+
16+
import com.android.settings.core.BasePreferenceController;
17+
18+
public class KeyboardNoNavigationBarController extends BasePreferenceController implements Preference.OnPreferenceChangeListener {
19+
20+
private static final String KEY_KEYBOARD_NO_NAVIGATION_BAR = "keyboard_no_navigation_bar";
21+
private static final String TAG = "NoNavbarController";
22+
23+
public KeyboardNoNavigationBarController(Context context, String preferenceKey) {
24+
super(context, preferenceKey);
25+
}
26+
27+
@Override
28+
public int getAvailabilityStatus() {
29+
int navigationMode = Settings.Secure.getInt(
30+
mContext.getContentResolver(),
31+
Settings.Secure.NAVIGATION_MODE,
32+
0 // Default to 0 if the setting is not found
33+
);
34+
35+
return navigationMode == 2
36+
? AVAILABLE
37+
: UNSUPPORTED_ON_DEVICE;
38+
39+
}
40+
41+
public boolean isChecked() {
42+
String value = SystemProperties.get("persist.sys.keyboard_no_navigation_bar", "1");
43+
boolean result = "1".equals(value); // switch is ON only when overlay is disabled
44+
Log.d(TAG, "isChecked() reversed logic returning: " + result);
45+
return result;
46+
}
47+
48+
@Override
49+
public boolean onPreferenceChange(Preference preference, Object newValue) {
50+
if (!(newValue instanceof Boolean)) {
51+
Log.e(TAG, "Unexpected value type for preference: " + newValue);
52+
return false;
53+
}
54+
55+
boolean enabled = (Boolean) newValue;
56+
String newPropValue = enabled ? "1" : "0";
57+
SystemProperties.set("persist.sys.keyboard_no_navigation_bar", newPropValue);
58+
Log.d(TAG, "onPreferenceChange() set persist.sys.keyboard_no_navigation_bar to: " + newPropValue);
59+
60+
String command = enabled
61+
? "cmd overlay disable com.voltage.overlay.customization.keyboard.nonavbar"
62+
: "cmd overlay enable com.voltage.overlay.customization.keyboard.nonavbar";
63+
64+
try {
65+
Runtime.getRuntime().exec(new String[]{"sh", "-c", command});
66+
Log.d(TAG, "Executed command: " + command);
67+
} catch (Exception e) {
68+
Log.e(TAG, "Failed to execute overlay command", e);
69+
}
70+
71+
return true;
72+
}
73+
74+
@Override
75+
public void updateState(Preference preference) {
76+
if (preference instanceof SwitchPreferenceCompat) {
77+
boolean checked = isChecked();
78+
((SwitchPreferenceCompat) preference).setChecked(checked);
79+
Log.d(TAG, "updateState() setting switch to: " + checked);
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)