List of usage examples for android.preference PreferenceManager getDefaultSharedPreferences
public static SharedPreferences getDefaultSharedPreferences(Context context)
From source file:Main.java
/** * Saves a float value under the provided key in the preference manager. If <code>value</code> * is <code>Float.MIN_VALUE</code>, then the provided key will be removed from the preferences. */// w w w . ja v a 2 s. c om public static void saveFloatToPreference(Context context, String key, float value) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); if (Float.MIN_VALUE == value) { // we want to remove pref.edit().remove(key).apply(); } else { pref.edit().putFloat(key, value).apply(); } }
From source file:Main.java
public static void setDefaultViewer(Context context, String mimeType, String activityPackage, String activityName) {//from w ww. jav a 2 s. co m if (TextUtils.isEmpty(mimeType)) { throw new IllegalArgumentException("Default viewer type can't be empty"); } PreferenceManager.getDefaultSharedPreferences(context).edit() .putString(DEFAULT_VIEWER_PREFIX + mimeType, activityPackage + "\t" + activityName).apply(); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void setAccountName(Context ctx, String accountName) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(ctx).edit(); editor.putString(KEY_ACCOUNT_NAME, accountName); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { editor.apply();// w w w .ja v a2 s. co m } else { editor.commit(); } mCurrentUser = accountName; }
From source file:Main.java
public static String getSelectedAccount(Context context) { if (context == null) return ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getString(PREF_SELECTED_ACCOUNT, ""); }
From source file:Main.java
public static int getPreference(Context context, String key, int defaultValue) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); return settings.getInt(key, defaultValue); }
From source file:Main.java
/** * Initialize the SharedPreferences instance for the app. * This method must be called before using any other methods of this class. *//*from w ww. j a va 2s .c o m*/ public static void init(Context mcontext) { if (sharedPreferences == null) { sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mcontext); editor = sharedPreferences.edit(); } }
From source file:Main.java
private static void saveWeatherInfo(Context context, String city, String cityid, String temp1, String temp2, String weather, String ptime) { SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d", Locale.CHINA); SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(context).edit(); edit.putBoolean("city_selected", true); edit.putString("city", city); edit.putString("cityid", cityid); edit.putString("temp1", temp1); edit.putString("temp2", temp2); edit.putString("weather", weather); edit.putString("ptime", ptime); edit.putString("ctime", format.format(new Date())); edit.commit();//from w w w. ja va2s . c om }
From source file:Main.java
public static String loadPrefString(Context context, String key, String defaultValue) { if (pref == null) { // pref = context // .getSharedPreferences(PREFS, Context.MODE_PRIVATE); pref = PreferenceManager.getDefaultSharedPreferences(context); }/*from w w w. j a va 2s. c om*/ return pref.getString(key, defaultValue); }
From source file:Main.java
private static String getPersistedData(Context context, String defaultLanguage) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); return preferences.getString(SELECTED_LANGUAGE, defaultLanguage); }
From source file:Main.java
/** * @Title: saveSettingRingtone//w w w . j a va2 s . c om * @Description: Save current setting ring tone * @param context * @param type * @param id * @return void * @throws */ public static void saveSettingRingtone(Context context, int type, String id) { SharedPreferences mSharePref = PreferenceManager.getDefaultSharedPreferences(context); Editor mEditor = mSharePref.edit(); mEditor.putString(TYPE_PRE + type, id); mEditor.commit(); }