Example usage for android.preference PreferenceManager getDefaultSharedPreferences

List of usage examples for android.preference PreferenceManager getDefaultSharedPreferences

Introduction

In this page you can find the example usage for android.preference PreferenceManager getDefaultSharedPreferences.

Prototype

public static SharedPreferences getDefaultSharedPreferences(Context context) 

Source Link

Document

Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context.

Usage

From source file:Main.java

public static void putString(final Context context, final String key, final String value) {
    if (context != null) {
        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = settings.edit();
        editor.putString(key, value).apply();
    }//from  w  w  w.  j a v a 2s.  com
}

From source file:Main.java

public static HashSet<String> getExcludedTags(Context context) {
    String tags = PreferenceManager.getDefaultSharedPreferences(context).getString("excludeTagsInheritance",
            null);/* w  w w  .  j av a  2 s .c  o  m*/

    if (tags == null)
        return null;

    HashSet<String> tagsSet = new HashSet<String>();
    for (String tag : tags.split(":")) {
        if (TextUtils.isEmpty(tag) == false)
            tagsSet.add(tag);
    }

    return tagsSet;
}

From source file:Main.java

public static void storeLongSharePref(Context context, String key, long value) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putLong(key, value);/*from ww w  .ja v a2  s  .com*/
    editor.apply();
}

From source file:Main.java

public static void setUserChapter(final Context context, final String chapter) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString(PREF_CHAPTER, chapter).commit();
}

From source file:Main.java

public static void setCancelNotificationTime(Context context) {
    if (null == context) {
        return;//from   w  w  w. ja va 2 s. c o  m
    }
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putLong("cancel_time", System.currentTimeMillis());
    editor.commit();
}

From source file:Main.java

public static boolean setLastLayerFileName(Context context, String fileName) {
    return PreferenceManager.getDefaultSharedPreferences(context).edit()
            .putString(LAYER_FILE_NAME_KEY, fileName).commit();
}

From source file:Main.java

public static void putSharedPreferencesLong(Context context, String key, long val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    Editor edit = preferences.edit();//from w  ww . j  a va 2 s .  c o m
    edit.putLong(key, val);
    edit.commit();
}

From source file:Main.java

public static void putSharedPreferencesInt(Context context, String key, int value) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    Editor edit = preferences.edit();/*ww  w. jav a2 s  .  c  o  m*/
    edit.putInt(key, value);
    edit.commit();
}

From source file:Main.java

public static void setSettingInt(final Context context, final String key, final int value) {
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = setting.edit();
    editor.putInt(key, value);//from ww w .  java 2  s.  c om
    editor.commit();
}

From source file:Main.java

public static void savePreferencesInt(String key, int value, Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Editor editor = sharedPreferences.edit();
    editor.putInt(key, value);/*from  w  w w.  ja  v a 2s.  c om*/
    editor.commit();
}