package com.cherish.settings.fragments; import com.android.internal.logging.nano.MetricsProto; import android.os.Bundle; import androidx.preference.ListPreference; import androidx.preference.Preference; import android.preference.SwitchPreference; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import com.android.settings.R; 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) { super.onCreate(icicle); 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; } @Override public int getMetricsCategory() { return MetricsProto.MetricsEvent.CHERISH_SETTINGS; } }