diff options
author | Bruno Martins <bgcngm@gmail.com> | 2020-10-07 14:38:45 +0100 |
---|---|---|
committer | Bruno Martins <bgcngm@gmail.com> | 2020-10-10 21:30:54 +0100 |
commit | 92e3fd385e6c5814a72180b7e419604c56ed1d54 (patch) | |
tree | 94913c3ea3c734fe6081a1785c97f42ecbcc9bed | |
parent | 6c8187c2b3a6c1751e5073124d005d71f898f069 (diff) |
ButtonSettings: Rework buttons/keyboard backlight control enablement
Let's end once and for all with the nonsense of using floats
config_{button,keyboard}BrightnessSettingDefaultFloat to enable
button and keyboard brightness control, respectively.
Instead, just move over to the recently introduced integers
config_deviceSupports{Button,Keyboard}BrightnessControl.
This avoids people with devices with hardware keys having to
overlay config_{button,keyboard}BrightnessSettingDefaultFloat to
a value of 0.0 just to disable the unsupported features.
Change-Id: I0dfd0b5fa51c51398face208f17df70419ef00ca
3 files changed, 28 insertions, 28 deletions
diff --git a/src/org/lineageos/lineageparts/input/ButtonBacklightBrightness.java b/src/org/lineageos/lineageparts/input/ButtonBacklightBrightness.java index bc39a52..58106e9 100644 --- a/src/org/lineageos/lineageparts/input/ButtonBacklightBrightness.java +++ b/src/org/lineageos/lineageparts/input/ButtonBacklightBrightness.java @@ -44,6 +44,7 @@ import lineageos.providers.LineageSettings; public class ButtonBacklightBrightness extends CustomDialogPreference<AlertDialog> implements SeekBar.OnSeekBarChangeListener { + private static final int BUTTON_BRIGHTNESS_TOGGLE_MODE_ONLY = 1; private static final int DEFAULT_BUTTON_TIMEOUT = 5; public static final String KEY_BUTTON_BACKLIGHT = "pre_navbar_button_backlight"; @@ -67,15 +68,15 @@ public class ButtonBacklightBrightness extends CustomDialogPreference<AlertDialo setDialogLayoutResource(R.layout.button_backlight); - if (isKeyboardSupported(context)) { + if (DeviceUtils.hasKeyboardBacklightSupport(context)) { mKeyboardBrightness = new BrightnessControl( LineageSettings.Secure.KEYBOARD_BRIGHTNESS, false); mActiveControl = mKeyboardBrightness; } - if (isButtonSupported(context)) { - boolean isSingleValue = !context.getResources().getBoolean( - org.lineageos.platform.internal.R.bool - .config_deviceHasVariableButtonBrightness); + if (DeviceUtils.hasButtonBacklightSupport(context)) { + final boolean isSingleValue = BUTTON_BRIGHTNESS_TOGGLE_MODE_ONLY == + context.getResources().getInteger(org.lineageos.platform.internal.R.integer + .config_deviceSupportsButtonBrightnessControl); float defaultBrightness = context.getResources().getFloat( org.lineageos.platform.internal.R.dimen @@ -225,25 +226,6 @@ public class ButtonBacklightBrightness extends CustomDialogPreference<AlertDialo } } - public static boolean isButtonSupported(Context context) { - final Resources res = context.getResources(); - // All hardware keys besides volume and camera can possibly have a backlight - boolean hasBacklightKey = DeviceUtils.hasHomeKey(context) - || DeviceUtils.hasBackKey(context) - || DeviceUtils.hasMenuKey(context) - || DeviceUtils.hasAssistKey(context) - || DeviceUtils.hasAppSwitchKey(context); - boolean hasBacklight = res.getFloat(org.lineageos.platform.internal.R.dimen - .config_buttonBrightnessSettingDefaultFloat) > 0.0f; - - return hasBacklightKey && hasBacklight; - } - - public static boolean isKeyboardSupported(Context context) { - return context.getResources().getFloat(org.lineageos.platform.internal.R.dimen - .config_keyboardBrightnessSettingDefaultFloat) > 0.0f; - } - public void updateSummary() { if (mButtonBrightness != null) { float buttonBrightness = mButtonBrightness.getBrightness(true); diff --git a/src/org/lineageos/lineageparts/input/ButtonSettings.java b/src/org/lineageos/lineageparts/input/ButtonSettings.java index 4b7dc11..20c38d7 100644 --- a/src/org/lineageos/lineageparts/input/ButtonSettings.java +++ b/src/org/lineageos/lineageparts/input/ButtonSettings.java @@ -398,8 +398,8 @@ public class ButtonSettings extends SettingsPreferenceFragment } final ButtonBacklightBrightness backlight = findPreference(KEY_BUTTON_BACKLIGHT); - if (!backlight.isButtonSupported(getActivity()) - && !backlight.isKeyboardSupported(getActivity())) { + if (!DeviceUtils.hasButtonBacklightSupport(getActivity()) + && !DeviceUtils.hasKeyboardBacklightSupport(getActivity())) { prefScreen.removePreference(backlight); } @@ -841,8 +841,8 @@ public class ButtonSettings extends SettingsPreferenceFragment result.add(KEY_DISABLE_NAV_KEYS); } - if (!ButtonBacklightBrightness.isButtonSupported(context) - && !ButtonBacklightBrightness.isKeyboardSupported(context)) { + if (!DeviceUtils.hasButtonBacklightSupport(context) + && !DeviceUtils.hasKeyboardBacklightSupport(context)) { result.add(KEY_BUTTON_BACKLIGHT); } diff --git a/src/org/lineageos/lineageparts/utils/DeviceUtils.java b/src/org/lineageos/lineageparts/utils/DeviceUtils.java index e6dae1c..5234536 100644 --- a/src/org/lineageos/lineageparts/utils/DeviceUtils.java +++ b/src/org/lineageos/lineageparts/utils/DeviceUtils.java @@ -135,6 +135,24 @@ public class DeviceUtils { return (getDeviceWakeKeys(context) & KEY_MASK_VOLUME) != 0; } + /* returns whether the device supports button backlight adjusment or not. */ + public static boolean hasButtonBacklightSupport(Context context) { + final boolean buttonBrightnessControlSupported = context.getResources().getInteger( + org.lineageos.platform.internal.R.integer + .config_deviceSupportsButtonBrightnessControl) != 0; + + // All hardware keys besides volume and camera can possibly have a backlight + return buttonBrightnessControlSupported + && (hasHomeKey(context) || hasBackKey(context) || hasMenuKey(context) + || hasAssistKey(context) || hasAppSwitchKey(context)); + } + + /* returns whether the device supports keyboard backlight adjusment or not. */ + public static boolean hasKeyboardBacklightSupport(Context context) { + return context.getResources().getInteger(org.lineageos.platform.internal.R.integer + .config_deviceSupportsKeyboardBrightnessControl) != 0; + } + public static boolean isPackageInstalled(Context context, String pkg, boolean ignoreState) { if (pkg != null) { try { |