本文整理汇总了Java中android.preference.ListPreference.setValueIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ListPreference.setValueIndex方法的具体用法?Java ListPreference.setValueIndex怎么用?Java ListPreference.setValueIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.ListPreference
的用法示例。
在下文中一共展示了ListPreference.setValueIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeTransportPreference
import android.preference.ListPreference; //导入方法依赖的package包/类
private void initializeTransportPreference(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
entries.add(getString(R.string.pref_transport_udp));
values.add(getString(R.string.pref_transport_udp_key));
entries.add(getString(R.string.pref_transport_tcp));
values.add(getString(R.string.pref_transport_tcp_key));
if (!getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
entries.add(getString(R.string.pref_transport_tls));
values.add(getString(R.string.pref_transport_tls_key));
}
setListPreferenceValues(pref, entries, values);
if (! isNewAccount) {
pref.setSummary(mPrefs.getAccountTransportString(n));
pref.setDefaultValue(mPrefs.getAccountTransportKey(n));
pref.setValueIndex(entries.indexOf(mPrefs.getAccountTransportString(n)));
} else {
pref.setSummary(getString(R.string.pref_transport_udp));
pref.setDefaultValue(getString(R.string.pref_transport_udp));
pref.setValueIndex(entries.indexOf(getString(R.string.pref_transport_udp)));
}
}
示例2: onCreate
import android.preference.ListPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
locationInfo = ConfigPreferences.getLocationConfig(getActivity());
//disable and enable praying notification related setting
if (ConfigPreferences.getPrayingNotification(getActivity()) == false) {
getPreferenceScreen().findPreference("silent").setEnabled(false);
getPreferenceScreen().findPreference("vibration").setEnabled(false);
getPreferenceScreen().findPreference("led").setEnabled(false);
}
//disable or enable silent related settings
if(ConfigPreferences.getSilentMood(getActivity()) == false){
getPreferenceScreen().findPreference("vibration").setEnabled(false);
}
if (locationInfo != null) {
Log.i("DATA_SETTING" ,"locationInfo.dls : "+(locationInfo.dls > 0));
CheckBoxPreference checked = (CheckBoxPreference) getPreferenceScreen().findPreference("day_light");
checked.setChecked(locationInfo.dls > 0);
ListPreference wayPref = (ListPreference) getPreferenceScreen().findPreference("calculations");
Log.i("DATA_SETTING" ,"locationInfo.way : "+locationInfo.way);
wayPref.setValueIndex(locationInfo.way);
ListPreference mazhapPref = (ListPreference) getPreferenceScreen().findPreference("mazhab");
mazhapPref.setValueIndex(locationInfo.mazhab);
Log.i("DATA_SETTING" ,"locationInfo.mazhab : "+locationInfo.mazhab);
}
listPreference = (ListPreference) findPreference("language");
String lang = ConfigPreferences.getApplicationLanguage(getActivity()).equalsIgnoreCase("en") ? "English" : "العربية";
listPreference.setSummary(getString(R.string.language_summary)
+ " (" + lang + ") ");
}
示例3: updateLocationPreferenceForXGeo
import android.preference.ListPreference; //导入方法依赖的package包/类
/**
* Updates the location preference to indicate that the site has access to location (via X-Geo)
* for searches that happen from the omnibox.
* @param preference The Location preference to modify.
*/
private void updateLocationPreferenceForXGeo(Preference preference) {
ListPreference listPreference = (ListPreference) preference;
Resources res = getResources();
listPreference.setEntries(new String[] {
res.getString(R.string.website_settings_permissions_allow_dse),
res.getString(ContentSettingsResources.getSiteSummary(ContentSetting.BLOCK)),
});
listPreference.setEntryValues(new String[] {
ContentSetting.DEFAULT.toString(),
ContentSetting.BLOCK.toString(),
});
listPreference.setValueIndex(0);
}
示例4: inflateCountrySelection
import android.preference.ListPreference; //导入方法依赖的package包/类
private void inflateCountrySelection() {
ListPreference countrySelectionPreference = (ListPreference) findPreference(PreferencesUtils.PREFERENCES_SELECTED_COUNTRY);
countrySelectionPreference.setEntries(LocaleUtils.getAvailableLocales());
countrySelectionPreference.setEntryValues(LocaleUtils.getAvailableIso3Codes());
countrySelectionPreference.setDefaultValue(LocaleUtils.getDeviceLocale(countrySelectionPreference.getContext()));
countrySelectionPreference.setValueIndex(countrySelectionPreference.findIndexOfValue(Prefs.with(countrySelectionPreference.getContext()).read(countrySelectionPreference.getKey(), LocaleUtils.getDeviceLocale(countrySelectionPreference.getContext()))));
bindPreferenceSummaryToValue(countrySelectionPreference);
}
示例5: prepareListPreference
import android.preference.ListPreference; //导入方法依赖的package包/类
private void prepareListPreference(final ListPreference listPreference)
{
if (listPreference == null)
{
return;
}
if (listPreference.getValue() == null)
{
// to ensure we don't get a null value
// set first value by default
listPreference.setValueIndex(0);
}
if (listPreference.getEntry() != null)
{
listPreference.setSummary(listPreference.getEntry().toString());
}
listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
listPreference.setValue(newValue.toString());
preference.setSummary(listPreference.getEntry().toString());
return true;
}
});
}
示例6: setSummaries
import android.preference.ListPreference; //导入方法依赖的package包/类
private void setSummaries(Recipients recipients) {
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
AdvancedRingtonePreference ringtonePreference = (AdvancedRingtonePreference) this.findPreference(PREFERENCE_TONE);
ListPreference vibratePreference = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
ColorPreference colorPreference = (ColorPreference) this.findPreference(PREFERENCE_COLOR);
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
final Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
mutePreference.setChecked(recipients.isMuted());
final Uri toneUri = recipients.getRingtone();
if (toneUri == null) {
ringtonePreference.setSummary(R.string.preferences__default);
ringtonePreference.setCurrentRingtone(Settings.System.DEFAULT_NOTIFICATION_URI);
} else if (toneUri.toString().isEmpty()) {
ringtonePreference.setSummary(R.string.preferences__silent);
ringtonePreference.setCurrentRingtone(null);
} else {
Ringtone tone = RingtoneManager.getRingtone(getActivity(), toneUri);
if (tone != null) {
ringtonePreference.setSummary(tone.getTitle(getActivity()));
ringtonePreference.setCurrentRingtone(toneUri);
}
}
if (recipients.getVibrate() == VibrateState.DEFAULT) {
vibratePreference.setSummary(R.string.preferences__default);
vibratePreference.setValueIndex(0);
} else if (recipients.getVibrate() == VibrateState.ENABLED) {
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_enabled);
vibratePreference.setValueIndex(1);
} else {
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_disabled);
vibratePreference.setValueIndex(2);
}
if (!recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
if (colorPreference != null) getPreferenceScreen().removePreference(colorPreference);
if (blockPreference != null) getPreferenceScreen().removePreference(blockPreference);
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
} else {
colorPreference.setChoices(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(getActivity()));
colorPreference.setValue(recipients.getColor().toActionBarColor(getActivity()));
if (recipients.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
IdentityUtil.getRemoteIdentityKey(getActivity(), masterSecret, recipients.getPrimaryRecipient()).addListener(new ListenableFuture.Listener<Optional<IdentityKey>>() {
@Override
public void onSuccess(Optional<IdentityKey> result) {
if (result.isPresent()) {
if (identityPreference != null) identityPreference.setOnPreferenceClickListener(new IdentityClickedListener(result.get()));
if (identityPreference != null) identityPreference.setEnabled(true);
} else if (canHaveSafetyNumber) {
if (identityPreference != null) identityPreference.setSummary(R.string.RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received);
if (identityPreference != null) identityPreference.setEnabled(false);
} else {
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
}
}
@Override
public void onFailure(ExecutionException e) {
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
}
});
}
}
示例7: setUpListPreference
import android.preference.ListPreference; //导入方法依赖的package包/类
/**
* Initialize a ListPreference with a certain value.
* @param preference The ListPreference to initialize.
* @param value The value to initialize it to.
*/
private void setUpListPreference(Preference preference, ContentSetting value) {
if (value == null) {
getPreferenceScreen().removePreference(preference);
return;
}
ListPreference listPreference = (ListPreference) preference;
int contentType = getContentSettingsTypeFromPreferenceKey(preference.getKey());
CharSequence[] keys = new String[2];
CharSequence[] descriptions = new String[2];
keys[0] = ContentSetting.ALLOW.toString();
keys[1] = ContentSetting.BLOCK.toString();
descriptions[0] = getResources().getString(
ContentSettingsResources.getSiteSummary(ContentSetting.ALLOW));
descriptions[1] = getResources().getString(
ContentSettingsResources.getSiteSummary(ContentSetting.BLOCK));
listPreference.setEntryValues(keys);
listPreference.setEntries(descriptions);
int index = (value == ContentSetting.ALLOW ? 0 : 1);
listPreference.setValueIndex(index);
int explanationResourceId = ContentSettingsResources.getExplanation(contentType);
if (explanationResourceId != 0) {
listPreference.setTitle(explanationResourceId);
}
if (listPreference.isEnabled()) {
SiteSettingsCategory category =
SiteSettingsCategory.fromContentSettingsType(contentType);
if (category != null && !category.enabledInAndroid(getActivity())) {
listPreference.setIcon(category.getDisabledInAndroidIcon(getActivity()));
listPreference.setEnabled(false);
} else {
listPreference.setIcon(ContentSettingsResources.getIcon(contentType));
}
} else {
listPreference.setIcon(
ContentSettingsResources.getDisabledIcon(contentType, getResources()));
}
preference.setSummary("%s");
listPreference.setOnPreferenceChangeListener(this);
}
示例8: setSummaries
import android.preference.ListPreference; //导入方法依赖的package包/类
private void setSummaries(Recipients recipients) {
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
AdvancedRingtonePreference ringtonePreference = (AdvancedRingtonePreference) this.findPreference(PREFERENCE_TONE);
ListPreference vibratePreference = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
ColorPreference colorPreference = (ColorPreference) this.findPreference(PREFERENCE_COLOR);
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
final Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
mutePreference.setChecked(recipients.isMuted());
final Uri toneUri = recipients.getRingtone();
if (toneUri == null) {
ringtonePreference.setSummary(R.string.preferences__default);
ringtonePreference.setCurrentRingtone(Settings.System.DEFAULT_NOTIFICATION_URI);
} else if (toneUri.toString().isEmpty()) {
ringtonePreference.setSummary(R.string.preferences__silent);
ringtonePreference.setCurrentRingtone(null);
} else {
Ringtone tone = RingtoneManager.getRingtone(getActivity(), toneUri);
if (tone != null) {
ringtonePreference.setSummary(tone.getTitle(getActivity()));
ringtonePreference.setCurrentRingtone(toneUri);
}
}
if (recipients.getVibrate() == VibrateState.DEFAULT) {
vibratePreference.setSummary(R.string.preferences__default);
vibratePreference.setValueIndex(0);
} else if (recipients.getVibrate() == VibrateState.ENABLED) {
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_enabled);
vibratePreference.setValueIndex(1);
} else {
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_disabled);
vibratePreference.setValueIndex(2);
}
if (!recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
if (colorPreference != null) getPreferenceScreen().removePreference(colorPreference);
if (blockPreference != null) getPreferenceScreen().removePreference(blockPreference);
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
} else {
colorPreference.setChoices(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(getActivity()));
colorPreference.setValue(recipients.getColor().toActionBarColor(getActivity()));
if (recipients.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
IdentityUtil.getRemoteIdentityKey(getActivity(), recipients.getPrimaryRecipient()).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() {
@Override
public void onSuccess(Optional<IdentityRecord> result) {
if (result.isPresent()) {
if (identityPreference != null) identityPreference.setOnPreferenceClickListener(new IdentityClickedListener(result.get()));
if (identityPreference != null) identityPreference.setEnabled(true);
} else if (canHaveSafetyNumber) {
if (identityPreference != null) identityPreference.setSummary(R.string.RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received);
if (identityPreference != null) identityPreference.setEnabled(false);
} else {
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
}
}
@Override
public void onFailure(ExecutionException e) {
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
}
});
}
}