Example usage for android.content Context getSharedPreferences

List of usage examples for android.content Context getSharedPreferences

Introduction

In this page you can find the example usage for android.content Context getSharedPreferences.

Prototype

public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);

Source Link

Document

Retrieve and hold the contents of the preferences file, returning a SharedPreferences through which you can retrieve and modify its values.

Usage

From source file:Main.java

/**
 * Add protein to today's Protein Counter.
 *//*from ww w.j  a va 2s  . c o  m*/
public static float addToProtToday(Context c, float toAdd) {
    sharedpreferences = c.getSharedPreferences(SHARED_PREF_FILE_NAME, 0);
    float result = toAdd + getProtToday(c);
    sPEditor = sharedpreferences.edit();
    sPEditor.putFloat(PROT_TODAY_PREF_NAME, result);
    sPEditor.commit();
    return result;
}

From source file:Main.java

public static SharedPreferences.Editor writeSharedPref(Context context, String sharedPref) {
    SharedPreferences settings = context.getSharedPreferences(sharedPref, 0);
    return settings.edit();
}

From source file:Main.java

/**
 * Get the MVD id. Default is "mvd".//from  ww w. java 2  s  .co m
 *
 * @param context The application context
 * @return The id
 */
public static String getMvdId(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
    return prefs.getString("id", "mvd");
}

From source file:Main.java

public static void setBooleanToCache(Context context, String key, boolean isGuide) {
    SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    sp.edit().putBoolean(key, isGuide).commit();
}

From source file:Main.java

public static boolean hasAsymmericMasterSecret(Context context) {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, 0);

    return settings.contains(ASYMMETRIC_LOCAL_PUBLIC_NIST) || settings.contains(ASYMMETRIC_LOCAL_PUBLIC_DJB);
}

From source file:Main.java

public static void setString(Context ctx, String key, String value) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    sp.edit().putString(key, value).apply();
}

From source file:Main.java

public static void storeFloat(Context context, String key, float value) {
    SharedPreferences pre = context.getSharedPreferences(STORE_NAME, Context.MODE_PRIVATE);
    pre.edit().putFloat(STORE_KEY_PREFIX + key, value).commit();
}

From source file:Main.java

public static void storeInteger(Context context, String key, int value) {
    SharedPreferences pre = context.getSharedPreferences(STORE_NAME, Context.MODE_APPEND);
    pre.edit().putInt(STORE_KEY_PREFIX + key, value).commit();

}

From source file:Main.java

public static void putString(Context context, String key, String value) {
    SharedPreferences sp = context.getSharedPreferences("atguigu", Context.MODE_PRIVATE);
    sp.edit().putString(key, value).commit();
}