ButtonBrightness: use switch for devices without variable button brightness
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -177,4 +177,6 @@
|
|||||||
|
|
||||||
<!-- Enable keys backlight-->
|
<!-- Enable keys backlight-->
|
||||||
<string name="button_brightness_title">Backlight</string>
|
<string name="button_brightness_title">Backlight</string>
|
||||||
|
<!-- Enable keys backlight-->
|
||||||
|
<string name="button_brightness_sw_title">Enable backlight</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -43,6 +43,11 @@
|
|||||||
settings:units=""
|
settings:units=""
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="button_brightness_sw"
|
||||||
|
android:title="@string/button_brightness_sw_title"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:dialogTitle="@string/backlight_timeout_title"
|
android:dialogTitle="@string/backlight_timeout_title"
|
||||||
android:entries="@array/backlight_timeout_entries"
|
android:entries="@array/backlight_timeout_entries"
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
//Keys
|
//Keys
|
||||||
private static final String KEY_BUTTON_BRIGHTNESS = "button_brightness";
|
private static final String KEY_BUTTON_BRIGHTNESS = "button_brightness";
|
||||||
|
private static final String KEY_BUTTON_BRIGHTNESS_SW = "button_brightness_sw";
|
||||||
private static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout";
|
private static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout";
|
||||||
|
|
||||||
// category keys
|
// category keys
|
||||||
@@ -52,6 +53,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private ListPreference mBacklightTimeout;
|
private ListPreference mBacklightTimeout;
|
||||||
private CustomSeekBarPreference mButtonBrightness;
|
private CustomSeekBarPreference mButtonBrightness;
|
||||||
|
private SwitchPreference mButtonBrightness_sw;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -60,10 +62,15 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||||
|
|
||||||
|
final boolean variableBrightness = getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_deviceHasVariableButtonBrightness);
|
||||||
|
|
||||||
mBacklightTimeout =
|
mBacklightTimeout =
|
||||||
(ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
|
(ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
|
||||||
mButtonBrightness =
|
mButtonBrightness =
|
||||||
(CustomSeekBarPreference) findPreference(KEY_BUTTON_BRIGHTNESS);
|
(CustomSeekBarPreference) findPreference(KEY_BUTTON_BRIGHTNESS);
|
||||||
|
mButtonBrightness_sw =
|
||||||
|
(SwitchPreference) findPreference(KEY_BUTTON_BRIGHTNESS_SW);
|
||||||
|
|
||||||
if (mBacklightTimeout != null) {
|
if (mBacklightTimeout != null) {
|
||||||
mBacklightTimeout.setOnPreferenceChangeListener(this);
|
mBacklightTimeout.setOnPreferenceChangeListener(this);
|
||||||
@@ -73,11 +80,21 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
|||||||
mBacklightTimeout.setSummary(mBacklightTimeout.getEntry());
|
mBacklightTimeout.setSummary(mBacklightTimeout.getEntry());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mButtonBrightness != null) {
|
if (variableBrightness) {
|
||||||
int ButtonBrightness = Settings.System.getInt(getContentResolver(),
|
prefScreen.removePreference(mButtonBrightness_sw);
|
||||||
Settings.System.BUTTON_BRIGHTNESS, 255);
|
if (mButtonBrightness != null) {
|
||||||
mButtonBrightness.setValue(ButtonBrightness / 1);
|
int ButtonBrightness = Settings.System.getInt(getContentResolver(),
|
||||||
mButtonBrightness.setOnPreferenceChangeListener(this);
|
Settings.System.BUTTON_BRIGHTNESS, 255);
|
||||||
|
mButtonBrightness.setValue(ButtonBrightness / 1);
|
||||||
|
mButtonBrightness.setOnPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prefScreen.removePreference(mButtonBrightness);
|
||||||
|
if (mButtonBrightness_sw != null) {
|
||||||
|
mButtonBrightness_sw.setChecked((Settings.System.getInt(getContentResolver(),
|
||||||
|
Settings.System.BUTTON_BRIGHTNESS, 1) == 1));
|
||||||
|
mButtonBrightness_sw.setOnPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +115,11 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
|||||||
Settings.System.putInt(getActivity().getContentResolver(),
|
Settings.System.putInt(getActivity().getContentResolver(),
|
||||||
Settings.System.BUTTON_BRIGHTNESS, value * 1);
|
Settings.System.BUTTON_BRIGHTNESS, value * 1);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (preference == mButtonBrightness_sw) {
|
||||||
|
boolean value = (Boolean) newValue;
|
||||||
|
Settings.System.putInt(getActivity().getContentResolver(),
|
||||||
|
Settings.System.BUTTON_BRIGHTNESS, value ? 1 : 0);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user