List of usage examples for android.preference PreferenceManager getDefaultSharedPreferences
public static SharedPreferences getDefaultSharedPreferences(Context context)
From source file:Main.java
/** * <pre>//from w w w .j av a 2s . co m * Get default {@link SharedPreferences} of the app. * </pre> */ public static SharedPreferences getPrefs() { if (sPrefs == null) { sPrefs = PreferenceManager.getDefaultSharedPreferences(getCurrentContext()); } return sPrefs; }
From source file:Main.java
public static List<String> getPackage(Context context) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); Gson gson = new Gson(); String json = sharedPrefs.getString(APP_LIST, null); Type type = new TypeToken<ArrayList<String>>() { }.getType();//from w w w . j av a2s . co m return gson.fromJson(json, type); }
From source file:Main.java
public static int getTrainingWordsSetting(Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); String count = preferences.getString(TRAINING_WORDS_COUNT, Integer.toString(TRAINING_VIEW_PAGER_COUNT)); try {/*from w ww. j ava 2 s . c om*/ return Integer.parseInt(count); } catch (NumberFormatException ex) { return TRAINING_VIEW_PAGER_COUNT; } }
From source file:Main.java
public static boolean shouldShowTutorial(Context context, String tutorialName, int limit) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int shown = prefs.getInt("tutorial" + tutorialName, 0); prefs.edit().putInt("tutorial" + tutorialName, shown + 1).apply(); return limit == shown; }
From source file:Main.java
public static SharedPreferences getPreference(Context context) { if (mPreference == null) mPreference = PreferenceManager.getDefaultSharedPreferences(context); return mPreference; }
From source file:Main.java
public static void updateLastSync(Context context) { long lastSync = getLastSync(context); long now = System.currentTimeMillis(); if (lastSync < now) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = prefs.edit(); editor.putLong(LASTSYNC_PARAM, now); editor.commit();/*from w ww .ja va 2s. c om*/ } }
From source file:Main.java
/** * Get the shared preference about knn from localization method. * * @param context The calling context.//from w ww .j a v a 2 s . c o m * @return Integer from preferences. If not a number, return value will be 3. */ public static int getPrefKnn(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); int value = 3; try { value = Integer.valueOf(sharedPreferences.getString("localization_knn", "3")); } catch (NumberFormatException e) { e.printStackTrace(); } return value; }
From source file:Main.java
public static void savePrefString(Context context, String key, String value) { if (pref == null) { // pref = context // .getSharedPreferences(PREFS, Context.MODE_PRIVATE); pref = PreferenceManager.getDefaultSharedPreferences(context); }//from ww w . j a v a 2 s. c om if (editor == null) { editor = pref.edit(); } editor.putString(key, value); editor.commit(); }
From source file:Main.java
/** * Retrieves a boolean value from preference manager. If no such key exists, it will return the * value provided as <code>defaultValue</code> *//*from ww w. j a v a 2 s .c o m*/ public static boolean getBooleanFromPreference(Context context, String key, boolean defaultValue) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); return pref.getBoolean(key, defaultValue); }
From source file:Main.java
/** * Called to save supplied value in shared preferences against given key. * * @param context Context of caller activity * @param key Key of value to save against * @param value Value to save/* w w w . jav a2 s. c o m*/ */ public static void saveToPrefs(Context context, String key, String value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = prefs.edit(); editor.putString(key, value); editor.commit(); }