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

@@ -31,4 +31,17 @@
<item>5</item>
<item>6</item>
</string-array>
<!--- Volume key cursor control -->
<string-array name="volume_key_cursor_control_entries">
<item>@string/volume_key_cursor_control_off</item>
<item>@string/volume_key_cursor_control_on</item>
<item>@string/volume_key_cursor_control_on_reverse</item>
</string-array>
<string-array name="volume_key_cursor_control_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>

View File

@@ -130,4 +130,11 @@
<!-- Volume rocker wake -->
<string name="volume_rocker_wake_title">Volume rocker wake</string>
<string name="volume_rocker_wake_summary">Pressing the volume keys will wake your device</string>
</resources>
<!-- Language options - Volume rocker cursor control -->
<string name="cursor_section_header">Cursor</string>
<string name="volume_key_cursor_control_title">Volume key cursor control</string>
<string name="volume_key_cursor_control_off">Disabled</string>
<string name="volume_key_cursor_control_on">Volume up/down moves cursor left/right</string>
<string name="volume_key_cursor_control_on_reverse">Volume up/down moves cursor right/left</string>
</resources>

View File

@@ -31,4 +31,10 @@
android:title="@string/volume_rocker_wake_title"
android:defaultValue="false" />
<ListPreference
android:dialogTitle="@string/volume_key_cursor_control_title"
android:entries="@array/volume_key_cursor_control_entries"
android:entryValues="@array/volume_key_cursor_control_values"
android:key="volume_key_cursor_control"
android:title="@string/volume_key_cursor_control_title" />
</PreferenceScreen>

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;
}