List of usage examples for android.preference ListPreference getEntry
public CharSequence getEntry()
From source file:de.tum.in.tumcampus.fragments.SettingsFragment.java
void setSummary(String key) { Preference t = findPreference(key);//from w w w . j av a 2s. c om if (t instanceof ListPreference) { ListPreference pref = (ListPreference) t; pref.setSummary(pref.getEntry()); } }
From source file:de.tum.in.tumcampus.fragments.SettingsFragment.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPreference = (ListPreference) pref; listPreference.setSummary(listPreference.getEntry()); }/* www .jav a 2 s .c o m*/ if (key.startsWith("card_")) { CardManager.shouldRefresh = true; } // When newspread selection changes // deselect all newspread sources and select only the // selected source if one of all was selected before if (key.equals("news_newspread")) { SharedPreferences.Editor e = sharedPreferences.edit(); boolean value = false; for (int i = 7; i < 14; i++) { if (sharedPreferences.getBoolean("card_news_source_" + i, false)) value = true; e.putBoolean("card_news_source_" + i, false); } String new_source = sharedPreferences.getString(key, "7"); e.putBoolean("card_news_source_" + new_source, value); e.apply(); CardManager.shouldRefresh = true; } // If the silent mode was activated, start the service. This will invoke // the service to call onHandleIntent which checks available lectures if (key.equals(Const.SILENCE_SERVICE)) { Intent service = new Intent(mContext, SilenceService.class); if (sharedPreferences.getBoolean(key, false)) { mContext.startService(service); } else { mContext.stopService(service); } } // If the background mode was activated, start the service. This will invoke // the service to call onHandleIntent which updates all background data if (key.equals(Const.BACKGROUND_MODE)) { Intent service = new Intent(mContext, BackgroundService.class); if (sharedPreferences.getBoolean(key, false)) { mContext.startService(service); } else { mContext.stopService(service); } } }
From source file:com.syncedsynapse.kore2.ui.SettingsFragment.java
/** * Sets up the preferences state and summaries * @param hasBoughtCoffee Whether the user has bought me a coffee *//* w w w .jav a 2s . co m*/ private void setupPreferences(boolean hasBoughtCoffee) { final Settings settings = Settings.getInstance(getActivity()); LogUtils.LOGD(TAG, "Setting up preferences. Has bought coffee? " + hasBoughtCoffee); // Coffee upgrade final Preference coffeePref = findPreference(Settings.KEY_PREF_COFFEE); if (coffeePref != null) { if (hasBoughtCoffee) { if (settings.showThanksForCofeeMessage) { coffeePref.setTitle(getResources().getString(R.string.thanks_for_coffe)); coffeePref.setSummary(getResources().getString(R.string.remove_coffee_message)); coffeePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { settings.showThanksForCofeeMessage = false; settings.save(); getPreferenceScreen().removePreference(coffeePref); return true; } }); } else { getPreferenceScreen().removePreference(coffeePref); } } else { coffeePref.setTitle(getResources().getString(R.string.buy_me_coffee)); coffeePref.setSummary(getResources().getString(R.string.expresso_please)); coffeePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { launchCoffeePurchase(); return true; } }); } } // Theme preferences ListPreference themePref = (ListPreference) findPreference(Settings.KEY_PREF_THEME); if (hasBoughtCoffee) { themePref.setEnabled(true); themePref.setSummary(themePref.getEntry()); } else { themePref.setEnabled(false); themePref.setSummary(getActivity().getString(R.string.buy_coffee_to_unlock_themes)); } // About preference String nameAndVersion = getActivity().getString(R.string.app_name); try { nameAndVersion += " v" + getActivity().getPackageManager() .getPackageInfo(getActivity().getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException exc) { } Preference aboutPreference = findPreference(Settings.KEY_PREF_ABOUT); aboutPreference.setSummary(nameAndVersion); aboutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { AboutDialogFragment aboutDialog = new AboutDialogFragment(); aboutDialog.show(getActivity().getFragmentManager(), null); return true; } }); }
From source file:com.hichinaschool.flashcards.anki.CramDeckOptions.java
protected void updateSummaries() { mAllowCommit = false;/*from ww w . j a v a2s .c o m*/ // for all text preferences, set summary as current database value for (String key : mPref.mValues.keySet()) { Preference pref = this.findPreference(key); String value = null; if (pref == null) { continue; } else if (pref instanceof CheckBoxPreference) { continue; } else if (pref instanceof ListPreference) { ListPreference lp = (ListPreference) pref; value = lp.getEntry().toString(); } else { value = this.mPref.getString(key, ""); } // update value for EditTexts if (pref instanceof EditTextPreference) { ((EditTextPreference) pref).setText(value); } // update summary if (!mPref.mSummaries.containsKey(key)) { CharSequence s = pref.getSummary(); mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null); } String summ = mPref.mSummaries.get(key); if (summ != null && summ.contains("XXX")) { pref.setSummary(summ.replace("XXX", value)); } else { pref.setSummary(value); } } mAllowCommit = true; }
From source file:com.ichi2.anki.FilteredDeckOptions.java
protected void updateSummaries() { mAllowCommit = false;/* w w w.ja v a 2 s.c o m*/ // for all text preferences, set summary as current database value for (String key : mPref.mValues.keySet()) { Preference pref = this.findPreference(key); String value = null; if (pref == null) { continue; } else if (pref instanceof CheckBoxPreference) { continue; } else if (pref instanceof ListPreference) { ListPreference lp = (ListPreference) pref; CharSequence entry = lp.getEntry(); if (entry != null) { value = entry.toString(); } else { value = ""; } } else { value = this.mPref.getString(key, ""); } // update value for EditTexts if (pref instanceof EditTextPreference) { ((EditTextPreference) pref).setText(value); } // update summary if (!mPref.mSummaries.containsKey(key)) { CharSequence s = pref.getSummary(); mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null); } String summ = mPref.mSummaries.get(key); if (summ != null && summ.contains("XXX")) { pref.setSummary(summ.replace("XXX", value)); } else { pref.setSummary(value); } } mAllowCommit = true; }
From source file:com.mantz_it.rfanalyzer.SettingsFragment.java
/** * Will go through each preference element and initialize/update the summary according to its value. * @note this will also correct invalid user inputs on EdittextPreferences! *//*from w ww . ja va2s . c om*/ public void updateSummaries() { // Source Type ListPreference listPref = (ListPreference) findPreference(getString(R.string.pref_sourceType)); listPref.setSummary(getString(R.string.pref_sourceType_summ, listPref.getEntry())); // Direct Sampling listPref = (ListPreference) findPreference(getString(R.string.pref_rtlsdr_directSamp)); listPref.setSummary(getString(R.string.pref_rtlsdr_directSamp_summ, listPref.getEntry())); // Frequency display listPref = (ListPreference) findPreference(getString(R.string.pref_surface_unit)); listPref.setSummary(getString(R.string.pref_surface_unit_summ, listPref.getEntry())); // FileSource Frequency EditTextPreference editTextPref = (EditTextPreference) findPreference( getString(R.string.pref_filesource_frequency)); if (editTextPref.getText().length() == 0) editTextPref.setText(getString(R.string.pref_filesource_frequency_default)); editTextPref.setSummary(getString(R.string.pref_filesource_frequency_summ, editTextPref.getText())); // FileSource Sample Rate editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_sampleRate)); if (editTextPref.getText().length() == 0) editTextPref.setText(getString(R.string.pref_filesource_sampleRate_default)); editTextPref.setSummary(getString(R.string.pref_filesource_sampleRate_summ, editTextPref.getText())); // FileSource File editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_file)); editTextPref.setSummary(getString(R.string.pref_filesource_file_summ, editTextPref.getText())); // FileSource Format listPref = (ListPreference) findPreference(getString(R.string.pref_filesource_format)); listPref.setSummary(getString(R.string.pref_filesource_format_summ, listPref.getEntry())); // HackRF frequency shift editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_hackrf_frequencyOffset)); if (editTextPref.getText().length() == 0) editTextPref.setText("0"); editTextPref.setSummary(getString(R.string.pref_hackrf_frequencyOffset_summ, editTextPref.getText())); // RTL-SDR IP editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_ip)); editTextPref.setSummary(getString(R.string.pref_rtlsdr_ip_summ, editTextPref.getText())); // RTL-SDR Port editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_port)); editTextPref.setSummary(getString(R.string.pref_rtlsdr_port_summ, editTextPref.getText())); // RTL-SDR frequency correction editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyCorrection)); if (editTextPref.getText().length() == 0) editTextPref.setText(getString(R.string.pref_rtlsdr_frequencyCorrection_default)); editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyCorrection_summ, editTextPref.getText())); // RTL-SDR frequency shift editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyOffset)); if (editTextPref.getText().length() == 0) editTextPref.setText("0"); editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyOffset_summ, editTextPref.getText())); // FFT size listPref = (ListPreference) findPreference(getString(R.string.pref_fftSize)); listPref.setSummary(getString(R.string.pref_fftSize_summ, listPref.getEntry())); // Color map type listPref = (ListPreference) findPreference(getString(R.string.pref_colorMapType)); listPref.setSummary(getString(R.string.pref_colorMapType_summ, listPref.getEntry())); // FFT drawing type listPref = (ListPreference) findPreference(getString(R.string.pref_fftDrawingType)); listPref.setSummary(getString(R.string.pref_fftDrawingType_summ, listPref.getEntry())); // Averaging listPref = (ListPreference) findPreference(getString(R.string.pref_averaging)); listPref.setSummary(getString(R.string.pref_averaging_summ, listPref.getEntry())); // Screen Orientation listPref = (ListPreference) findPreference(getString(R.string.pref_screenOrientation)); listPref.setSummary(getString(R.string.pref_screenOrientation_summ, listPref.getEntry())); // Spectrum Waterfall Ratio listPref = (ListPreference) findPreference(getString(R.string.pref_spectrumWaterfallRatio)); listPref.setSummary(getString(R.string.pref_spectrumWaterfallRatio_summ, listPref.getEntry())); // Font Size listPref = (ListPreference) findPreference(getString(R.string.pref_fontSize)); listPref.setSummary(getString(R.string.pref_fontSize_summ, listPref.getEntry())); // Frame Rate SwitchPreference switchPref = (SwitchPreference) findPreference(getString(R.string.pref_dynamicFrameRate)); listPref = (ListPreference) findPreference(getString(R.string.pref_frameRate)); if (switchPref.isChecked()) listPref.setSummary(getString(R.string.pref_frameRate_summ, "auto")); else listPref.setSummary(getString(R.string.pref_frameRate_summ, listPref.getEntry())); // Logfile editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_logfile)); editTextPref.setSummary(getString(R.string.pref_logfile_summ, editTextPref.getText())); // Shared preferences updated in e.g. the onRequestPermissionResult() method are // not automatically updated in the preference fragment gui. do it manually: SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); switchPref = (SwitchPreference) findPreference(getString(R.string.pref_logging)); switchPref.setChecked(preferences.getBoolean(getString(R.string.pref_logging), false)); }
From source file:org.adblockplus.android.Preferences.java
/** * Constructs and updates subscription status text. * * @param text//from w w w .j a v a2 s. c o m * status message * @param time * time of last change */ private void setSubscriptionStatus(final String text, final long time) { final ListPreference subscriptionList = (ListPreference) findPreference( getString(R.string.pref_subscription)); final CharSequence summary = subscriptionList.getEntry(); final StringBuilder builder = new StringBuilder(); if (summary != null) { builder.append(summary); if (StringUtils.isNotEmpty(text)) { builder.append(" ("); final int id = getResources().getIdentifier(text, "string", getPackageName()); if (id > 0) builder.append(getString(id, text)); else builder.append(text); if (time > 0) { builder.append(": "); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); final Date date = calendar.getTime(); builder.append(DateFormat.getDateFormat(this).format(date)); builder.append(" "); builder.append(DateFormat.getTimeFormat(this).format(date)); } builder.append(")"); } subscriptionSummary = builder.toString(); subscriptionList.setSummary(subscriptionSummary); } }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); Resources resources = getResources(); TwoStatePreference runningPref = findPref("running_switch"); updateRunningState();// ww w. ja va 2 s.co m runningPref.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { startServer(); } else { stopServer(); } return true; }); PreferenceScreen prefScreen = findPref("preference_screen"); Preference marketVersionPref = findPref("market_version"); marketVersionPref.setOnPreferenceClickListener(preference -> { // start the market at our application Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp")); try { // this can fail if there is no market installed startActivity(intent); } catch (Exception e) { Cat.e("Failed to launch the market."); e.printStackTrace(); } return false; }); if (!App.isFreeVersion()) { prefScreen.removePreference(marketVersionPref); } updateLoginInfo(); EditTextPreference usernamePref = findPref("username"); usernamePref.setOnPreferenceChangeListener((preference, newValue) -> { String newUsername = (String) newValue; if (preference.getSummary().equals(newUsername)) return false; if (!newUsername.matches("[a-zA-Z0-9]+")) { Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show(); return false; } stopServer(); return true; }); mPassWordPref = findPref("password"); mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); mAutoconnectListPref = findPref("autoconnect_preference"); mAutoconnectListPref.setOnPopulateListener(pref -> { Cat.d("autoconnect populate listener"); WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); if (configs == null) { Cat.e("Unable to receive wifi configurations, bark at user and bail"); Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points, Toast.LENGTH_LONG).show(); return; } CharSequence[] ssids = new CharSequence[configs.size()]; CharSequence[] niceSsids = new CharSequence[configs.size()]; for (int i = 0; i < configs.size(); ++i) { ssids[i] = configs.get(i).SSID; String ssid = configs.get(i).SSID; if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } niceSsids[i] = ssid; } pref.setEntries(niceSsids); pref.setEntryValues(ssids); }); mAutoconnectListPref.setOnPreferenceClickListener(preference -> { Cat.d("Clicked"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) { if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)) { new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title) .setMessage(R.string.request_coarse_location_dlg_message) .setPositiveButton(android.R.string.ok, (dialog, which) -> { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); }).setOnCancelListener(dialog -> { mAutoconnectListPref.getDialog().cancel(); }).create().show(); } else { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); } } } return false; }); EditTextPreference portnum_pref = findPref("portNum"); portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default))); portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> { String newPortnumString = (String) newValue; if (preference.getSummary().equals(newPortnumString)) return false; int portnum = 0; try { portnum = Integer.parseInt(newPortnumString); } catch (Exception e) { Cat.d("Error parsing port number! Moving on..."); } if (portnum <= 0 || 65535 < portnum) { Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show(); return false; } preference.setSummary(newPortnumString); stopServer(); return true; }); Preference chroot_pref = findPref("chrootDir"); chroot_pref.setSummary(FsSettings.getChrootDirAsString()); chroot_pref.setOnPreferenceClickListener(preference -> { AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir()) .setSelectedButton(R.string.select, path -> { if (preference.getSummary().equals(path)) return; if (!FsSettings.setChrootDir(path)) return; // TODO: this is a hotfix, create correct resources, improve UI/UX final File root = new File(path); if (!root.canRead()) { Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.", Toast.LENGTH_LONG).show(); } else if (!root.canWrite()) { Toast.makeText(getActivity(), "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.", Toast.LENGTH_LONG).show(); } preference.setSummary(path); stopServer(); }).setNegativeButton(R.string.cancel, null).create(); folderPicker.show(); return true; }); final CheckBoxPreference wakelock_pref = findPref("stayAwake"); wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage"); String externalStorageUri = FsSettings.getExternalStorageUri(); if (externalStorageUri == null) { writeExternalStorage_pref.setChecked(false); } writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> { if ((boolean) newValue) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE); return false; } else { FsSettings.setExternalStorageUri(null); return true; } }); ListPreference theme = findPref("theme"); theme.setSummary(theme.getEntry()); theme.setOnPreferenceChangeListener((preference, newValue) -> { theme.setSummary(theme.getEntry()); getActivity().recreate(); return true; }); Preference help = findPref("help"); help.setOnPreferenceClickListener(preference -> { Cat.v("On preference help clicked"); Context context = getActivity(); AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title) .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create(); ad.show(); Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL); return true; }); Preference about = findPref("about"); about.setOnPreferenceClickListener(preference -> { startActivity(new Intent(getActivity(), AboutActivity.class)); return true; }); }
From source file:com.hichinaschool.flashcards.anki.DeckOptions.java
protected void updateSummaries() { Resources res = getResources(); // for all text preferences, set summary as current database value for (String key : mPref.mValues.keySet()) { Preference pref = this.findPreference(key); if (key.equals("deckConf")) { String groupName = getOptionsGroupName(); int count = getOptionsGroupCount(); pref.setSummary(res.getQuantityString(R.plurals.deck_conf_group_summ, count, groupName, count)); continue; }/* ww w. j a v a 2 s. c o m*/ String value = null; if (pref == null) { continue; } else if (pref instanceof CheckBoxPreference) { continue; } else if (pref instanceof ListPreference) { ListPreference lp = (ListPreference) pref; value = lp.getEntry() != null ? lp.getEntry().toString() : ""; } else { value = this.mPref.getString(key, ""); } // update summary if (!mPref.mSummaries.containsKey(key)) { CharSequence s = pref.getSummary(); mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null); } String summ = mPref.mSummaries.get(key); if (summ != null && summ.contains("XXX")) { pref.setSummary(summ.replace("XXX", value)); } else { pref.setSummary(value); } } // Update summaries of preference items that don't have values (aren't in mValues) int subDeckCount = getSubdeckCount(); this.findPreference("confSetSubdecks").setSummary( res.getQuantityString(R.plurals.deck_conf_set_subdecks_summ, subDeckCount, subDeckCount)); }
From source file:com.ichi2.anki2.DeckOptions.java
protected void updateSummaries() { // for all text preferences, set summary as current database value for (String key : mPref.mValues.keySet()) { Preference pref = this.findPreference(key); String value = null;/*from ww w . j ava 2 s . co m*/ if (pref == null) { continue; } else if (pref instanceof CheckBoxPreference) { continue; } else if (pref instanceof ListPreference) { ListPreference lp = (ListPreference) pref; value = lp.getEntry() != null ? lp.getEntry().toString() : ""; } else { value = this.mPref.getString(key, ""); } // update summary if (!mPref.mSummaries.containsKey(key)) { CharSequence s = pref.getSummary(); mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null); } String summ = mPref.mSummaries.get(key); if (summ != null && summ.contains("XXX")) { pref.setSummary(summ.replace("XXX", value)); } else { pref.setSummary(value); } } }