-
Notifications
You must be signed in to change notification settings - Fork 3
/
PreferenceUtil.java
75 lines (64 loc) · 2.21 KB
/
PreferenceUtil.java
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
package com.android.kickstart.utils;
import android.app.Activity;
import android.content.Context;
public class PreferenceUtil {
// SharedPreference
private android.content.SharedPreferences SharedPreferences;
private android.content.SharedPreferences.Editor SharedPreferencesEditor;
public PreferenceUtil(Context context, String preferenceName) {
// Create SharedPreferences
SharedPreferences = context.getSharedPreferences(preferenceName, Activity.MODE_PRIVATE);
SharedPreferencesEditor = SharedPreferences.edit();
}
/**
* @param key Key of the preference
* @param value Value of the key
*/
public void putInt(String key, int value) {
SharedPreferencesEditor.putInt(key, value).commit();
}
/**
* @param key Key of the preference
* @param value Value of the key
*/
public void putString(String key, String value) {
SharedPreferencesEditor.putString(key, value).commit();
}
/**
* @param key Key of the preference
* @param value Value of the key
*/
public void putBoolean(String key, boolean value) {
SharedPreferencesEditor.putBoolean(key, value).commit();
}
/**
* @param key Key of the preference
* @param defaultVaule Default value if key is not available
* @return Value of key
*/
public int getInt(String key, int defaultVaule) {
return SharedPreferences.getInt(key, defaultVaule);
}
/**
* @param key Key of the preference
* @param defaultVaule Default value if key is not available
* @return Value of key
*/
public String getString(String key, String defaultVaule) {
return SharedPreferences.getString(key, defaultVaule);
}
/**
* @param key Key of the preference
* @param defaultVaule Default value if key is not available
* @return Value of key
*/
public boolean getBoolean(String key, boolean defaultVaule) {
return SharedPreferences.getBoolean(key, defaultVaule);
}
/**
*
*/
public void clear() {
SharedPreferencesEditor.clear().commit();
}
}