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 Map<String, ?> getAll(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    Map<String, ?> prefsMap = preferences.getAll();
    return prefsMap;
}

From source file:Main.java

public static void putInt(final Context context, final String key, final int value) {
    if (context != null) {
        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = settings.edit();
        editor.putInt(key, value).apply();
    }/*from w  ww.  ja v a 2  s  .co m*/
}

From source file:Main.java

public static void setUserDOB(final Context context, final String dob) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString(PREF_DOB, dob).commit();
}

From source file:Main.java

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

From source file:Main.java

public static String getDefaults(String key, Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getString(key, "false");
}

From source file:Main.java

protected static void initialize(Context context) {
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
}

From source file:Main.java

public static String getPreference(Context context, String key, String defaultValue) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    return settings.getString(key, defaultValue);
}

From source file:Main.java

public static long getCanelNotificationTime(Context context) {
    long time = 0;
    if (context != null) {
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        time = settings.getLong("cancel_time", System.currentTimeMillis());
    }//from   w w w.j  a  v a2 s  .com
    return time;
}

From source file:Main.java

public static void setPrefFontSize(final Context context, float size) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putFloat(PREF_FONT_SIZE, size).commit();
}

From source file:Main.java

public static void putLong(final Context context, final String key, final long value) {
    if (context != null) {
        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = settings.edit();
        editor.putLong(key, value).apply();
    }//from   w w w .  java2 s  .  co m
}