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 String getLastUsedTrackID(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getString("last_track_id", null);
}

From source file:Main.java

public static void setLastUsedTrackID(Context context, String trackID) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString("last_track_id", trackID).commit();
}

From source file:Main.java

public static Integer getPreferences(Context context, String key, int defValue) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Integer savedPref = sharedPreferences.getInt(key, defValue);
    return savedPref;
}

From source file:Main.java

public static boolean isNotificationFiredForBlock(Context context, String blockId) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    final String key = String.format("notification_fired_%s", blockId);
    boolean fired = sp.getBoolean(key, false);
    sp.edit().putBoolean(key, true).apply();
    return fired;
}

From source file:Main.java

public static boolean isNotificationFiredForBlock(Context context, String blockId) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    final String key = String.format("notification_fired_%s", blockId);
    boolean fired = sp.getBoolean(key, false);
    sp.edit().putBoolean(key, true).commit();
    return fired;
}

From source file:Main.java

public static void unmarkFeedbackNotificationFiredForSession(Context context, String sessionId) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    final String key = String.format("feedback_notification_fired_%s", sessionId);
    sp.edit().putBoolean(key, false).commit();
}

From source file:Main.java

public static boolean isFeedbackNotificationFiredForSession(Context context, String sessionId) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    final String key = String.format("feedback_notification_fired_%s", sessionId);
    boolean fired = sp.getBoolean(key, false);
    sp.edit().putBoolean(key, true).commit();
    return fired;
}

From source file:Main.java

public static boolean getPrefBool(Context context, int keyId, int defaultValueId) {

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String key = context.getString(keyId);
    boolean defaultValue = false;
    try {//from   w ww  . j  ava2  s .c  om
        defaultValue = Boolean.parseBoolean(context.getString(defaultValueId));
    } catch (Exception e) { /* don't care */
    }

    return sharedPreferences.getBoolean(key, defaultValue);
}

From source file:Main.java

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

From source file:Main.java

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