List of usage examples for android.preference ListPreference getValue
public String getValue()
From source file:com.windnow.SettingsActivity.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_type_prefs); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { getActionBar().setDisplayHomeAsUpEnabled(true); }//ww w.jav a2s . c o m addPreferencesFromResource(R.xml.pref_general); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); Preference p = findPreference("user_dir"); EditTextPreference editTextPref = (EditTextPreference) p; p.setSummary(getString(R.string.pref_dialog_sum_dir) + " " + editTextPref.getText()); Preference q = findPreference("pref_list"); ListPreference listPref = (ListPreference) q; q.setSummary(getString(R.string.maximum_number_summary) + " " + listPref.getValue()); }
From source file:com.windnow.SettingsActivity.java
@SuppressWarnings("deprecation") @Override/*w ww . jav a2 s .co m*/ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Preference p = findPreference(key); if (p.getKey().equals("pref_list") && p instanceof ListPreference) { MainActivity.maxRetries = Integer.parseInt(prefs.getString("pref_list", "5")); ListPreference listPref = (ListPreference) p; p.setSummary(getString(R.string.maximum_number_summary) + " " + listPref.getValue()); } if (p.getKey().equals("user_dir") && p instanceof EditTextPreference) { LoadSaveOps.userDir = prefs.getString("user_dir", "WindNow"); EditTextPreference editTextPref = (EditTextPreference) p; p.setSummary(getString(R.string.pref_dialog_sum_dir) + " " + editTextPref.getText()); } }
From source file:fr.free.nrw.commons.settings.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { AndroidInjection.inject(this); super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); // Update spinner to show selected value as summary ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE); licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue()))); // Keep summary updated when changing value licensePreference.setOnPreferenceChangeListener((preference, newValue) -> { preference.setSummary(getString(Utils.licenseNameFor((String) newValue))); return true; });/*from ww w . j a v a 2 s . c o m*/ CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme"); themePreference.setOnPreferenceChangeListener((preference, newValue) -> { getActivity().recreate(); return true; }); final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads"); int uploads = prefs.getInt(Prefs.UPLOADS_SHOWING, 100); uploadLimit.setText(uploads + ""); uploadLimit.setSummary(uploads + ""); uploadLimit.setOnPreferenceChangeListener((preference, newValue) -> { int value = Integer.parseInt(newValue.toString()); final SharedPreferences.Editor editor = prefs.edit(); if (value > 500) { new AlertDialog.Builder(getActivity()).setTitle(R.string.maximum_limit) .setMessage(R.string.maximum_limit_alert) .setPositiveButton(android.R.string.yes, (dialog, which) -> { }).setIcon(android.R.drawable.ic_dialog_alert).show(); editor.putInt(Prefs.UPLOADS_SHOWING, 500); editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); uploadLimit.setSummary(500 + ""); uploadLimit.setText(500 + ""); } else { editor.putInt(Prefs.UPLOADS_SHOWING, Integer.parseInt(newValue.toString())); editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); uploadLimit.setSummary(newValue.toString()); } editor.apply(); return true; }); Preference sendLogsPreference = findPreference("sendLogFile"); sendLogsPreference.setOnPreferenceClickListener(preference -> { //first we need to check if we have the necessary permissions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { sendAppLogsViaEmail(); } else { //first get the necessary permission requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_CODE_WRITE_EXTERNAL_STORAGE); } } else { sendAppLogsViaEmail(); } return true; }); }
From source file:bander.notepad.PrefsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); ListPreference sortOrderPreference = (ListPreference) findPreference(KEY_SORTORDER); sortOrderPreference.setOnPreferenceChangeListener(this); setSortOrderSummary(sortOrderPreference); setSortAscendingEnabled(!sortOrderPreference.getValue().equals("0")); ListPreference textSizePreference = (ListPreference) findPreference(KEY_TEXTSIZE); textSizePreference.setOnPreferenceChangeListener(this); setTextSizeSummary(textSizePreference); ListPreference themePreference = (ListPreference) findPreference(KEY_THEME_TYPE); themePreference.setOnPreferenceChangeListener(this); ListPreference colorSchemePreference = (ListPreference) findPreference(KEY_COLOR); colorSchemePreference.setOnPreferenceChangeListener(this); Preference aboutPreference = findPreference(KEY_ABOUT); aboutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override//from w ww. j a v a 2 s . c om public boolean onPreferenceClick(Preference preference) { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); About.newInstance().show(ft, "dialog"); return false; } }); }
From source file:org.dmfs.webcal.fragments.PreferencesFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.webcal_preference); ListPreference locales = (ListPreference) findPreference("content_location"); locales.setOnPreferenceChangeListener(PrefUpdater); try {/* w w w . j a v a2s. c o m*/ getCountries(); locales.setEntries(mCountryNames); locales.setEntryValues(mCountryCodes); } catch (Exception e) { Log.e(TAG, "could not load country list", e); } int index = locales.findIndexOfValue(locales.getValue()); if (index >= 0) { locales.setSummary(locales.getEntries()[index]); } else { locales.setSummary(locales.getEntries()[0]); locales.setValueIndex(0); } }
From source file:mx.klozz.xperience.tweaker.fragments.CPUAdvanced.java
private void setlistPref(ListPreference l, String p, String s) { final String v = l.getValue(); if (!v.equals(Helpers.LeerUnaLinea(p))) { new CMDProcessor().su.runWaitFor("busybox echo " + v + " > " + p); }/*from ww w. j ava 2 s . c o m*/ l.setSummary(s); }
From source file:ml.puredark.hviewer.ui.fragments.SettingFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesName(SharedPreferencesUtil.FILE_NAME); addPreferencesFromResource(R.xml.preferences); String downloadPath = DownloadManager.getDownloadPath(); if (downloadPath != null) { String displayPath = Uri.decode(downloadPath); getPreferenceManager().findPreference(KEY_PREF_DOWNLOAD_PATH).setSummary(displayPath); }//from w ww. j a v a 2s .c o m ListPreference listPreference = (ListPreference) getPreferenceManager() .findPreference(KEY_PREF_VIEW_DIRECTION); CharSequence[] entries = listPreference.getEntries(); int i = listPreference.findIndexOfValue(listPreference.getValue()); i = (i <= 0) ? 0 : i; listPreference.setSummary(entries[i]); listPreference.setOnPreferenceChangeListener(this); listPreference = (ListPreference) getPreferenceManager().findPreference(KEY_PREF_VIEW_VIDEO_PLAYER); entries = listPreference.getEntries(); i = listPreference.findIndexOfValue(listPreference.getValue()); i = (i <= 0) ? 0 : i; listPreference.setSummary(entries[i]); listPreference.setOnPreferenceChangeListener(this); getPreferenceScreen().setOnPreferenceChangeListener(this); final DirectoryChooserConfig config = DirectoryChooserConfig.builder() .initialDirectory((downloadPath.startsWith("/")) ? downloadPath : DownloadManager.DEFAULT_PATH) .newDirectoryName("download").allowNewDirectoryNameModification(true).build(); mDialog = DirectoryChooserFragment.newInstance(config); mDialog.setTargetFragment(this, 0); float size = (float) Fresco.getImagePipelineFactory().getMainFileCache().getSize() / ByteConstants.MB; Preference cacheCleanPreference = getPreferenceManager().findPreference(KEY_PREF_CACHE_CLEAN); cacheCleanPreference.setSummary(String.format(" %.2f MB", size)); LongClickPreference prefDownloadPath = (LongClickPreference) getPreferenceManager() .findPreference(KEY_PREF_DOWNLOAD_PATH); prefDownloadPath.setOnLongClickListener(v -> { new AlertDialog.Builder(activity).setTitle("?") .setItems(new String[] { "", "" }, (dialogInterface, pos) -> { if (pos == 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); try { startActivityForResult(intent, RESULT_CHOOSE_DIRECTORY); } catch (ActivityNotFoundException e) { e.printStackTrace(); mDialog.show(getFragmentManager(), null); } new Handler().postDelayed(() -> { if (!opened) activity.showSnackBar( "?"); }, 1000); } else if (pos == 1) { mDialog.show(getFragmentManager(), null); } else activity.showSnackBar("???"); }) .setNegativeButton(getString(R.string.cancel), null).show(); return true; }); }
From source file:com.schoentoon.connectbot.HostEditorActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); getSupportActionBar().setSubtitle("Host editor"); getSupportActionBar().setDisplayHomeAsUpEnabled(true); long hostId = this.getIntent().getLongExtra(Intent.EXTRA_TITLE, -1); // TODO: we could pass through a specific ContentProvider uri here //this.getPreferenceManager().setSharedPreferencesName(uri); this.hostdb = new HostDatabase(this); this.pubkeydb = new PubkeyDatabase(this); host = hostdb.findHostById(hostId);// w w w . j a v a 2 s. c om connection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService(); hostBridge = bound.getConnectedBridge(host); } public void onServiceDisconnected(ComponentName name) { hostBridge = null; } }; this.pref = new CursorPreferenceHack(HostDatabase.TABLE_HOSTS, hostId); this.pref.registerOnSharedPreferenceChangeListener(this); this.addPreferencesFromResource(R.xml.host_prefs); // add all existing pubkeys to our listpreference for user to choose from // TODO: may be an issue here when this activity is recycled after adding a new pubkey // TODO: should consider moving into onStart, but we dont have a good way of resetting the listpref after filling once ListPreference pubkeyPref = (ListPreference) this.findPreference(HostDatabase.FIELD_HOST_PUBKEYID); List<CharSequence> pubkeyNicks = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntries())); pubkeyNicks.addAll(pubkeydb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME)); pubkeyPref.setEntries(pubkeyNicks.toArray(new CharSequence[pubkeyNicks.size()])); List<CharSequence> pubkeyIds = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntryValues())); pubkeyIds.addAll(pubkeydb.allValues("_id")); pubkeyPref.setEntryValues(pubkeyIds.toArray(new CharSequence[pubkeyIds.size()])); // Populate the character set encoding list with all available final ListPreference charsetPref = (ListPreference) findPreference(HostDatabase.FIELD_HOST_ENCODING); if (CharsetHolder.isInitialized()) { initCharsetPref(charsetPref); } else { String[] currentCharsetPref = new String[1]; currentCharsetPref[0] = charsetPref.getValue(); charsetPref.setEntryValues(currentCharsetPref); charsetPref.setEntries(currentCharsetPref); new Thread(new Runnable() { public void run() { initCharsetPref(charsetPref); } }).start(); } this.updateSummaries(); }
From source file:com.p3authentication.preferences.Prefs.java
@SuppressWarnings("deprecation") @Override/*from w ww .j a va 2s .c o m*/ public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); addPreferencesFromResource(R.xml.pref); AccessPin = (EditTextPreference) getPreferenceManager().findPreference("KeypadKey"); final Preference ResetPreference = getPreferenceManager().findPreference("reset_data"); final Preference EULAPreference = getPreferenceManager().findPreference("eula"); final Preference AboutUsPreference = getPreferenceManager().findPreference("about_us"); final Preference UnlockAppsPreference = getPreferenceManager().findPreference("unlock_apps"); final Preference TouchTolerance = getPreferenceManager().findPreference("touch_tolerance"); final Preference RedownloadImage = getPreferenceManager().findPreference("redownload_images"); final Preference RateApp = getPreferenceManager().findPreference("rate_app"); final CheckBoxPreference GhostStatusPref = (CheckBoxPreference) getPreferenceManager() .findPreference("GhostStatus"); final CheckBoxPreference StartServicePref = (CheckBoxPreference) getPreferenceManager() .findPreference("startup_service"); final ListPreference patterntype = (ListPreference) getPreferenceManager().findPreference("PatternType"); final ListPreference PatternStealth = (ListPreference) getPreferenceManager() .findPreference("PatternStealth"); if (patterntype.getValue().toString().equals("No Pattern")) { PatternStealth.setEnabled(false); } else { PatternStealth.setEnabled(true); } if (GhostStatusPref.isChecked()) { AccessPin.setEnabled(true); } else { AccessPin.setEnabled(false); } AccessPin.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub if (newValue.toString().trim().equals("")) { Toast.makeText(Prefs.this, "Your Custom PIN cannot be empty.", Toast.LENGTH_LONG).show(); return false; } else if (newValue.toString().length() < 5) { Toast.makeText(Prefs.this, "Your Custom PIN must be atleast 5 Digits.", Toast.LENGTH_LONG) .show(); return false; } Toast.makeText(Prefs.this, "Your Custom PIN is set.", Toast.LENGTH_LONG).show(); return true; } }); GhostStatusPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.toString().equals("true")) { hideLauncherIcon(); Toast.makeText(Prefs.this, "P3 hidden from App Menu", Toast.LENGTH_SHORT).show(); } else { showLauncherIcon(); Toast.makeText(Prefs.this, "P3 visible on App Menu", Toast.LENGTH_SHORT).show(); } return true; } }); StartServicePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.toString().equals("true")) { ComponentName receiver = new ComponentName(Prefs.this, Startup.class); PackageManager pm = getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { ComponentName receiver = new ComponentName(Prefs.this, Startup.class); PackageManager pm = getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } return true; } }); patterntype.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub if (!newValue.toString().equals("No Pattern")) { PatternStealth.setEnabled(true); } else { PatternStealth.setEnabled(false); } return true; } }); ResetPreference.setOnPreferenceClickListener(this); UnlockAppsPreference.setOnPreferenceClickListener(this); TouchTolerance.setOnPreferenceClickListener(this); RedownloadImage.setOnPreferenceClickListener(this); RateApp.setOnPreferenceClickListener(this); AboutUsPreference.setOnPreferenceClickListener(this); EULAPreference.setOnPreferenceClickListener(this); }
From source file:com.xorcode.andtweet.PreferencesActivity.java
protected void showListPreference(String keyPreference, int keysR, int displayR, int summaryR) { String displayParm = ""; ListPreference lP = (ListPreference) findPreference(keyPreference); if (lP != null) { String[] k = getResources().getStringArray(keysR); String[] d = getResources().getStringArray(displayR); displayParm = d[0];/* w ww . j av a 2 s . com*/ String listValue = lP.getValue(); for (int i = 0; i < k.length; i++) { if (listValue.equals(k[i])) { displayParm = d[i]; break; } } } else { displayParm = keyPreference + " was not found"; } MessageFormat sf = new MessageFormat(getText(summaryR).toString()); lP.setSummary(sf.format(new Object[] { displayParm })); }