1 package com.folioreader.util;
\r
3 import android.content.Context;
\r
4 import android.content.SharedPreferences;
\r
5 import android.preference.PreferenceManager;
\r
7 import java.util.Set;
\r
10 * Created by PC on 6/9/2016.
\r
12 public class SharedPreferenceUtil {
\r
13 public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer";
\r
14 public static final String REGISTRATION_COMPLETE = "registrationComplete";
\r
16 public static void putSharedPreferencesInt(Context context, String key, int value) {
\r
17 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
18 SharedPreferences.Editor edit = preferences.edit();
\r
19 edit.putInt(key, value);
\r
23 public static void putSharedPreferencesBoolean(Context context, String key, boolean val) {
\r
24 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
25 SharedPreferences.Editor edit = preferences.edit();
\r
26 edit.putBoolean(key, val);
\r
30 public static void putSharedPreferencesString(Context context, String key, String val) {
\r
31 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
32 SharedPreferences.Editor edit = preferences.edit();
\r
33 edit.putString(key, val);
\r
37 public static void putSharedPreferencesStringSet(Context context, String key, Set<String> val) {
\r
38 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
39 SharedPreferences.Editor editor = preferences.edit();
\r
40 editor.putStringSet(key, val);
\r
44 public static void putSharedPreferencesFloat(Context context, String key, float val) {
\r
45 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
46 SharedPreferences.Editor edit = preferences.edit();
\r
47 edit.putFloat(key, val);
\r
51 public static void putSharedPreferencesLong(Context context, String key, long val) {
\r
52 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
53 SharedPreferences.Editor edit = preferences.edit();
\r
54 edit.putLong(key, val);
\r
58 public static long getSharedPreferencesLong(Context context, String key, long defaultValue) {
\r
59 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
60 return preferences.getLong(key, defaultValue);
\r
63 public static float getSharedPreferencesFloat(Context context, String key, float defaultValue) {
\r
64 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
65 return preferences.getFloat(key, defaultValue);
\r
68 public static String getSharedPreferencesString(Context context, String key, String defaultValue) {
\r
69 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
70 return preferences.getString(key, defaultValue);
\r
73 public static Set<String> getSharedPreferencesStringSet(Context context, String key, Set<String> defaultValue) {
\r
74 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
75 return preferences.getStringSet(key, defaultValue);
\r
78 public static int getSharedPreferencesInt(Context context, String key, int defaultValue) {
\r
79 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
80 return preferences.getInt(key, defaultValue);
\r
83 public static boolean getSharedPreferencesBoolean(Context context, String key, boolean defaultValue) {
\r
84 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
85 return preferences.getBoolean(key, defaultValue);
\r
88 public static boolean removeSharedPreferencesKey(Context context, String key) {
\r
89 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
\r
90 SharedPreferences.Editor editor = preferences.edit();
\r
92 return editor.commit();
\r