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 resetDefaultViewer(Context context, String mimeType) {
    if (!TextUtils.isEmpty(mimeType)) {
        PreferenceManager.getDefaultSharedPreferences(context).edit().remove(DEFAULT_VIEWER_PREFIX + mimeType)
                .apply();//from  www .  j  a va 2  s .co m
    }
}

From source file:Main.java

public static void savePrefFloat(Context context, String key, float value) {
    if (pref == null) {
        pref = PreferenceManager.getDefaultSharedPreferences(context);
    }/* w  w  w.  j ava  2 s  .  co m*/
    if (editor == null) {
        editor = pref.edit();
    }
    editor.putFloat(key, value);
    editor.commit();

}

From source file:Main.java

public static void savePrefInt(Context context, String key, int value) {
    if (pref == null) {
        pref = PreferenceManager.getDefaultSharedPreferences(context);
        // pref = context
        // .getSharedPreferences(PREFS, Context.MODE_PRIVATE);
    }/*from   ww w . j  ava 2 s  .co  m*/
    if (editor == null) {
        editor = pref.edit();
    }
    editor.putInt(key, value);
    editor.commit();

}

From source file:Main.java

private static void persist(Context context, String language) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = preferences.edit();

    editor.putString(SELECTED_LANGUAGE, language);
    editor.apply();/*from w  w w  .  ja  va 2  s .c o m*/
}

From source file:Main.java

public static void savePrefBoolean(Context context, String key, boolean value) {
    if (pref == null) {
        pref = PreferenceManager.getDefaultSharedPreferences(context);
    }/*from www  .j av a 2s .c  om*/
    if (editor == null) {
        editor = pref.edit();
    }
    editor.putBoolean(key, value);
    editor.commit();
}

From source file:Main.java

public static void saveDefaultRingtone(Context context, int type, String id) {
    SharedPreferences mSharePref = PreferenceManager.getDefaultSharedPreferences(context);
    Editor mEditor = mSharePref.edit();//w w  w . j ava 2 s  . c  o  m
    mEditor.putString(TYPE_SYSTEM_PRIMER + type, id);
    mEditor.commit();
}

From source file:Main.java

public static void setLatestQuestionSaved(Context context, String questionUrl) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Editor edit = prefs.edit();//w  ww  .  j  ava  2s .com
    edit.putString(PREF_LATEST_QUESTION, questionUrl);
    edit.commit();
}

From source file:Main.java

public static boolean getConfig(Context context, String key, boolean defaultValue) {
    return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, defaultValue);
}

From source file:Main.java

public static boolean hasDefaultViewer(Context context, String mimeType) {
    if (!TextUtils.isEmpty(mimeType)) {
        return PreferenceManager.getDefaultSharedPreferences(context)
                .contains(DEFAULT_VIEWER_PREFIX + mimeType);
    }//from  w  w  w .  j  a va 2 s.  co  m
    return false;
}

From source file:Main.java

public static void setLatestForumPostSaved(Context context, String forumPostUrl) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Editor edit = prefs.edit();//from w ww  . j  ava  2 s.  com
    edit.putString(PREF_LATEST_FORUM_POST, forumPostUrl);
    edit.commit();
}