Java Code Examples for android.preference.PreferenceScreen#getSharedPreferences()
The following examples show how to use
android.preference.PreferenceScreen#getSharedPreferences() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrefsLoaderFragment.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
@Override public void setStringFieldSummary(String fieldName) { PreferenceScreen pfs = getPreferenceScreen(); SharedPreferences sp = pfs.getSharedPreferences(); Preference pref = pfs.findPreference(fieldName); String val = sp.getString(fieldName, null); if (TextUtils.isEmpty(val)) { val = getDefaultFieldSummary(fieldName); } setPreferenceSummary(pref, val); }
Example 2
Source File: GenericPrefs.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
/** * Set summary of a standard string field If empty will display the default * summary Else it displays the preference value * * @param fieldName the preference key name */ public void setStringFieldSummary(String fieldName) { PreferenceScreen pfs = getPreferenceScreen(); SharedPreferences sp = pfs.getSharedPreferences(); Preference pref = pfs.findPreference(fieldName); String val = sp.getString(fieldName, null); if (TextUtils.isEmpty(val)) { val = getDefaultFieldSummary(fieldName); } setPreferenceSummary(pref, val); }
Example 3
Source File: GenericPrefs.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
/** * Set summary of a password field If empty will display default summary If * password will display a * char for each letter of password * * @param fieldName the preference key name */ public void setPasswordFieldSummary(String fieldName) { PreferenceScreen pfs = getPreferenceScreen(); SharedPreferences sp = pfs.getSharedPreferences(); Preference pref = pfs.findPreference(fieldName); String val = sp.getString(fieldName, null); if (TextUtils.isEmpty(val)) { val = getDefaultFieldSummary(fieldName); } else { val = val.replaceAll(".", "*"); } setPreferenceSummary(pref, val); }
Example 4
Source File: SharedPreferencesUtils.java From GravityBox with Apache License 2.0 | 4 votes |
public static SharedPreferences getSharedPreferences(PreferenceManager preferenceManager, PreferenceScreen preferenceScreen) { preferenceManager.setSharedPreferencesMode(Context.MODE_WORLD_READABLE); return preferenceScreen.getSharedPreferences(); }
Example 5
Source File: PreferencesActivity.java From ministocks with MIT License | 4 votes |
@Override protected void onResume() { super.onResume(); showRecentChanges(); PreferenceScreen screen = getPreferenceScreen(); SharedPreferences sharedPreferences = screen.getSharedPreferences(); // Hide preferences for certain widget sizes int widgetSize = sharedPreferences.getInt("widgetSize", 0); // Remove extra stocks if (widgetSize == 0 || widgetSize == 1) { PreferenceScreen stock_setup = (PreferenceScreen) findPreference("stock_setup"); for (int i = 5; i < 11; i++) removePref(stock_setup, "Stock" + i); } // Remove extra widget views if (widgetSize == 1 || widgetSize == 3) { PreferenceScreen widget_views = (PreferenceScreen) findPreference("widget_views"); removePref(widget_views, "show_percent_change"); removePref(widget_views, "show_portfolio_change"); removePref(widget_views, "show_profit_daily_change"); removePref(widget_views, "show_profit_change"); } // Hide Feedback option if not relevant String install_date = getAppPreferences().getString("install_date", null); if (DateTools.elapsedDays(install_date) < 30) removePref("about_menu", "rate_app"); // Initialise the summaries when the preferences screen loads Map<String, ?> map = sharedPreferences.getAll(); for (String key : map.keySet()) updateSummaries(sharedPreferences, key); // Update version number findPreference("version").setSummary("BUILD " + VersionTools.BUILD); // Force update of global preferences // TODO Ensure the items below are included in the above list // rather than updating these items twice (potentially) updateSummaries(sharedPreferences, "update_interval"); updateSummaries(sharedPreferences, "update_start"); updateSummaries(sharedPreferences, "update_end"); updateSummaries(sharedPreferences, "update_weekend"); // Set up a listener whenever a key changes sharedPreferences.registerOnSharedPreferenceChangeListener(this); }