文章目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
public class PerferencesUtils {
public static String PREFERENCE_NAME = "MYPERFERENCERS";

public static boolean putString(Context context,String key,String value) {
SharedPreferces settings = context.getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
SharedPreferces.Editor = settings.edit();
editor.putString(key,value);
return editor.commit();
}

public static String getString(Context context,String key) {
return getString(context,key,null);
}

public static String getString(Context context,String key,String defaultValue) {
SharedPreferces settings = context.getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
return settings.getString(key,defaultValue);
}

public static boolean putInt(Context context,String key,int value) {
SharedPreferces settings = context.getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
SharedPreferces.Editor = settings.edit();
editor.putInt(key,value);
return editor.commit();
}

public static int getInt(Context context,String key) {
return getInt(context,key,-1);
}

public static int getInt(Context context,String key,int defaultValue) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
return settings.getInt(key,defaultValue);
}

public static putLong(Context context,String key,long value) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putLong(key,value);
return editor.commit();
}

public static long getLong(Context context, String key) {
return getLong(context, key, -1);
}

public static long getLong(Context context, String key, long defaultValue) {
SharedPreferences settings = context.getSharedPreferences(
PREFERENCE_NAME, Context.MODE_PRIVATE);
return settings.getLong(key, defaultValue);
}

public static boolean putFloat(Context context, String key, float value) {
SharedPreferences settings = context.getSharedPreferences(
PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putFloat(key, value);
return editor.commit();
}

public static float getFloat(Context context, String key) {
return getFloat(context, key, -1);
}

public static float getFloat(Context context, String key, float defaultValue) {
SharedPreferences settings = context.getSharedPreferences(
PREFERENCE_NAME, Context.MODE_PRIVATE);
return settings.getFloat(key, defaultValue);
}

public static boolean putBoolean(Context context, String key, boolean value) {
SharedPreferences settings = context.getSharedPreferences(
PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(key, value);
return editor.commit();
}

public static boolean getBoolean(Context context, String key) {
return getBoolean(context, key, false);
}

public static boolean getBoolean(Context context, String key,
boolean defaultValue) {
SharedPreferences settings = context.getSharedPreferences(
PREFERENCE_NAME, Context.MODE_PRIVATE);
return settings.getBoolean(key, defaultValue);
}

}
文章目录