Java Code Examples for android.preference.PreferenceManager#setSharedPreferencesMode()
The following examples show how to use
android.preference.PreferenceManager#setSharedPreferencesMode() .
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: AbstractSettingsActivity.java From mytracks with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM); ApiAdapterFactory.getApiAdapter().configureActionBarHomeAsUp(this); PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager.setSharedPreferencesName(Constants.SETTINGS_NAME); preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE); // Set up automatic preferences backup backupPreferencesListener = new BackupPreferencesListener(this); preferenceManager.getSharedPreferences() .registerOnSharedPreferenceChangeListener(backupPreferencesListener); }
Example 2
Source File: SettingsFragment.java From android with MIT License | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final PreferenceManager pm = this.getPreferenceManager(); pm.setSharedPreferencesName(Const.APP_PREFS_NAME); pm.setSharedPreferencesMode(Context.MODE_PRIVATE); addPreferencesFromResource(R.xml.prefs_settings); mPrefs = pm.getSharedPreferences(); pToggleLogin = findPreference(TOGGLE_LOGIN); pCity = findPreference(CITY); pCarshareMode = (SwitchPreference) findPreference(CARSHARE_MODE); // Listeners pToggleLogin.setOnPreferenceClickListener(this); }
Example 3
Source File: AboutFragment.java From android with MIT License | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final PreferenceManager pm = this.getPreferenceManager(); pm.setSharedPreferencesName(Const.APP_PREFS_NAME); pm.setSharedPreferencesMode(Context.MODE_PRIVATE); addPreferencesFromResource(R.xml.prefs_about); findPreference(ONBOARDING).setOnPreferenceClickListener(this); findPreference(TERMS).setOnPreferenceClickListener(this); findPreference(FAQ).setOnPreferenceClickListener(this); findPreference(PRIVACY).setOnPreferenceClickListener(this); findPreference(RATE_APP).setOnPreferenceClickListener(this); }
Example 4
Source File: SettingsActivity.java From moVirt with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); account = getArguments().getParcelable(ACCOUNT_NAME_KEY); ObjectUtils.requireNotNull(account, "account"); PreferenceManager prefMgr = getPreferenceManager(); prefMgr.setSharedPreferencesName(account.getId() + Constants.PREFERENCES_NAME_SUFFIX); prefMgr.setSharedPreferencesMode(MODE_PRIVATE); toggleVisibility(); addPreferencesFromResource(R.xml.preferences); disposables.add(rxStore.onRemovedAccountObservable(account) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(account -> getActivity().finish())); try { sharedPreferencesHelper = environmentStore.getSharedPreferencesHelper(account); eventProviderHelper = environmentStore.getEventProviderHelper(account); } catch (AccountDeletedException e) { getActivity().finish(); } }
Example 5
Source File: SharedPreferencesUtils.java From GravityBox with Apache License 2.0 | 5 votes |
public static SharedPreferences getSharedPreferences(PreferenceManager preferenceManager, String prefName) { if (!TextUtils.isEmpty(prefName)) { preferenceManager.setSharedPreferencesName(prefName); } preferenceManager.setSharedPreferencesMode(Context.MODE_WORLD_READABLE); return preferenceManager.getSharedPreferences(); }
Example 6
Source File: SettingsActivity.java From xposed-whatsapp with MIT License | 5 votes |
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); PreferenceManager prefMgr = getPreferenceManager(); prefMgr.setSharedPreferencesMode(MODE_WORLD_READABLE); addPreferencesFromResource(R.xml.pref_whatsapp); }
Example 7
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 8
Source File: SettingsActivity.java From PlayMusicExporter with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create the settings mSettings = new PlayMusicExporterSettings(this); // Setup the default shared preference PreferenceManager prefMgr = getPreferenceManager(); prefMgr.setSharedPreferencesName(PlayMusicExporterSettings.DEFAULT_SETTINGS_FILENAME); prefMgr.setSharedPreferencesMode(MODE_PRIVATE); // Loads the preference xml addPreferencesFromResource(R.xml.preferences); // The export path preference mPrefExportPath = findPreference("preference_export_path"); mPrefExportPath.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { // Current path Uri currentPath = mSettings.getUri(PlayMusicExporterSettings.PREF_EXPORT_URI, Uri.EMPTY); // Starts the directory browser activity Intent intent = DirectoryBrowserActivity.openDirectoryBrowser(getApplicationContext(), currentPath, getString(R.string.settings_export_path)); startActivityForResult(intent, REQUEST_EXPORT_PATH); // We wait for the activity result return true; } }); // Build date Preference prefBuildDate = findPreference("preference_build_date"); // Hack to get the build date try { ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(getPackageName(), 0); ZipFile zipFile = new ZipFile(applicationInfo.sourceDir); ZipEntry dexFile = zipFile.getEntry("classes.dex"); long time = dexFile.getTime(); prefBuildDate.setSummary(DateFormat.format("yyyy-MM-dd HH:mm:ss", new Date(time)).toString()); } catch (Exception e) { // Failed } updatePrefExportPath(); }
Example 9
Source File: NotifySettingsActivity.java From AndroidPNClient with Apache License 2.0 | 4 votes |
private PreferenceScreen createPreferenceHierarchy() { Log.d(LOGTAG, "createSettingsPreferenceScreen()..."); PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME); preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE); PreferenceScreen root = preferenceManager.createPreferenceScreen(this); // PreferenceCategory prefCat = new PreferenceCategory(this); // // inlinePrefCat.setTitle(""); // root.addPreference(prefCat); CheckBoxPreference notifyPref = new CheckBoxPreference(this); notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED); notifyPref.setTitle(R.string.notifications_enabled); notifyPref.setSummaryOn(R.string.receive_push_messages); notifyPref.setSummaryOff(R.string.do_not_receive_push_messages); notifyPref.setDefaultValue(Boolean.TRUE); notifyPref .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { boolean checked = Boolean.valueOf(newValue.toString()); if (checked) { preference.setTitle(R.string.notifications_enabled); } else { preference.setTitle(R.string.notifications_disabled); } return true; } }); CheckBoxPreference soundPref = new CheckBoxPreference(this); soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED); soundPref.setTitle(R.string.sound); soundPref.setSummary(R.string.play_sound_for_notifications); soundPref.setDefaultValue(Boolean.TRUE); // soundPref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED); CheckBoxPreference vibratePref = new CheckBoxPreference(this); vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED); vibratePref.setTitle(R.string.vibrate); vibratePref.setSummary(R.string.vibrate_the_phone_for_notifications); vibratePref.setDefaultValue(Boolean.TRUE); // vibratePref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED); root.addPreference(notifyPref); root.addPreference(soundPref); root.addPreference(vibratePref); // prefCat.addPreference(notifyPref); // prefCat.addPreference(soundPref); // prefCat.addPreference(vibratePref); // root.addPreference(prefCat); return root; }
Example 10
Source File: NotificationSettingsActivity.java From AndroidPNClient with Apache License 2.0 | 4 votes |
private PreferenceScreen createPreferenceHierarchy() { Log.d(LOGTAG, "createSettingsPreferenceScreen()..."); PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME); preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE); PreferenceScreen root = preferenceManager.createPreferenceScreen(this); CheckBoxPreference notifyPref = new CheckBoxPreference(this); notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED); notifyPref.setTitle("Notifications Enabled"); notifyPref.setSummaryOn("Receive push messages"); notifyPref.setSummaryOff("Do not receive push messages"); notifyPref.setDefaultValue(Boolean.TRUE); notifyPref .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { boolean checked = Boolean.valueOf(newValue.toString()); if (checked) { preference.setTitle("Notifications Enabled"); } else { preference.setTitle("Notifications Disabled"); } return true; } }); CheckBoxPreference soundPref = new CheckBoxPreference(this); soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED); soundPref.setTitle("Sound"); soundPref.setSummary("Play a sound for notifications"); soundPref.setDefaultValue(Boolean.TRUE); CheckBoxPreference vibratePref = new CheckBoxPreference(this); vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED); vibratePref.setTitle("Vibrate"); vibratePref.setSummary("Vibrate the phone for notifications"); vibratePref.setDefaultValue(Boolean.TRUE); root.addPreference(notifyPref); root.addPreference(soundPref); root.addPreference(vibratePref); return root; }
Example 11
Source File: NotificationSettingsActivity.java From android-demo-xmpp-androidpn with Apache License 2.0 | 4 votes |
private PreferenceScreen createPreferenceHierarchy() { Log.d(LOGTAG, "createSettingsPreferenceScreen()..."); PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME); preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE); PreferenceScreen root = preferenceManager.createPreferenceScreen(this); // PreferenceCategory prefCat = new PreferenceCategory(this); // // inlinePrefCat.setTitle(""); // root.addPreference(prefCat); CheckBoxPreference notifyPref = new CheckBoxPreference(this); notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED); notifyPref.setTitle("Notifications Enabled"); notifyPref.setSummaryOn("Receive push messages"); notifyPref.setSummaryOff("Do not receive push messages"); notifyPref.setDefaultValue(Boolean.TRUE); notifyPref .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { boolean checked = Boolean.valueOf(newValue.toString()); if (checked) { preference.setTitle("Notifications Enabled"); } else { preference.setTitle("Notifications Disabled"); } return true; } }); CheckBoxPreference soundPref = new CheckBoxPreference(this); soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED); soundPref.setTitle("Sound"); soundPref.setSummary("Play a sound for notifications"); soundPref.setDefaultValue(Boolean.TRUE); // soundPref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED); CheckBoxPreference vibratePref = new CheckBoxPreference(this); vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED); vibratePref.setTitle("Vibrate"); vibratePref.setSummary("Vibrate the phone for notifications"); vibratePref.setDefaultValue(Boolean.TRUE); // vibratePref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED); root.addPreference(notifyPref); root.addPreference(soundPref); root.addPreference(vibratePref); // prefCat.addPreference(notifyPref); // prefCat.addPreference(soundPref); // prefCat.addPreference(vibratePref); // root.addPreference(prefCat); return root; }
Example 12
Source File: AlpSettings.java From android-lockpattern with Apache License 2.0 | 3 votes |
/** * Setup {@code pm} to use global unique filename and global access mode. * You must use this method if you let the user change preferences via UI * (such as {@link PreferenceActivity}, {@link PreferenceFragment}...). * * @param context * the context. * @param pm * {@link PreferenceManager}. * @since v2.6 beta */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static void setupPreferenceManager(Context context, PreferenceManager pm) { pm.setSharedPreferencesMode(Context.MODE_MULTI_PROCESS); pm.setSharedPreferencesName(genPreferenceFilename()); }
Example 13
Source File: Settings.java From android-lockpattern with Apache License 2.0 | 3 votes |
/** * Setup {@code pm} to use global unique filename and global access mode. * You must use this method if you let the user change preferences via UI * (such as {@link PreferenceActivity}, {@link PreferenceFragment}...). * * @param context * the context. * @param pm * {@link PreferenceManager}. * @since v2.6 beta */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static void setupPreferenceManager(Context context, PreferenceManager pm) { pm.setSharedPreferencesMode(Context.MODE_MULTI_PROCESS); pm.setSharedPreferencesName(genPreferenceFilename()); }
Example 14
Source File: Prefs.java From Pi-Locker with GNU General Public License v2.0 | 3 votes |
/** * Setup {@code pm} to use global unique filename and global access mode. * You must use this method if you let the user change preferences via UI * (such as {@link PreferenceActivity}, {@link PreferenceFragment}...). * * @param context the context. * @param pm {@link PreferenceManager}. * @since v2.6 beta */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static void setupPreferenceManager(Context context, PreferenceManager pm) { pm.setSharedPreferencesMode(Context.MODE_MULTI_PROCESS); pm.setSharedPreferencesName(genPreferenceFilename(context)); }