From f4e3d097fe63c111dff58bd26b42b8fe40dc870d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 1 Jan 2014 23:15:39 -0800 Subject: [PATCH] Make keyboard type show up in preferences list Show the actual current setting of the preference in the summary. --- .../android/ui/SettingsActivity.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/android/src/com/levien/synthesizer/android/ui/SettingsActivity.java b/android/src/com/levien/synthesizer/android/ui/SettingsActivity.java index 6c4e044..9c8eadd 100644 --- a/android/src/com/levien/synthesizer/android/ui/SettingsActivity.java +++ b/android/src/com/levien/synthesizer/android/ui/SettingsActivity.java @@ -1,15 +1,33 @@ package com.levien.synthesizer.android.ui; import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceActivity; import com.levien.synthesizer.R; public class SettingsActivity extends PreferenceActivity { + @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); + ListPreference keyboardTypePref = (ListPreference)findPreference("keyboard_type"); + updateListSummary(keyboardTypePref, keyboardTypePref.getValue()); + keyboardTypePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + public boolean onPreferenceChange(Preference pref, Object newVal) { + updateListSummary(pref, newVal.toString()); + return true; + } + }); + } + + private void updateListSummary(Preference pref, String newVal) { + ListPreference lp = (ListPreference)pref; + int index = lp.findIndexOfValue(newVal); + lp.setSummary(lp.getEntries()[index]); } }