fctom1215
2020-03-10 29cd07271e0e37ce1e4b5c0d7c56f98da208190f
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package safeluck.drive.evaluation.fragment;
 
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
 
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
 
import com.anyun.exam.lib.AYSdk;
import com.anyun.exam.lib.MyLog;
import com.anyun.exam.lib.util.ByteUtil;
import com.google.gson.Gson;
import com.safeluck.aykj.utils.BytesUtils;
 
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
 
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.BuildConfig;
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatus;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatusViewModel;
import safeluck.drive.evaluation.DB.rtktb.RTKConfig;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel;
import safeluck.drive.evaluation.MainActivity;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.adapter.GpsInfoAdapter;
import safeluck.drive.evaluation.adapter.QuickAdapter;
import safeluck.drive.evaluation.adapter.WrapContentLinearLayoutManager;
import safeluck.drive.evaluation.bean.ExamPlatformData;
import safeluck.drive.evaluation.bean.MCUInfo;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
import safeluck.drive.evaluation.util.FileUtil;
 
/**
 * 基础数据设置
 * 通过设置IP和port,与驾考辅助软件通过tcp传输GPS报文给评判软件
 * MyApplication2
 * Created by lzw on 2019/3/20. 11:22:39
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class BaseDatasFragment extends SupportFragment {
 
    private static final String TAG = BaseDatasFragment.class.getSimpleName();
    private Gson gson = new Gson();
    private RTKConfig mRtkConfig;
    private AppStatus appStatus;
    private AppStatusViewModel appStatusViewModel;
    private ICEventListener icEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
            if (msgCode == Constant.MCU_SN){
                String mcuinfoStr = (String)obj;
                if (gson != null){
                    final MCUInfo mcuInfo=gson.fromJson(mcuinfoStr, MCUInfo.class);
                            Field [] fields = mcuInfo.getClass().getDeclaredFields();
                            datas.clear();
 
                            for (int i = 0; i < fields.length; i++) {
                                fields[i].setAccessible(true);
                                try {
                                    if (fields[i].getName().equalsIgnoreCase("version")){
                                        String version = (String) fields[i].get(mcuInfo);
                                        version = new String(BytesUtils.hexStringToBytes(version),"GBK");
                                        datas.add("版本号:" + version+"#"+ BuildConfig.VERSION_NAME);
                                    }else if(fields[i].getName().equalsIgnoreCase("sn")){
                                        datas.add( "设备序列号:" + fields[i].get(mcuInfo));
                                    }else if(fields[i].getName().equalsIgnoreCase("selftest")){
                                        datas.add( "自检状态:" + fields[i].get(mcuInfo));
                                    }
 
                                } catch (IllegalAccessException e) {
                                    e.printStackTrace();
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                }
                            }
                            lv.post(new Runnable() {
                                @Override
                                public void run() {
 
                                    if (mRtkConfig != null){
                                        datas.add("省ID:"+mRtkConfig.getProvince());
                                        datas.add("市ID:"+mRtkConfig.getCity());
                                        datas.add("电话:"+mRtkConfig.getPhone());
                                        datas.add("RTK平台地址:"+mRtkConfig.getIp()+":"+mRtkConfig.getPort());
 
                                        datas.add("考试平台地址:"+ExamPlatformData.getInstance().getPlatformIP()+":"+ExamPlatformData.getInstance().getPlatformPort());
                                    }
                                    if (appStatus != null){
                                        datas.add("RTK平台状态:"+(appStatus.getRtk_connect_status()==1?(appStatus.getRtk_login_code()==0?"已登录":"未登录"):"未连接"));
                                        datas.add("考试平台状态:"+ExamPlatformData.getInstance().getExamplatformStatusStr(ExamPlatformData.getInstance().getExamplatformStatus()));
                                    }
                                    gpsInfoAdapter.addAll(datas);
                                }
                            });
 
                }
            }
        }
    };
 
    public static SupportFragment newInstance() {
        return new BaseDatasFragment();
    }
 
 
    private List<String> datas = new ArrayList<>();
    private RecyclerView recyclerView;
    private ListView lv;
    private GpsInfoAdapter gpsInfoAdapter;
    private List<String> gpsinfos = new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 
 
 
        View view = inflater.inflate(R.layout.layout_gps_info, container, false);
        initView(view);
        
        View footView = inflater.inflate(R.layout.gps_info_item_rightarrow,null);
        View headView = inflater.inflate(R.layout.inspect_signal_head,null);
        lv.addFooterView(footView);
        lv.addHeaderView(headView);
        footView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                SetArgumentsFragment setArgumentsFragment = findFragment(SetArgumentsFragment.class);
//                if (setArgumentsFragment == null){
//                    setArgumentsFragment = SetArgumentsFragment.newInstance();
//                }
                ((BaseSettingFragment)getParentFragment()).startBrotherFragment(SetArgumentsFragment.newInstance());
 
            }
        });
        headView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((BaseSettingFragment)getParentFragment()).startBrotherFragment(InspectSignalFragment.newInstance());
 
            }
        });
 
        RTKConfigViewModel rtkConfigViewModel= ViewModelProviders.of(this).get(RTKConfigViewModel.class);
        rtkConfigViewModel.getRTKConfig().observe(this, new Observer<RTKConfig>() {
            @Override
            public void onChanged(RTKConfig rtkConfig) {
                if (rtkConfig != null){
                    Log.i(TAG, "RTKConfig Changed: "+rtkConfig.toString());
                    mRtkConfig = rtkConfig;
                }
 
 
            }
        });
 
                appStatusViewModel = ViewModelProviders.of(this).get(AppStatusViewModel.class);
        appStatusViewModel.getAppStatus().observe(this, new Observer<AppStatus>() {
            @Override
            public void onChanged(AppStatus ppStatus) {
                if (ppStatus != null){
                    appStatus = ppStatus;
                }
            }
        });
 
        return view;
    }
    private void initView(View view) {
        lv = view.findViewById(R.id.lv_gpsinfo);
        gpsInfoAdapter = new GpsInfoAdapter(_mActivity);
        lv.setAdapter(gpsInfoAdapter);
 
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_MCUINFO_TOPIC);
    }
 
    @Override
    public void onDetach() {
        super.onDetach();
        CEventCenter.onBindEvent(false,icEventListener,Constant.BIND_MCUINFO_TOPIC);
    }
}