-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPUtils.java
More file actions
50 lines (40 loc) · 1.66 KB
/
Copy pathSPUtils.java
File metadata and controls
50 lines (40 loc) · 1.66 KB
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
import android.content.Context;
import android.content.SharedPreferences;
public class SPUtils {
private SPUtils(){
}
private static final String FILE_NAME = "config_data";
public static void put(String key, Object object) {
SharedPreferences sp = getSharedPreferences();
SharedPreferences.Editor editor = sp.edit();
if (object instanceof String) {
editor.putString(key, (String) object);
} else if (object instanceof Integer) {
editor.putInt(key, (Integer) object);
} else if (object instanceof Boolean) {
editor.putBoolean(key, (Boolean) object);
} else if (object instanceof Float) {
editor.putFloat(key, (Float) object);
} else if (object instanceof Long) {
editor.putLong(key, (Long) object);
} else {
editor.putString(key, object.toString());
}
editor.apply();
}
public static SharedPreferences getSharedPreferences() {
return SenseMeetWallApplication.getInstance().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
}
public static String getString(String key, String defValue) {
return getSharedPreferences().getString(key, defValue);
}
public static int getInt(String key, int defValue) {
return getSharedPreferences().getInt(key, defValue);
}
public static float getFloat(String key, float defValue) {
return getSharedPreferences().getFloat(key, defValue);
}
public static boolean getBoolean(String key, boolean defValue) {
return getSharedPreferences().getBoolean(key, defValue);
}
}