Buttons: Add buttons brightness and button backlight timeout options

This commit is contained in:
xyyx
2020-09-25 15:25:41 +00:00
committed by Hưng Phan
parent 33bc5e6d60
commit d3a510773e
5 changed files with 111 additions and 5 deletions

View File

@@ -36,22 +36,69 @@ import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import com.android.internal.logging.nano.MetricsProto;
public class ButtonSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener{
//Keys
private static final String KEY_BUTTON_BRIGHTNESS = "button_brightness";
private static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout";
// category keys
private static final String CATEGORY_HWKEY = "hardware_keys";
private ListPreference mBacklightTimeout;
private CustomSeekBarPreference mButtonBrightness;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.cherish_settings_button);
final PreferenceScreen prefScreen = getPreferenceScreen();
mBacklightTimeout =
(ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
mButtonBrightness =
(CustomSeekBarPreference) findPreference(KEY_BUTTON_BRIGHTNESS);
if (mBacklightTimeout != null) {
mBacklightTimeout.setOnPreferenceChangeListener(this);
int BacklightTimeout = Settings.System.getInt(getContentResolver(),
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, 5000);
mBacklightTimeout.setValue(Integer.toString(BacklightTimeout));
mBacklightTimeout.setSummary(mBacklightTimeout.getEntry());
}
if (mButtonBrightness != null) {
int ButtonBrightness = Settings.System.getInt(getContentResolver(),
Settings.System.BUTTON_BRIGHTNESS, 255);
mButtonBrightness.setValue(ButtonBrightness / 1);
mButtonBrightness.setOnPreferenceChangeListener(this);
}
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mBacklightTimeout) {
String BacklightTimeout = (String) newValue;
int BacklightTimeoutValue = Integer.parseInt(BacklightTimeout);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, BacklightTimeoutValue);
int BacklightTimeoutIndex = mBacklightTimeout
.findIndexOfValue(BacklightTimeout);
mBacklightTimeout
.setSummary(mBacklightTimeout.getEntries()[BacklightTimeoutIndex]);
return true;
} else if (preference == mButtonBrightness) {
int value = (Integer) newValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.BUTTON_BRIGHTNESS, value * 1);
return true;
}
return false;
}

View File

@@ -38,7 +38,7 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
private int mInterval = 1;
private int mCurrentValue;
private int mDefaultValue = -1;
private int mMax = 100;
private int mMax = 255;
private String mUnits = "";
private String mDefaultText = "";
private SeekBar mSeekBar;
@@ -51,7 +51,7 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.CustomSeekBarPreference);
mMax = attrs.getAttributeIntValue(ANDROIDNS, "max", 100);
mMax = attrs.getAttributeIntValue(ANDROIDNS, "max", 255);
mMin = attrs.getAttributeIntValue(SETTINGS_NS, "min", 0);
mDefaultValue = attrs.getAttributeIntValue(ANDROIDNS, "defaultValue", -1);
if (mDefaultValue > mMax) {