yy1717
2020-09-17 1635b1420128b33b3d17e21e92625da651fca11e
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package safeluck.drive.evaluation.fragment;
 
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
 
import androidx.annotation.IdRes;
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.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
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.basecommonlib.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.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
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.BaseDataInfoAdapter;
import safeluck.drive.evaluation.adapter.GpsInfoAdapter;
import safeluck.drive.evaluation.adapter.QuickAdapter;
import safeluck.drive.evaluation.adapter.WrapContentLinearLayoutManager;
import safeluck.drive.evaluation.bean.BaseDataUIBean;
import safeluck.drive.evaluation.bean.ExamPlatformData;
import safeluck.drive.evaluation.bean.MCUInfo;
import safeluck.drive.evaluation.bean.MapInfoHead;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
import safeluck.drive.evaluation.util.DataInitKt;
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 implements BaseDataInfoAdapter.Callback {
 
    private static final String TAG = BaseDatasFragment.class.getSimpleName();
    private Gson gson = new Gson();
    private RTKConfig mRtkConfig;
    private AppStatus appStatus;
    private SpannableString spannableString;
    private String versionDes;
    private String version;
    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")){
                                        version= (String) fields[i].get(mcuInfo);
                                        version = new String(BytesUtils.hexStringToBytes(version),"GBK");
                                        versionDes= "版本号                     ";
                                        version = version+"#"+ BuildConfig.VERSION_NAME;
 
                                        datas.add(new BaseDataUIBean(str2SpannableString(versionDes),R.mipmap.version_pic,str2FouregourdSpannableString(version),"",1,null));
                                    }else if(fields[i].getName().equalsIgnoreCase("sn")){
                                        datas.add(new BaseDataUIBean(str2SpannableString("设备序列号"),R.mipmap.device_sn,str2FouregourdSpannableString(String.valueOf(fields[i].get(mcuInfo))),"",1,null));
                                    }else if(fields[i].getName().equalsIgnoreCase("selftest")){
                                        datas.add(new BaseDataUIBean(str2SpannableString("自检状态 "),R.mipmap.auto_check_status,str2FouregourdSpannableString(String.valueOf(fields[i].get(mcuInfo))),"",1,null));
                                    }
 
                                } catch (IllegalAccessException e) {
                                    e.printStackTrace();
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                }
                            }
                            lv.post(new Runnable() {
                                @Override
                                public void run() {
 
                                    if (mRtkConfig != null){
                                        datas.add(new BaseDataUIBean(str2SpannableString("省ID  "),R.mipmap.province_id,str2FouregourdSpannableString(String.valueOf(mRtkConfig.getProvince())),"",1,null));
                                        datas.add(new BaseDataUIBean(str2SpannableString("市ID  "),R.mipmap.province_id,str2FouregourdSpannableString(String.valueOf(mRtkConfig.getCity())),"",1,null));
                                        datas.add(new BaseDataUIBean(str2SpannableString("RTK平台地址  "),R.mipmap.platform_pic,str2FouregourdSpannableString(mRtkConfig.getIp()+":"+mRtkConfig.getPort()),"",1,null));
                                        datas.add(new BaseDataUIBean(str2SpannableString("考试平台地址  "),R.mipmap.platform_pic,str2FouregourdSpannableString(ExamPlatformData.getInstance().getPlatformIP()
                                                +":"+ExamPlatformData.getInstance().getPlatformPort()),"",1,null));
 
                                    }
                                    if (appStatus != null){
                                          datas.add(new BaseDataUIBean(str2SpannableString("RTK平台状态"),R.mipmap.conn_status,str2FouregourdSpannableString(appStatus.getRtk_connect_status()==1?(appStatus.getRtk_login_code()==0?"已登录":"未登录"):"未连接"),"",1,null));
                                          datas.add(new BaseDataUIBean(str2SpannableString("考试平台状态"),R.mipmap.conn_status,str2FouregourdSpannableString(ExamPlatformData.getInstance().getExamplatformStatusStr(ExamPlatformData.getInstance().getExamplatformStatus())),"",1,null));
                                    }
                                    HashMap<BaseDataUIBean.TYPE_, MapInfoHead> hashMaps = ExamPlatformData.getInstance().getMapInfoHeads();
                                    if (hashMaps != null){
                                        Iterator<Map .Entry<BaseDataUIBean.TYPE_,MapInfoHead>> iterator = hashMaps.entrySet().iterator();
                                        while (iterator.hasNext()){
                                            Map.Entry<BaseDataUIBean.TYPE_,MapInfoHead>entry = iterator.next();
                                            Log.i(TAG,"key= " + entry.getKey() + " and value= " + entry.getValue());
                                            datas.add(new BaseDataUIBean(str2SpannableString(entry.getValue().getStr()),R.mipmap.province_id,str2FouregourdSpannableString(getResources().getString(R.string.mapversion)+entry.getValue().getVersion()),
                                                    entry.getKey()== BaseDataUIBean.TYPE_.car?"更新车辆模型":(entry.getKey()== BaseDataUIBean.TYPE_.road?"更新道路地图":"更新场地地图")
                                                    ,1, entry.getKey()));
                                        }
                                    }
 
 
                                    gpsInfoAdapter.addAll(datas);
                                }
                            });
 
                }
            }
        }
    };
 
    private SpannableString str2FouregourdSpannableString(String s) {
        spannableString = new SpannableString(s);
        spannableString.setSpan(new AbsoluteSizeSpan(28),0,s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFFFF")),0,s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
 
 
 
    public static SupportFragment newInstance() {
        return new BaseDatasFragment();
    }
 
 
    private List<BaseDataUIBean> datas = new ArrayList<>();
    private ListView lv;
    private BaseDataInfoAdapter gpsInfoAdapter;
    @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);
        lv.setDivider(new ColorDrawable(Color.parseColor("#2A344B")));
        lv.setDividerHeight(1);
        footView.setOnClickListener(v -> ((BaseSettingFragment)getParentFragment()).startBrotherFragment(SetArgumentsFragment.newInstance()));
        headView.setOnClickListener(v -> ((BaseSettingFragment)getParentFragment()).startBrotherFragment(InspectSignalFragment.newInstance()));
 
        RTKConfigViewModel rtkConfigViewModel= ViewModelProviders.of(this).get(RTKConfigViewModel.class);
        rtkConfigViewModel.getRTKConfig().observe(this, rtkConfig -> {
            if (rtkConfig != null){
                Log.i(TAG, "RTKConfig Changed: "+rtkConfig.toString());
                mRtkConfig = rtkConfig;
            }
 
 
        });
 
                appStatusViewModel = ViewModelProviders.of(this).get(AppStatusViewModel.class);
        appStatusViewModel.getAppStatus().observe(this, ppStatus -> {
            if (ppStatus != null){
                appStatus = ppStatus;
            }
        });
 
        return view;
    }
    private void initView(View view) {
        Log.i(TAG,"currTopFragment="+getTopFragment().getClass().getSimpleName());
        if (HomeFragment.class.getSimpleName().equals(getTopFragment().getClass().getSimpleName())){
            ((MainActivity)_mActivity).viewtitle.setVisibility(View.GONE);
            ((MainActivity)_mActivity).btn_return.setVisibility(View.GONE);
        }else{
            ((MainActivity)_mActivity).viewtitle.setVisibility(View.VISIBLE);
            ((MainActivity)_mActivity).btn_return.setVisibility(View.VISIBLE);
        }
        lv = view.findViewById(R.id.lv_gpsinfo);
        gpsInfoAdapter = new BaseDataInfoAdapter(_mActivity);
        lv.setAdapter(gpsInfoAdapter);
 
        gpsInfoAdapter.setCallback(this);
 
 
 
    }
 
    private SpannableString str2SpannableString(String str) {
        spannableString = new SpannableString(str);
        spannableString.setSpan(new AbsoluteSizeSpan(22),0,str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#A8AAA7")),0,str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
 
    @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);
    }
 
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ((MainActivity)_mActivity).viewtitle.setVisibility(View.GONE);
        ((MainActivity)_mActivity).btn_return.setVisibility(View.GONE);
    }
 
    @Override
    public void click(View view) {
        if (view != null){
            Log.i(TAG,"view="+(int)view.getTag());
            BaseDataUIBean.TYPE_ type = datas.get((int)view.getTag()).getType_();
            switch (type){
                case car:
 
                    break;
                case road:
 
                    break;
                case yard:
 
                    break;
            }
        }
    }
}