List of usage examples for android.preference ListPreference setSummary
@Override public void setSummary(CharSequence summary)
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 w w w .j av a 2 s . com*/ 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); }/* w ww . j ava 2 s . 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.nttec.everychan.chans.dobrochan.DobroModule.java
private void addRatingPreference(PreferenceGroup group) { Context context = group.getContext(); Preference.OnPreferenceChangeListener updateRatingListener = new Preference.OnPreferenceChangeListener() { @Override/* w w w. j a va 2 s . co m*/ public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals(getSharedKey(PREF_KEY_MAX_RATING))) { setMaxRating((String) newValue); return true; } return false; } }; ListPreference ratingPref = new LazyPreferences.ListPreference(context); ratingPref.setTitle(R.string.dobrochan_prefs_max_rating); ratingPref.setSummary(preferences.getString(getSharedKey(PREF_KEY_MAX_RATING), "R-15")); ratingPref.setEntries(RATINGS); ratingPref.setEntryValues(RATINGS); ratingPref.setDefaultValue("R-15"); ratingPref.setKey(getSharedKey(PREF_KEY_MAX_RATING)); ratingPref.setOnPreferenceChangeListener(updateRatingListener); group.addPreference(ratingPref); }
From source file:de.k3b.android.toGoZip.SettingsActivity.java
private void setPref(String key, ListPreference listPreference, int arrayResourceId) { int index = listPreference.findIndexOfValue(key); String summary = ""; if (index >= 0) { String[] names = this.getResources().getStringArray(arrayResourceId); if (index < names.length) { summary = names[index];// ww w .jav a 2s . co m } } listPreference.setSummary(summary); }
From source file:com.cesarsk.say_it.ui.fragments.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Use an activity context to get the rewarded video instance. mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity()); mRewardedVideoAd.setRewardedVideoAdListener(this); loadRewardedVideoAd();//from ww w . ja v a 2 s . c om PackageInfo pInfo = null; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String version = pInfo.versionName; final Preference app_version = getPreferenceManager().findPreference("app_version"); app_version.setSummary("Version: " + version + " (Click for Privacy Policy)"); final Context context = getActivity(); if (context instanceof Callback) { mCallback = (Callback) context; } else { throw new IllegalStateException("Owner must implement URLCallback interface"); } // add listeners for non-default actions Preference preference = findPreference(KEY_1); preference.setOnPreferenceClickListener(this); Preference open_source_licenses = findPreference(KEY_2); open_source_licenses.setOnPreferenceClickListener(this); Preference rate_us = getPreferenceManager().findPreference("rate_us"); rate_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { rateUs(getActivity()); return false; } }); Preference contact_us = getPreferenceManager().findPreference("contact_us"); contact_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity()); return false; } }); Preference bug_report = getPreferenceManager().findPreference("bug_report"); bug_report.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity()); return false; } }); Preference donate_ad = getPreferenceManager().findPreference("donation_ad"); donate_ad.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { //Launch AD if (mRewardedVideoAd.isLoaded()) { mRewardedVideoAd.show(); } return false; } }); final Preference about_us = getPreferenceManager().findPreference("about_us"); about_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/07/18/about-us/"); return false; } }); final Preference eula = getPreferenceManager().findPreference("eula"); eula.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/04/28/say-it-eula-agreement/"); return false; } }); /*final Preference github = getPreferenceManager().findPreference("github"); github.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://github.com/Cesarsk/Say_it"); return false; } });*/ final Preference other_apps = getPreferenceManager().findPreference("other_apps"); other_apps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://play.google.com/store/apps/developer?id=Cesarsk+Dev+Team"); return false; } }); final Preference voice_settings = getPreferenceManager().findPreference("tts_settings"); voice_settings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(); intent.setAction("com.android.settings.TTS_SETTINGS"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return false; } }); // compute your public key and store it in base64EncodedPublicKey mHelper = new IabHelper(getActivity(), LCSecurity.base64EncodedPublicKey); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { // Oh no, there was a problem. if (MainActivity.isLoggingEnabled) Log.d("Say It!", "Problem setting up In-app Billing: " + result); } // Hooray, IAB is fully set up! if (MainActivity.isLoggingEnabled) Log.d("Say It!", "Hooray. IAB is fully set up!" + result); } }); mIabPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase info) { if (result.isFailure()) { Toast.makeText(getActivity(), "Purchase Failed! Perhaps have you already purchased the item?", Toast.LENGTH_SHORT).show(); } else if (info.getSku().equals(PlayActivity.no_ads_in_app)) { UtilitySharedPrefs.loadAdsStatus(getActivity()); UtilitySharedPrefs.savePrefs(getActivity(), true, MainActivity.NO_ADS_STATUS_KEY); } } }; mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, Inventory inventory) { if (result.isFailure()) { if (MainActivity.isLoggingEnabled) Toast.makeText(getActivity(), "Query Failed!", Toast.LENGTH_SHORT).show(); return; } //Open Purchase Dialog try { mHelper.flagEndAsync(); mHelper.launchPurchaseFlow(getActivity(), PlayActivity.no_ads_in_app, 64000, mIabPurchaseFinishedListener); } catch (IabHelper.IabAsyncInProgressException e) { e.printStackTrace(); } } }; final Preference remove_ads = getPreferenceManager().findPreference("remove_ads"); if (MainActivity.NO_ADS) { remove_ads.setEnabled(false); remove_ads.setSummary("Thank you for supporting us ?"); } else { remove_ads.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { //helper to remove ads List<String> additionalSkuList = new ArrayList<>(); additionalSkuList.add(PlayActivity.no_ads_in_app); try { mHelper.flagEndAsync(); mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener); } catch (IabHelper.IabAsyncInProgressException e) { e.printStackTrace(); } return false; } }); } final Preference reset_tutorial = getPreferenceManager().findPreference("reset_showcase"); reset_tutorial.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Random rand = new Random(); int randomNum = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min MainActivity.id_showcase_playactivity = "" + randomNum; Toast.makeText(getActivity(), "Tutorial has been reset", Toast.LENGTH_SHORT).show(); //MainActivity.id_showcase_fragments = "" + randomNum2; //int randomNum2 = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min //These two statements are commented because MaterialShowCase often crashes on fragments and while pressing the back button. return false; } }); //setting an own Alert Dialog's title color final Spannable title = new SpannableString("Delete Recordings"); title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, title.length(), 0); final Spannable message = new SpannableString("Are you sure you want to delete all recordings?"); message.setSpan(new ForegroundColorSpan(Color.GRAY), 0, message.length(), 0); final Preference delete_recordings = getPreferenceManager().findPreference("delete_recordings"); delete_recordings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Utility.delete_recordings(getActivity()); Toast.makeText(getActivity(), "Recordings deleted!", Toast.LENGTH_SHORT).show(); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //do nothing } }).show(); return true; } }); final ListPreference button_vibration = (ListPreference) getPreferenceManager() .findPreference("button_vibration"); button_vibration.setSummary(button_vibration.getEntry()); final Spannable default_vibration_settings_title = new SpannableString("Vibration Settings"); default_vibration_settings_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, default_vibration_settings_title.length(), 0); button_vibration.setDialogTitle(default_vibration_settings_title); button_vibration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_vibration = button_vibration.findIndexOfValue(new_value); CharSequence[] entries = button_vibration.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_VIBRATION_KEY); button_vibration .setSummary(button_vibration.getEntries()[button_vibration.findIndexOfValue(new_value)]); Toast.makeText(getActivity(), String.valueOf(entries[index_default_vibration]), Toast.LENGTH_SHORT) .show(); UtilitySharedPrefs.loadSettingsPrefs(context); return true; } }); final ListPreference default_accent = (ListPreference) getPreferenceManager() .findPreference("default_accent"); default_accent.setSummary(default_accent.getEntry()); final Spannable default_accent_title = new SpannableString("Default Accent"); default_accent_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, default_accent_title.length(), 0); default_accent.setDialogTitle(default_accent_title); default_accent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_accent = default_accent.findIndexOfValue(new_value); CharSequence[] entries = default_accent.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_ACCENT_KEY); default_accent.setSummary(default_accent.getEntries()[default_accent.findIndexOfValue(new_value)]); //Toast.makeText(getActivity(), String.valueOf(entries[index_default_accent]), Toast.LENGTH_SHORT).show(); UtilitySharedPrefs.loadSettingsPrefs(context); return true; } }); final ListPreference theme_selector = (ListPreference) getPreferenceManager() .findPreference("theme_selector"); final Spannable theme_selector_title = new SpannableString("Theme"); theme_selector_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, theme_selector_title.length(), 0); theme_selector.setDialogTitle(theme_selector_title); theme_selector.setSummary(theme_selector.getEntry()); theme_selector.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_theme = theme_selector.findIndexOfValue(new_value); CharSequence[] entries = theme_selector.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_THEME_KEY); theme_selector.setSummary(theme_selector.getEntries()[theme_selector.findIndexOfValue(new_value)]); //Toast.makeText(getActivity(), String.valueOf(entries[index_default_theme]), Toast.LENGTH_SHORT).show(); UtilitySharedPrefs.loadSettingsPrefs(context); Toast.makeText(getActivity(), "Done! Reboot to see changes.", Toast.LENGTH_SHORT).show(); return true; } }); Preference acknowledgements = getPreferenceManager().findPreference("acknowledgements"); acknowledgements.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final Intent preference_intent = new Intent(getActivity(), FileTextActivity.class); Bundle args = new Bundle(); args.putString(FileTextActivity.PREFERENCE, "acknowledgements"); preference_intent.putExtras(args); startActivity(preference_intent, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle()); return false; } }); app_version.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/04/18/privacy-policy/"); return false; } }); }
From source file:nz.Intelx.DroidNetLogin.DroidNetLoginActivity.java
@Override public void onPreferenceAttached(PreferenceScreen root, int xmlId) { if (root == null) return; //for whatever reason in very rare cases this is null updatePreference(root.getSharedPreferences()); //registering the listeners to the preference screen root.findPreference("login_preference").setOnPreferenceChangeListener(this); root.findPreference("debug_preference").setOnPreferenceChangeListener(this); root.findPreference("proxy_preference").setOnPreferenceChangeListener(this); root.findPreference("manual_login").setOnPreferenceClickListener(this); root.findPreference("manual_logout").setOnPreferenceClickListener(this); root.findPreference("manual_startProxy").setOnPreferenceClickListener(this); root.findPreference("manual_stopProxy").setOnPreferenceClickListener(this); //match summary for Login list preference to selected preference ListPreference login_preference = (ListPreference) root.findPreference("login_preference"); CharSequence Login_Summary = login_preference.getEntry(); login_preference.setSummary(Login_Summary); }
From source file:nz.Intelx.DroidNetLogin.DroidNetLoginActivity.java
@Override public boolean onPreferenceChange(Preference pref, Object newValue) { //match summary for Login list preference to selected preference if (pref.getKey().equals("login_preference")) { ListPreference login_preference = (ListPreference) pref; login_preference.setValue((String) newValue); CharSequence Login_Summary = login_preference.getEntry(); login_preference.setSummary(Login_Summary); }/*from ww w . jav a2s. co m*/ if (pref.getKey().equals("debug_preference")) { CheckBoxPreference debug_preference = (CheckBoxPreference) pref; debug_preference.setChecked((Boolean) newValue); } if (pref.getKey().equals("proxy_preference")) { CheckBoxPreference proxy_preference = (CheckBoxPreference) pref; proxy_preference.setChecked((Boolean) newValue); } updatePreference(pref.getSharedPreferences()); return true; }
From source file:com.hichinaschool.flashcards.anki.Preferences.java
private void updateListPreference(String key) { ListPreference listpref = (ListPreference) getPreferenceScreen().findPreference(key); String entry;/*from ww w . j a va 2 s. c o m*/ try { entry = listpref.getEntry().toString(); } catch (NullPointerException e) { Log.e(AnkiDroidApp.TAG, "Error getting set preference value of " + key + ": " + e); entry = "?"; } if (mListsToUpdate.containsKey(key)) { listpref.setSummary(replaceString(mListsToUpdate.get(key), entry)); } else { String oldsum = (String) listpref.getSummary(); if (oldsum.contains("XXX")) { mListsToUpdate.put(key, oldsum); listpref.setSummary(replaceString(oldsum, entry)); } else { listpref.setSummary(entry); } } }
From source file:com.android.leanlauncher.SettingsActivity.java
private void displayIconThemePref(ListPreference lpIconSetting) { ArrayMap<String, String> iconPacks = LauncherAppState.getInstance().getIconCache().getAvailableIconPacks(); if (iconPacks != null && iconPacks.size() != 0) { String iconPackValues[] = iconPacks.keySet().toArray(new String[iconPacks.size() + 1]); iconPackValues[iconPacks.size()] = ""; String[] iconPackTitles = new String[iconPacks.size() + 1]; for (int i = 0; i < iconPacks.size(); i++) { iconPackTitles[i] = iconPacks.get(iconPacks.keyAt(i)); }/*from w w w .j ava2 s .c o m*/ iconPackTitles[iconPacks.size()] = getString(R.string.pref_no_icon_theme); lpIconSetting.setEntries(iconPackTitles); lpIconSetting.setEntryValues(iconPackValues); } else { lpIconSetting.setEnabled(false); lpIconSetting.setShouldDisableView(true); lpIconSetting.setSummary(R.string.pref_icon_theme_summary_disabled); } }
From source file:com.ichi2.anki.PreferenceContext.java
public void updateNotificationPreference(ListPreference listpref) { CharSequence[] entries = listpref.getEntries(); CharSequence[] values = listpref.getEntryValues(); for (int i = 0; i < entries.length; i++) { int value = Integer.parseInt(values[i].toString()); if (entries[i].toString().contains("%d")) { entries[i] = String.format(entries[i].toString(), value); }//from w w w . j ava2 s . co m } listpref.setEntries(entries); listpref.setSummary(listpref.getEntry().toString()); }