private void setPreferenceSummary(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list (since they have separate labels/values). ListPreference listPreference = (ListPreference) preference; int prefIndex = listPreference.findIndexOfValue(stringValue); if (prefIndex >= 0) { preference.setSummary(listPreference.getEntries()[prefIndex]); } } else { // For other preferences, set the summary to the value's simple string representation. preference.setSummary(stringValue); } }
/** * Updates the summary for the preference * * @param preference The preference to be updated * @param value The value that the preference was updated to */ private void setPreferenceSummary(Preference preference, String value) { if (preference instanceof ListPreference) { // For list preferences, figure out the label of the selected value ListPreference listPreference = (ListPreference) preference; int prefIndex = listPreference.findIndexOfValue(value); if (prefIndex >= 0) { // Set the summary to that label listPreference.setSummary(listPreference.getEntries()[prefIndex]); } } }
private static void sync(PreferenceManager preferenceManager, String key) { Preference pref = preferenceManager.findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummary(listPref.getEntry()); } }
@Override public boolean onPreferenceChange(Preference preference, final Object newValue) { pref.setTitle( pref.getEntries()[ pref.findIndexOfValue(newValue.toString()) ]); return true; } });
final CharSequence[] entries = languagePref.getEntries(); String value = sharedPref.getString("language", ""); int index = languagePref.findIndexOfValue(value); languagePref.setSummary(entries[index]); languagePref.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override
if (pref.getEntries() != null) e.addAll(Arrays.asList(pref.getEntries())); if (pref.getEntryValues() != null) ev.addAll(Arrays.asList(pref.getEntryValues())); pref.setEntries(e.toArray(new CharSequence[e.size()])); pref.setEntryValues(ev.toArray(new CharSequence[ev.size()])); pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, final Object newValue) { CharSequence[] entries = pref.getEntries(); boolean enabled = entries != null && entries.length > 0; pref.setEnabled(enabled);
private void initThemePref(String theme) { ListPreference themePref = (ListPreference) findPreference(getString(R.string.pref_key_theme)); String theme_name = Settings.Utils.getThemeName(getActivity(), theme); themePref.setSummary(theme_name); themePref.setOnPreferenceChangeListener(this); }
protected void updateSketchbookDrivePref(ListPreference sketchbookDrive, Preference sketchbookLocation, ArrayList<APDE.StorageDrive> drives) { int selectedIndex = sketchbookDrive.findIndexOfValue(sketchbookDrive.getValue()); if (selectedIndex == -1) { //Uh-oh return; } APDE.StorageDrive selected = drives.get(selectedIndex); sketchbookLocation.setEnabled(!(selected.type.equals(APDE.StorageDrive.StorageDriveType.INTERNAL) || selected.type.equals(APDE.StorageDrive.StorageDriveType.SECONDARY_EXTERNAL))); sketchbookDrive.setSummary(selected.space + " " + selected.type.title); }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (KEY_EXPORT_DATA_FORMAT_LIST.equals(key)) { listPreference.setSummary("Current format is " + listPreference.getEntry().toString()); } } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { editor.putString("language", (String) newValue).commit(); languagePref.setSummary(entries[languagePref.findIndexOfValue( (String) newValue)]); Intent intent = new Intent(context, MainActivity.class); context.finish(); startActivity(intent); return true; } });
if (listPreference.getValue() == null) listPreference.setValueIndex(0); if (listPreference.getEntry() != null) listPreference.setSummary(listPreference.getEntry().toString()); listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
pUMSpeed.setEntries(R.array.UMSpeed_Metric); pGPSDistance.setEntries(R.array.GPSDistance_Metric); pAltitudeCorrection.setSummary(altcor != 0 ? getString(R.string.pref_AltitudeCorrection_summary_offset) + " = " + Double.valueOf(Math.round(altcor*1000d)/1000d).toString() + " m" : getString(R.string.pref_AltitudeCorrection_summary_not_defined)); pUMSpeed.setEntries(R.array.UMSpeed_Imperial); pGPSDistance.setEntries(R.array.GPSDistance_Imperial); pAltitudeCorrection.setSummary(altcor != 0 ? getString(R.string.pref_AltitudeCorrection_summary_offset) + " = " + Double.valueOf(Math.round(altcor*1000d)/1000d).toString() + " ft" : getString(R.string.pref_AltitudeCorrection_summary_not_defined)); pUMSpeed.setEntries(R.array.UMSpeed_AerialNautical); pGPSDistance.setEntries(R.array.GPSDistance_Imperial); pAltitudeCorrection.setSummary(altcor != 0 ? getString(R.string.pref_AltitudeCorrection_summary_offset) + " = " + Double.valueOf(Math.round(altcor*1000d)/1000d).toString() + " ft" : getString(R.string.pref_AltitudeCorrection_summary_not_defined)); pUMSpeed.setSummary(pUMSpeed.getEntry()); pUM.setSummary(pUM.getEntry()); pGPSDistance.setSummary(pGPSDistance.getEntry()); pGPSUpdateFrequency.setSummary(pGPSUpdateFrequency.getEntry()); pKMLAltitudeMode.setSummary(pKMLAltitudeMode.getEntry()); pGPXVersion.setSummary(pGPXVersion.getEntry()); pShowTrackStatsType.setSummary(pShowTrackStatsType.getEntry()); pShowDirections.setSummary(pShowDirections.getEntry()); pViewTracksWith.setSummary(pViewTracksWith.getEntry());
private void initNotificationPart(SharedPreferences sharedPreferences) { notificationIconStyle.setSummary( ValueUtils.getIconStyle( getActivity(), sharedPreferences.getString(getString(R.string.key_notification_icon_style), "material"))); notificationIconStyle.setOnPreferenceChangeListener(this); notificationTextColor.setSummary( ValueUtils.getNotificationTextColor( getActivity(), sharedPreferences.getString(getString(R.string.key_notification_text_color), "dark"))); notificationTextColor.setOnPreferenceChangeListener(this); notificationIconStyle.setEnabled(true); notificationTempIcon.setEnabled(true); notificationTextColor.setEnabled(true); notificationBackground.setEnabled(true); notificationClearFlag.setEnabled(true); } else { notificationIconStyle.setEnabled(false); notificationTempIcon.setEnabled(false); notificationTextColor.setEnabled(false); notificationBackground.setEnabled(false); notificationClearFlag.setEnabled(false);
value[i] = Tools.getprop(Constants.props[i]); if (value[i] == null || value[i].isEmpty()) { props[i].setValue(""); summary = getString(R.string.unknown); props[i].setSummary(summary); props[i].setIcon(R.drawable.interrogation); } else { props[i].setValue(value[i]); summary = value[i]; props[i].setSummary(summary); props[i].setIcon(summary.equals(Constants.props_OK[i]) ? R.drawable.ok : R.drawable.warning);
public void onClick(DialogInterface dialog, int id) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor1 = settings.edit(); editor1.putString("prefKMLAltitudeMode", "0"); editor1.commit(); ListPreference pKMLAltitudeMode = (ListPreference) findPreference("prefKMLAltitudeMode"); pKMLAltitudeMode.setValue("0"); pKMLAltitudeMode.setSummary(R.string.pref_KML_altitude_mode_absolute); } });
private String summarizeBackupScheduleSettings(boolean isEnabled) { if (!isEnabled) { return null; } final StringBuilder summary = new StringBuilder(); final ListPreference regSchedule = (ListPreference) findPreference(REGULAR_TIMEOUT_SECONDS.key); final ListPreference incomingSchedule = (ListPreference) findPreference(INCOMING_TIMEOUT_SECONDS.key); // values are out-of sync regSchedule.setValue(String.valueOf(preferences.getRegularTimeoutSecs())); incomingSchedule.setValue(String.valueOf(preferences.getIncomingTimeoutSecs())); summary.append(regSchedule.getTitle()) .append(": ") .append(regSchedule.getEntry()) .append(", ") .append(incomingSchedule.getTitle()) .append(": ") .append(incomingSchedule.getEntry()); if (preferences.isWifiOnly()) { summary.append(" (") .append(findPreference(WIFI_ONLY.key).getTitle()) .append(")"); } return summary.toString(); }
@Override public void setValue(String value) { super.setValue(value); syncSummary(); }
temp_value = ""; props[i] = (ListPreference) findPreference(Constants.props[i]); props[i].setOnPreferenceChangeListener(this); temp_value = Tools.getprop(Constants.props[i]); CharSequence[] entries = { "" }; props[i].setEntries(entries); props[i].setEntryValues(entryValues);
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { listPreference.setValue(newValue.toString()); preference.setSummary(listPreference.getEntry().toString()); if (activity != null) { final Intent intent = activity.getIntent(); activity.finish(); activity.startActivity(intent); } return true; } });
mShowFabPolicyPreference.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override mShowFabPolicyPreference.getValue()));