diff options
author | Arian <arian.kulmer@web.de> | 2021-01-03 16:50:25 +0100 |
---|---|---|
committer | Bruno Martins <bgcngm@gmail.com> | 2021-01-06 19:27:56 +0000 |
commit | c77e9f89a0ae946ac64d4eac84dd4e2ad3ebd8d9 (patch) | |
tree | a24300e49c60edbece5fe4e7c8ec1adfb16ca6f1 | |
parent | 5f2579010f2ed6769ba3c01c61242ecdfaecfeff (diff) |
ButtonSettings: Add a setting to swap capacitive keys
Change-Id: Ibfcd698989c6496e45ca756a7f279216fe671329
-rw-r--r-- | res/values/strings.xml | 6 | ||||
-rw-r--r-- | res/xml/button_settings.xml | 6 | ||||
-rw-r--r-- | src/org/lineageos/lineageparts/BootReceiver.java | 2 | ||||
-rw-r--r-- | src/org/lineageos/lineageparts/input/ButtonSettings.java | 42 |
4 files changed, 54 insertions, 2 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index ad53e96..eb0d487 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2015 The CyanogenMod Project - 2017-2020 The LineageOS Project + 2017-2021 The LineageOS Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -233,6 +233,10 @@ <string name="disable_navkeys_title">Enable on-screen nav bar</string> <string name="disable_navkeys_summary">Enable on-screen navigation bar and disable hardware buttons</string> + <!-- Buttons - Swap capacitive keys --> + <string name="swap_capacitive_keys_title">Swap capacitive buttons</string> + <string name="swap_capacitive_keys_summary">Swap the order of recents and back buttons</string> + <!-- Navigation Bar --> <string name="navigation_bar_category">Navigation bar</string> <string name="navigation_bar_invert_layout_title">Invert layout</string> diff --git a/res/xml/button_settings.xml b/res/xml/button_settings.xml index 828c310..f4880f1 100644 --- a/res/xml/button_settings.xml +++ b/res/xml/button_settings.xml @@ -25,6 +25,12 @@ android:summary="@string/disable_navkeys_summary" android:defaultValue="false" /> + <SwitchPreference + android:key="swap_capacitive_keys" + android:title="@string/swap_capacitive_keys_title" + android:summary="@string/swap_capacitive_keys_summary" + android:defaultValue="false" /> + <org.lineageos.lineageparts.input.ButtonBacklightBrightness android:key="button_backlight" android:title="@string/button_backlight_title" diff --git a/src/org/lineageos/lineageparts/BootReceiver.java b/src/org/lineageos/lineageparts/BootReceiver.java index 30d75f5..6b0ab87 100644 --- a/src/org/lineageos/lineageparts/BootReceiver.java +++ b/src/org/lineageos/lineageparts/BootReceiver.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2012 The CyanogenMod Project + * 2017-2019,2021 The LineageOS project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +41,7 @@ public class BootReceiver extends BroadcastReceiver { setRestoredTunable(ctx); } + ButtonSettings.restoreKeySwapper(ctx); TouchscreenGestureSettings.restoreTouchscreenGestureStates(ctx); // Extract the contributors database diff --git a/src/org/lineageos/lineageparts/input/ButtonSettings.java b/src/org/lineageos/lineageparts/input/ButtonSettings.java index b46a6f3..9af549e 100644 --- a/src/org/lineageos/lineageparts/input/ButtonSettings.java +++ b/src/org/lineageos/lineageparts/input/ButtonSettings.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2016 The CyanogenMod project - * 2017-2020 The LineageOS project + * 2017-2021 The LineageOS project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.RemoteException; @@ -40,6 +41,7 @@ import android.view.WindowManagerGlobal; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; @@ -101,6 +103,7 @@ public class ButtonSettings extends SettingsPreferenceFragment "torch_long_press_power_timeout"; private static final String KEY_CLICK_PARTIAL_SCREENSHOT = "click_partial_screenshot"; + private static final String KEY_SWAP_CAPACITIVE_KEYS = "swap_capacitive_keys"; private static final String CATEGORY_POWER = "power_key"; private static final String CATEGORY_HOME = "home_key"; @@ -140,15 +143,20 @@ public class ButtonSettings extends SettingsPreferenceFragment private SwitchPreference mHomeAnswerCall; private SwitchPreference mTorchLongPressPowerGesture; private ListPreference mTorchLongPressPowerTimeout; + private SwitchPreference mSwapCapacitiveKeys; private PreferenceCategory mNavigationPreferencesCat; private Handler mHandler; + private LineageHardwareManager mHardware; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mHardware = LineageHardwareManager.getInstance(getActivity()); + addPreferencesFromResource(R.xml.button_settings); final Resources res = getResources(); @@ -245,6 +253,7 @@ public class ButtonSettings extends SettingsPreferenceFragment // Remove keys that can be provided by the navbar updateDisableNavkeysOption(); mNavigationPreferencesCat.setEnabled(mDisableNavigationKeys.isChecked()); + mDisableNavigationKeys.setDisableDependentsState(true); } else { prefScreen.removePreference(mDisableNavigationKeys); } @@ -434,6 +443,14 @@ public class ButtonSettings extends SettingsPreferenceFragment } } + mSwapCapacitiveKeys = findPreference(KEY_SWAP_CAPACITIVE_KEYS); + if (mSwapCapacitiveKeys != null && !isKeySwapperSupported(getActivity())) { + prefScreen.removePreference(mSwapCapacitiveKeys); + } else { + mSwapCapacitiveKeys.setOnPreferenceChangeListener(this); + mSwapCapacitiveKeys.setDependency(KEY_DISABLE_NAV_KEYS); + } + // Override key actions on Go devices in order to hide any unsupported features if (ActivityManager.isLowRamDeviceStatic()) { String[] actionEntriesGo = res.getStringArray(R.array.hardware_keys_action_entries_go); @@ -586,6 +603,9 @@ public class ButtonSettings extends SettingsPreferenceFragment handleListChange(mEdgeLongSwipeAction, newValue, LineageSettings.System.KEY_EDGE_LONG_SWIPE_ACTION); return true; + } else if (preference == mSwapCapacitiveKeys) { + mHardware.set(LineageHardwareManager.FEATURE_KEY_SWAP, (Boolean) newValue); + return true; } return false; } @@ -692,6 +712,11 @@ public class ButtonSettings extends SettingsPreferenceFragment return hardware.isSupported(LineageHardwareManager.FEATURE_KEY_DISABLE); } + private static boolean isKeySwapperSupported(Context context) { + final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context); + return hardware.isSupported(LineageHardwareManager.FEATURE_KEY_SWAP); + } + public static void restoreKeyDisabler(Context context) { if (!isKeyDisablerSupported(context)) { return; @@ -703,6 +728,17 @@ public class ButtonSettings extends SettingsPreferenceFragment writeDisableNavkeysOption(context, enabled); } + public static void restoreKeySwapper(Context context) { + if (!isKeySwapperSupported(context)) { + return; + } + + final SharedPreferences preferences = + PreferenceManager.getDefaultSharedPreferences(context); + final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context); + hardware.set(LineageHardwareManager.FEATURE_KEY_SWAP, + preferences.getBoolean(KEY_SWAP_CAPACITIVE_KEYS, false)); + } @Override public boolean onPreferenceTreeClick(Preference preference) { @@ -856,6 +892,10 @@ public class ButtonSettings extends SettingsPreferenceFragment result.add(KEY_DISABLE_NAV_KEYS); } + if (!isKeySwapperSupported(context)) { + result.add(KEY_SWAP_CAPACITIVE_KEYS); + } + if (!DeviceUtils.hasButtonBacklightSupport(context) && !DeviceUtils.hasKeyboardBacklightSupport(context)) { result.add(KEY_BUTTON_BACKLIGHT); |