doum
6 天以前 2b287056e2f59518888d05a1bbc7e5a55fbd84d5
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
package com.example.datalibrary.utils;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
 
public class BasePreferencesManager {
 
    /**
     * 上下问对象
     */
    private Context mContext;
 
    protected BasePreferencesManager(Context context) {
        this.mContext = context;
    }
 
    protected void clear(String preferences) {
        Editor editor = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.commit();
    }
 
    protected void setBoolean(String preferences, String key, boolean value) {
        Editor editor = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE).edit();
        editor.putBoolean(key, value);
        editor.commit();
    }
 
    protected boolean getBoolean(String preferences, String key, boolean defaultvalue) {
        SharedPreferences sp = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE);
        return sp.getBoolean(key, defaultvalue);
    }
 
    protected int getInt(String preferences, String key, int defaultvalue) {
        SharedPreferences sp = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE);
        return sp.getInt(key, defaultvalue);
    }
 
    protected void setInt(String preferences, String key, int value) {
        Editor editor = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE).edit();
        editor.putInt(key, value);
        editor.commit();
    }
 
    protected String getString(String preferences, String key, String defaultvalue) {
        SharedPreferences sp = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE);
        return sp.getString(key, defaultvalue);
    }
 
    protected void setString(String preferences, String key, String value) {
        Editor editor = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE).edit();
        editor.putString(key, value);
        editor.commit();
    }
 
    protected float getFloat(String preferences, String key, float defaultvalue) {
        SharedPreferences sp = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE);
        return sp.getFloat(key, defaultvalue);
    }
 
    protected void setFloat(String preferences, String key, float value) {
        Editor editor = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE).edit();
        editor.putFloat(key, value);
        editor.commit();
    }
 
    public long getLong(String preferences, String key, long defaultvalue) {
        SharedPreferences sp = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE);
        return sp.getLong(key, defaultvalue);
    }
 
    protected void setLong(String preferences, String key, long value) {
        Editor editor = mContext.getSharedPreferences(preferences, Context.MODE_PRIVATE).edit();
        editor.putLong(key, value);
        editor.commit();
    }
}