Java Code Examples for android.preference.PreferenceManager#setSharedPreferencesName()

The following examples show how to use android.preference.PreferenceManager#setSharedPreferencesName() . 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: SettingsActivity.java    From moVirt with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: AboutFragment.java    From android with MIT License 6 votes vote down vote up
@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 3
Source File: AbstractSettingsActivity.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: SettingsFragment.java    From android with MIT License 6 votes vote down vote up
@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 5
Source File: SharedPreferencesUtils.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
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: TagSettingActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PreferenceManager prefMgr = getPreferenceManager();
    prefMgr.setSharedPreferencesName(TagSetting.FILE_NAME);

    addPreferencesFromResource(R.xml.activity_setting_pref_oauth);

    SwitchPreference serverPreferences = (SwitchPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_ouath_on_off));
    serverPreferences.setOnPreferenceChangeListener(this);
}
 
Example 7
Source File: MainSettingsActivity.java    From glitchify with MIT License 5 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceManager pref = getPreferenceManager();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        pref.setStorageDeviceProtected();
    }
    pref.setSharedPreferencesName("preferences");
    addPreferencesFromResource(R.xml.preferences);
}
 
Example 8
Source File: WeChatDecoratorSettingsActivity.java    From decorator-wechat with Apache License 2.0 5 votes vote down vote up
@Override protected void onCreate(@Nullable final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	final PreferenceManager manager = getPreferenceManager();
	manager.setSharedPreferencesName(WeChatDecorator.PREFERENCES_NAME);
	if (SDK_INT >= N) manager.setStorageDeviceProtected();
	getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(mPreferencesChangeListener);
	addPreferencesFromResource(R.xml.decorators_wechat_settings);
}
 
Example 9
Source File: SettingsActivity.java    From PlayMusicExporter with MIT License 4 votes vote down vote up
@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 10
Source File: NotifySettingsActivity.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
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 11
Source File: NotificationSettingsActivity.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
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 12
Source File: NotificationSettingsActivity.java    From android-demo-xmpp-androidpn with Apache License 2.0 4 votes vote down vote up
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 13
Source File: SettingsActivityTest.java    From JayPS-AndroidApp with MIT License 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());

    TestApplication app = new TestApplication();
    app.setObjectGraph(ObjectGraph.create(TestModule.class));
    app.inject(this);
    setApplication(app);

    setupMocks();

    //setActivityInitialTouchMode(false);
    _targetContext = getInstrumentation().getTargetContext();
    Intent intent = new Intent(_targetContext, SettingsActivity.class);
    startActivity(intent, null, null);

    _activity = getActivity();
    assertNotNull(_activity);

    // change pref name to avoid to reset preferences on a real device
    PreferenceManager prefMgr = _activity.getPreferenceManager();
    prefMgr.setSharedPreferencesName("only_for_test");

    _installPreference = _activity.findPreference("INSTALL_WATCHFACE");
    assertNotNull(_installPreference);

    _unitsOfMeasure = _activity.findPreference("UNITS_OF_MEASURE");
    assertNotNull(_unitsOfMeasure);

    _refreshPref = _activity.findPreference("REFRESH_INTERVAL");
    assertNotNull(_refreshPref);

    _loginPref = _activity.findPreference("LIVE_TRACKING_LOGIN");
    assertNotNull(_loginPref);

    _loginMntPref = _activity.findPreference("LIVE_TRACKING_MMT_LOGIN");
    assertNotNull(_loginMntPref);

    _oruxMaps = (ListPreference) _activity.findPreference("ORUXMAPS_AUTO");
    assertNotNull(_oruxMaps);

    _canvas = (ListPreference) _activity.findPreference("CANVAS_MODE");
    assertNotNull(_canvas);
}
 
Example 14
Source File: AlpSettings.java    From android-lockpattern with Apache License 2.0 3 votes vote down vote up
/**
 * 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 15
Source File: Settings.java    From android-lockpattern with Apache License 2.0 3 votes vote down vote up
/**
 * 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 16
Source File: Prefs.java    From Pi-Locker with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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));
}
 
Example 17
Source File: Settings.java    From divide with Apache License 2.0 3 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PreferenceManager manager = getPreferenceManager();
    manager.setSharedPreferencesName(PREFERENCE_NAME);

    addPreferencesFromResource(R.xml.prefs);

}