lizhanwei
2020-01-08 c18de19b7c31f8f3436ece05378e07d089cf6b09
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package safeluck.drive.evaluation;
 
import android.app.Application;
import android.util.Log;
import android.widget.Toast;
 
 
import androidx.annotation.NonNull;
 
import com.anyun.exam.lib.AYSdk;
import com.anyun.exam.lib.IAYExamListener;
 
import me.yokeyword.fragmentation.Fragmentation;
import me.yokeyword.fragmentation.helper.ExceptionHandler;
import com.anyun.exam.lib.MyLog;
import com.anyun.exam.lib.crash.CrashHandler;
import com.facebook.stetho.Stetho;
import com.google.gson.Gson;
 
 
import org.json.JSONException;
import org.json.JSONObject;
 
import safeluck.drive.evaluation.DB.failitems.FailedProj;
import safeluck.drive.evaluation.DB.failitems.FailedProjRepository;
import safeluck.drive.evaluation.bean.RTKConfig;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.util.FileUtil;
import safeluck.drive.evaluation.util.SystemUtil;
 
/**
 * MyApplication2
 * Created by lzw on 2019/3/15. 10:53:52
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class app extends Application implements IAYExamListener {
 
    private static final String TAG = "app";
    private Gson gson;
    RTKConfig rtkConfig;
    @Override
    public void onCreate() {
        super.onCreate();
        //初始化Fragment 建议在Application onCreate里面初始化
        if (SystemUtil.compareProcessName(this)){
            Fragmentation.builder().stackViewMode(Fragmentation.BUBBLE).debug(false)
                    .handleException(new ExceptionHandler() {
                        @Override
                        public void onException(@NonNull Exception e) {
                            MyLog.i(TAG, "onException: " + e.getMessage());
                        }
                    })
                    .install();
 
            CrashHandler crashHandler =CrashHandler.getInstance();
            crashHandler.init(getApplicationContext());
            AYSdk.getInstance().init(getApplicationContext());
            AYSdk.getInstance().registListener(this);
            Log.i(TAG, "onCreate: ");
            MyLog.createIfNotExist();
            Stetho.initializeWithDefaults(this);
 
            //RTK配置信息
            rtkConfig = new RTKConfig();
            rtkConfig.setCity(12);
            rtkConfig.setImei("460123874561");
            rtkConfig.setInterval(1);
            rtkConfig.setIp("47.93.80.84");
            rtkConfig.setModel("123");
            rtkConfig.setPhone("2019101500000001");
            rtkConfig.setPort(12125);
            rtkConfig.setProvince(23);
            rtkConfig.setSn("2019101500000001");
        }
 
    }
 
    @Override
    public void onTerminate() {
        super.onTerminate();
        MyLog.e(TAG, "OnTerminate()");
        AYSdk.getInstance().uninit();
    }
 
    @Override
    public void onLowMemory() {
        super.onLowMemory();
        MyLog.e(TAG, "OnTerminate()");
    }
 
    @Override
    public void callBackMsg(int cmd, String json) {
        MyLog.d(TAG,  String.format("收到命令[%d],Json内容为%s",cmd,json));
        switch (cmd){
            case Constant.NDK_START:
                Toast.makeText(this, "NDK start", Toast.LENGTH_SHORT).show();
                break;
            case Constant.RTK_PLATFORM_REGISTER_STATUS:
                try {
                    JSONObject jsonObject = new JSONObject();
                    int reg_code = jsonObject.getInt("register_code");
                    String rtkLoginPwd = jsonObject.getString("password");
                    rtkConfig.setPassword(rtkLoginPwd);
                    rtkConfig.setRegistered(reg_code);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            case Constant.RTK_PLATFORM_REGISTER_RESULT:
                break;
            case Constant.FETCH_RTK_PLATFORM_INFO:
                if (gson == null){
                    gson = new Gson();
                }
                MyLog.i(TAG, "RTK配置信息:"+gson.toJson(rtkConfig));
                AYSdk.getInstance().sendCmd(Constant.PUSH_RTK_PLATFORM_INFO,gson.toJson(rtkConfig));
                break;
            case Constant.JUDGE_INFO:
                FailedProjRepository failedProjRepository = new FailedProjRepository(this);
                failedProjRepository.insert(new FailedProj(1,cmd,Constant.TEST_STU_ID));
                break;
        }
 
    }
 
 
 
}