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 setSharedPreferences(Context context, String key, String value) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(HORSEPUSH + key, value);
    editor.commit();//w w  w .  j av a2s  .  c om
}

From source file:Main.java

protected static SharedPreferences createPrefs(Context context, String name, int mode) {
    if (TextUtils.isEmpty(name)) {
        return PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
    } else {/*from   w  w  w  . j  a v  a2s .  c o m*/
        return context.getSharedPreferences(name, mode);
    }
}

From source file:Main.java

public static void setSettingString(final Context context, final String key, final String value) {
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = setting.edit();
    editor.putString(key, value);//from  w ww .jav  a2  s . c  om
    editor.commit();
}

From source file:Main.java

public static long loadPrefLong(Context context, String key, long defaultValue) {
    if (pref == null) {
        pref = PreferenceManager.getDefaultSharedPreferences(context);
    }/*from w  ww.j  a  v  a2 s.  co  m*/
    return pref.getLong(key, defaultValue);
}

From source file:Main.java

public static int loadPrefInt(Context context, String key, int defaultValue) {
    if (pref == null) {
        pref = PreferenceManager.getDefaultSharedPreferences(context);
        // pref = context
        // .getSharedPreferences(PREFS, Context.MODE_PRIVATE);
    }/*from   w  w w. j a va  2 s  .co  m*/
    return pref.getInt(key, defaultValue);
}

From source file:Main.java

public static void setDeclaretion(Context context, String key, String value) {
    if (null == context) {
        return;/*from w  w w .j av  a2  s .  co m*/
    }
    SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = spf.edit();
    editor.putString(key, value);
    editor.commit();
}

From source file:Main.java

public static int getSettingInt(final Context context, final String key, final int defaultValue) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    return settings.getInt(key, defaultValue);
}

From source file:Main.java

public static float loadPrefFloat(Context context, String key, float defaultValue) {
    if (pref == null) {
        pref = PreferenceManager.getDefaultSharedPreferences(context);
    }/*from w  w w  .  ja  v a2 s.  com*/
    return pref.getFloat(key, defaultValue);
}

From source file:Main.java

public static void setUserPhoneNumber(final Context context, final String phone) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString(PREF_PHONE_NUMBER, phone).commit();
}

From source file:Main.java

public static String getLatestForumPostSaved(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String forumPostUrl = prefs.getString(PREF_LATEST_FORUM_POST, null);
    return forumPostUrl;
}