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.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); }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()); datas.add("考试平台状态:"+appStatus.getRtk_connect_status()); } gpsInfoAdapter.addAll(datas); } }); } } } }; public static SupportFragment newInstance() { return new BaseDatasFragment(); } private List datas = new ArrayList<>(); private RecyclerView recyclerView; private ListView lv; private GpsInfoAdapter gpsInfoAdapter; private List 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() { @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() { @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(true,icEventListener,Constant.BIND_MCUINFO_TOPIC); } }