张海江
2017-07-26 8dcf4645301af81d39bbcb936b52eb8f904352e8
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
package com.moral.yunfushao.utils;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
 
import com.moral.yunfushao.MainApp;
import com.moral.yunfushao.model.User;
 
public class SharedPreferencesUtil {
    private Context mContext;
    public final static String SP_LOGIN_USER_KEY = "login_user";
    public final static String SP_BLE = "ble";
    public SharedPreferencesUtil(Context context) {
        this.mContext = context;
    }
 
    /**
     * 保存蓝牙设备信息
     * @param mac
     */
    public void saveBLE(String  mac){
        SharedPreferences preferences = mContext.getSharedPreferences(SP_BLE, Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.putString("mac", mac);
        editor.commit();
    }
 
    public String getBLE(){
        SharedPreferences preferences = mContext.getSharedPreferences(SP_BLE, Context.MODE_PRIVATE);
        String mac = preferences.getString("mac","");
        return mac;
    }
 
 
    public void saveLoginInfo(User loginUser){
        SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.commit();
    }
 
    public User getLoginInfo(){
        SharedPreferences sp = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE);
        User loginUserInfo = new User();
        return loginUserInfo;
    }
 
    public String getUserid(){
        SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE);
        String userid = preferences.getString("id","");
        return userid;
    }
 
    
 
    
    public void exitLogin(){
        SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.putString("id","");
        editor.putString("nickname","");
        editor.putString("password","");
        editor.putString("username","");
        editor.putString("hotelid","");
        editor.putString("hotelname","");
        editor.putInt("opt",0);
        editor.commit();
        MainApp.theApp.userId="";
    }
 
    /**
     * 保存是否第一次登陆
     * @param flag
     */
    public void saveFirstUse(int flag) {
        SharedPreferences preferences = mContext.getSharedPreferences("firstInfo",
                Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.putInt("firstUse", flag);
        editor.commit();
    }
    
    public int getFirstUse() {
        SharedPreferences preferences = mContext.getSharedPreferences("firstInfo",
                Context.MODE_PRIVATE);
        int firstUse = preferences.getInt("firstUse", 0);
        return firstUse;
    }
}