xuxiuxi
2017-08-01 21e08324c323d0c5d1e7cedc36323c554857a239
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
package cn.com.basic.face.base;
 
import android.app.Application;
 
import cn.com.basic.face.discern.common.CommonVariables;
import cn.com.basic.face.discern.entity.Device;
import cn.com.basic.face.discern.query.item.DeviceQueryItem;
import cn.com.basic.face.service.InternetAccessThread;
import cn.com.basic.face.service.DictionaryMng;
 
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 androidDevice;
    private DeviceQueryItem camera1;
    private DeviceQueryItem camera2;
 
 
    public static boolean deviceAvailable = false;
 
    public void setAndroidDevice(Device device) {
        this.androidDevice = device;
        if (device != null && device.getDeviceId() != null && !"".equals(device.getDeviceId())) {
            deviceAvailable = true;
            DictionaryMng.getInstance().loadAllDictionaryData();
        }
    }
 
    public void setCamera1(DeviceQueryItem camera1) {
        this.camera1 = camera1;
        if (camera1 != null && camera1.getDeviceId() != null && !"".equals(camera1.getDeviceId())) {
            DictionaryMng.getInstance().loadAllDictionaryData();
        }
    }
 
    public void setCamera2(DeviceQueryItem camera2) {
        this.camera2 = camera2;
        if (camera2 != null && camera2.getDeviceId() != null && !"".equals(camera2.getDeviceId())) {
            DictionaryMng.getInstance().loadAllDictionaryData();
        }
    }
 
    public Device getAndroidDevice() {
        if (androidDevice == null) {
            androidDevice = new Device();
        }
        return androidDevice;
    }
 
    @Override
    public void onCreate() {
        super.onCreate();
        x.Ext.init(this);
        Fresco.initialize(this);
        initOkHttpUtils();
        application = this;
    }
 
    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);
    }
 
 
    public boolean networkAvailable() {
//        return false;
        return MainActivity.getInstance().getInternetAccessible() == CommonVariables.InternetAccess.INTERNET_ACCESSIBLE;
    }
}