1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-14 05:25:07 -05:00
k-9/src/com/fsck/k9/activity/K9PreferenceActivity.java
Joe Steele e4d26b8c75 Remove code for unsupported API levels
An assortment of miscellaneous changes, each usually limited in scope to a
single file.
2014-08-19 17:17:55 -04:00

82 lines
2.9 KiB
Java

package com.fsck.k9.activity;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import com.fsck.k9.K9;
public class K9PreferenceActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle icicle) {
K9ActivityCommon.setLanguage(this, K9.getK9Language());
setTheme(K9.getK9ThemeResourceId());
super.onCreate(icicle);
}
/**
* Set up the {@link ListPreference} instance identified by {@code key}.
*
* @param key
* The key of the {@link ListPreference} object.
* @param value
* Initial value for the {@link ListPreference} object.
*
* @return The {@link ListPreference} instance identified by {@code key}.
*/
protected ListPreference setupListPreference(final String key, final String value) {
final ListPreference prefView = (ListPreference) findPreference(key);
prefView.setValue(value);
prefView.setSummary(prefView.getEntry());
prefView.setOnPreferenceChangeListener(new PreferenceChangeListener(prefView));
return prefView;
}
/**
* Initialize a given {@link ListPreference} instance.
*
* @param prefView
* The {@link ListPreference} instance to initialize.
* @param value
* Initial value for the {@link ListPreference} object.
* @param entries
* Sets the human-readable entries to be shown in the list.
* @param entryValues
* The array to find the value to save for a preference when an
* entry from entries is selected.
*/
protected void initListPreference(final ListPreference prefView, final String value,
final CharSequence[] entries, final CharSequence[] entryValues) {
prefView.setEntries(entries);
prefView.setEntryValues(entryValues);
prefView.setValue(value);
prefView.setSummary(prefView.getEntry());
prefView.setOnPreferenceChangeListener(new PreferenceChangeListener(prefView));
}
/**
* This class handles value changes of the {@link ListPreference} objects.
*/
private static class PreferenceChangeListener implements Preference.OnPreferenceChangeListener {
private ListPreference mPrefView;
private PreferenceChangeListener(final ListPreference prefView) {
this.mPrefView = prefView;
}
/**
* Show the preference value in the preference summary field.
*/
@Override
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
final String summary = newValue.toString();
final int index = mPrefView.findIndexOfValue(summary);
mPrefView.setSummary(mPrefView.getEntries()[index]);
mPrefView.setValue(summary);
return false;
}
}
}