xuxiuxi
2017-05-02 fe29f318c4973f07f61713d2436d0bf533092db2
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
package cn.com.basic.face.base;
 
import android.app.Application;
 
import cn.com.basic.face.discern.entity.Device;
import cn.com.basic.face.service.DictionaryMng;
import cn.com.basic.face.service.DeviceMng;
import cn.com.basic.face.util.WindowsUtil;
 
import com.facebook.drawee.backends.pipeline.Fresco;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.model.HttpHeaders;
import com.lzy.okhttputils.model.HttpParams;
 
import org.xutils.x;
 
public class BaseApplication extends Application{
 
    private static BaseApplication application;
 
    public static BaseApplication getInstance() {
        return application;
    }
 
    private Device device;
 
    public static boolean deviceAvailable = false;
 
    public void setDevice(Device device) {
        this.device = device;
        if (device != null && device.getDeviceId() != null && !"".equals(device.getDeviceId())) {
            deviceAvailable = true;
            DictionaryMng.getInstance().loadAllDictionaryData();
        }
    }
 
    public Device getDevice() {
        if (device == null) {
            device = new Device();
        }
        return device;
    }
 
    @Override
    public void onCreate() {
        super.onCreate();
        x.Ext.init(this);
        Fresco.initialize(this);
        initOkHttpUtils();
        application = this;
        DeviceMng.getInstance().findDevice();
 
    }
 
    private void initOkHttpUtils() {
        HttpHeaders headers = new HttpHeaders();
        headers.put("commonHeaderKey1", "commonHeaderValue1");    //所有的 header 都 不支持 中文
        headers.put("commonHeaderKey2", "commonHeaderValue2");
        HttpParams params = new HttpParams();
        params.put("commonParamsKey1", "commonParamsValue1");     //所有的 params 都 支持 中文
        params.put("commonParamsKey2", "这里支持中文参数");
        //必须调用初始化
        OkHttpUtils.init(this);
    }
 
}