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

private static boolean neverDisplayDialog(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getBoolean("NEVER_SHOW_RATE_DIALOG", false);
}

From source file:Main.java

public final static boolean setHideMusicControls(Context context, boolean hideMusicControls) {
    return PreferenceManager.getDefaultSharedPreferences(context).edit()
            .putBoolean(prefsKeyHideMusicControls, hideMusicControls).commit();
}

From source file:Main.java

public static void remove(final Context context, final String key) {
    if (context != null) {
        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = settings.edit();
        editor.remove(key).commit();/*  w  w  w  .jav a2  s  . c o m*/
    }
}

From source file:Main.java

public static String readFromPreferences(Context context, String preferenceName, String defaultValue) {
    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(context.getApplicationContext());
    return sharedPreferences.getString(preferenceName, defaultValue);
}

From source file:Main.java

public static String getUserCourse(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getString(PREF_COURSE, null);
}

From source file:Main.java

public static void setUserId(Context context, String userId) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(USER_ID, userId);/*w  ww  . j  a  v a2  s .  c o m*/
    editor.commit();
}

From source file:Main.java

public static boolean isFirstRun(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getBoolean(PREF_FIRST_RUN, true);
}

From source file:Main.java

public static int getIntFromDefaults(Context context, String key) {
    if (context != null) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        return sharedPreferences.getInt(key, -1);
    } else/*from ww w. j  a v  a 2s .  c om*/
        return -1;
}

From source file:Main.java

public static String getUserChapter(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getString(PREF_CHAPTER, null);
}

From source file:Main.java

public static void removePreference(Context context, String preference) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.remove(preference);/*from ww w .  java  2  s.c o  m*/
    editor.apply();
}