Cherish:Volume rocker cursor control (2/2)

This commit is contained in:
Konsta
2017-09-09 19:15:43 +08:00
committed by Hưng Phan
parent 4893ec803f
commit cbe6fdc678
4 changed files with 50 additions and 2 deletions

View File

@@ -15,6 +15,9 @@ import com.android.settings.SettingsPreferenceFragment;
public class VolumeRockerSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String VOLUME_KEY_CURSOR_CONTROL = "volume_key_cursor_control";
private ListPreference mVolumeKeyCursorControl;
@Override
public void onCreate(Bundle icicle) {
@@ -22,11 +25,30 @@ public class VolumeRockerSettings extends SettingsPreferenceFragment implements
addPreferencesFromResource(R.xml.cherish_settings_volume);
// volume key cursor control
mVolumeKeyCursorControl = (ListPreference) findPreference(VOLUME_KEY_CURSOR_CONTROL);
if (mVolumeKeyCursorControl != null) {
mVolumeKeyCursorControl.setOnPreferenceChangeListener(this);
int volumeRockerCursorControl = Settings.System.getInt(getContentResolver(),
Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
mVolumeKeyCursorControl.setValue(Integer.toString(volumeRockerCursorControl));
mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntry());
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
if (preference == mVolumeKeyCursorControl) {
String volumeKeyCursorControl = (String) value;
int volumeKeyCursorControlValue = Integer.parseInt(volumeKeyCursorControl);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.VOLUME_KEY_CURSOR_CONTROL, volumeKeyCursorControlValue);
int volumeKeyCursorControlIndex = mVolumeKeyCursorControl
.findIndexOfValue(volumeKeyCursorControl);
mVolumeKeyCursorControl
.setSummary(mVolumeKeyCursorControl.getEntries()[volumeKeyCursorControlIndex]);
return true;
}
return false;
}