| | |
| | | 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.ViewGroup; |
| | | import android.widget.Button; |
| | | import android.widget.EditText; |
| | | import android.widget.ListView; |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | |
| | | 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.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; |
| | |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class BaseDatasFragment extends SupportFragment implements View.OnClickListener { |
| | | public class BaseDatasFragment extends SupportFragment { |
| | | |
| | | private static final String TAG = BaseDatasFragment.class.getSimpleName(); |
| | | private static final int REQUEST_CODE_MAP = 100; |
| | | private static final int REQUEST_CODE_CAR = 101; |
| | | private int request_code = REQUEST_CODE_MAP; |
| | | private Button btn_inspect_signal; |
| | | private Button btn_config_signal; |
| | | private Button btn_mcu_upgrade,btn_map_select; |
| | | private EditText et_ip,et_port; |
| | | private Gson gson; |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | private EditText et_ip_rtk,et_port_rtk,et_city_id,et_city_province,et_phone; |
| | | private TextView tv_mcu; |
| | | // RTK注册状态、RTK连接状态、 |
| | | // private TextView tv_reg,tv_connect,tv_model,tv_sn,tv_imei,tv_login; |
| | | private RTKConfigViewModel rtkConfigViewModel; |
| | | private Gson gson = new Gson(); |
| | | private RTKConfig mRtkConfig; |
| | | private AppStatus appStatus; |
| | | private AppStatusViewModel appStatusViewModel; |
| | | private ICEventListener icEventListener = new ICEventListener() { |
| | | @Override |
| | |
| | | String mcuinfoStr = (String)obj; |
| | | if (gson != null){ |
| | | final MCUInfo mcuInfo=gson.fromJson(mcuinfoStr, MCUInfo.class); |
| | | stringBuffer.delete(0,stringBuffer.toString().length()); |
| | | |
| | | 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"); |
| | | stringBuffer.append(" "+fields[i].getName() + ":" + version); |
| | | Log.i(TAG, "onCEvent: "+version); |
| | | datas.add(fields[i].getName() + ":" + version); |
| | | }else |
| | | stringBuffer.append(" "+fields[i].getName() + ":" + fields[i].get(mcuInfo)); |
| | | datas.add(fields[i].getName() + ":" + fields[i].get(mcuInfo)); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | tv_mcu.post(new Runnable() { |
| | | lv.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | tv_mcu.setText(getString(R.string.mcu_info)+stringBuffer.toString()); |
| | | |
| | | if (mRtkConfig != null){ |
| | | datas.add("省ID:"+mRtkConfig.getProvince()); |
| | | datas.add("市ID:"+mRtkConfig.getCity()); |
| | | datas.add("电话:"+mRtkConfig.getPhone()); |
| | | datas.add("RTK平台地址:"+mRtkConfig.getIp()); |
| | | datas.add("RTK平台端口:"+mRtkConfig.getPort()); |
| | | |
| | | datas.add("考试平台地址:"+ExamPlatformData.getInstance().getPlatformIP()); |
| | | datas.add("考试平台端口:"+ExamPlatformData.getInstance().getPlatformPort()); |
| | | } |
| | | if (appStatus != null){ |
| | | datas.add("RTK平台连接状态:"+appStatus.getRtk_connect_status()); |
| | | datas.add("RTK平台登录状态:"+appStatus.getRtk_login_code()); |
| | | datas.add("考试平台连接状态:"+appStatus.getRtk_connect_status()); |
| | | datas.add("考试平台登录状态:"+appStatus.getRtk_login_code()); |
| | | } |
| | | gpsInfoAdapter.addAll(datas); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | 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_base_datas, container, false); |
| | | |
| | | View view = inflater.inflate(R.layout.layout_gps_info, container, false); |
| | | initView(view); |
| | | rtkConfigViewModel= ViewModelProviders.of(this).get(RTKConfigViewModel.class); |
| | | |
| | | 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; |
| | | et_ip_rtk.setText(rtkConfig.getIp()); |
| | | et_city_id.setText(String.valueOf(rtkConfig.getCity())); |
| | | et_city_province.setText(String.valueOf(rtkConfig.getProvince())); |
| | | et_port_rtk.setText(String.valueOf(rtkConfig.getPort())); |
| | | et_phone.setText(rtkConfig.getPhone()); |
| | | // tv_sn.setText(getResources().getString(R.string.rtk_config_sn,rtkConfig.getSn())); |
| | | // tv_model.setText(getResources().getString(R.string.rtk_config_model,rtkConfig.getModel())); |
| | | // tv_imei.setText(getResources().getString(R.string.rtk_config_imei,rtkConfig.getImei())); |
| | | // tv_reg.setText(getResources().getString(R.string.rtk_register_status,rtkConfig.getRegistered())); |
| | | } |
| | | |
| | | |
| | | } |
| | | }); |
| | | |
| | | appStatusViewModel = ViewModelProviders.of(this).get(AppStatusViewModel.class); |
| | | appStatusViewModel = ViewModelProviders.of(this).get(AppStatusViewModel.class); |
| | | appStatusViewModel.getAppStatus().observe(this, new Observer<AppStatus>() { |
| | | @Override |
| | | public void onChanged(AppStatus appStatus) { |
| | | if (appStatus != null){ |
| | | // tv_login.setText(getResources().getString(R.string.rtk_config_login,appStatus.getRtk_login_code())); |
| | | // tv_connect.setText(getResources().getString(R.string.rtk_connect_status,appStatus.getRtk_connect_status())); |
| | | public void onChanged(AppStatus ppStatus) { |
| | | if (ppStatus != null){ |
| | | appStatus = ppStatus; |
| | | } |
| | | } |
| | | }); |
| | | |
| | | return view; |
| | | } |
| | | |
| | | private void initView(View view) { |
| | | gson = new Gson(); |
| | | view.findViewById(R.id.btn_save_platform).setOnClickListener(this); |
| | | et_ip = view.findViewById(R.id.et_platform_ip); |
| | | et_port = view.findViewById(R.id.et_platform_port); |
| | | et_ip.setText(ExamPlatformData.getInstance().getPlatformIP()); |
| | | et_port.setText(ExamPlatformData.getInstance().getPlatformPort()+""); |
| | | btn_inspect_signal = view.findViewById(R.id.btn_inpsect_signal); |
| | | btn_mcu_upgrade = view.findViewById(R.id.btn_mcu_upgrade); |
| | | btn_map_select = view.findViewById(R.id.btn_map_select); |
| | | view.findViewById(R.id.btn_car_select).setOnClickListener(this); |
| | | btn_mcu_upgrade.setOnClickListener(this); |
| | | btn_map_select.setOnClickListener(this); |
| | | btn_inspect_signal.setOnClickListener(this); |
| | | btn_config_signal = view.findViewById(R.id.btn_signal_conf); |
| | | btn_config_signal.setOnClickListener(this); |
| | | lv = view.findViewById(R.id.lv_gpsinfo); |
| | | gpsInfoAdapter = new GpsInfoAdapter(_mActivity); |
| | | lv.setAdapter(gpsInfoAdapter); |
| | | |
| | | |
| | | et_ip_rtk = view.findViewById(R.id.rtk_addr_ip); |
| | | et_city_id = view.findViewById(R.id.et_city_id); |
| | | et_city_province = view.findViewById(R.id.et_provice_id); |
| | | et_phone = view.findViewById(R.id.et_phone); |
| | | et_port_rtk = view.findViewById(R.id.rtk_addr_port); |
| | | tv_mcu = view.findViewById(R.id.tv_mcu_info); |
| | | |
| | | // tv_connect = view.findViewById(R.id.tv_rtk_connect);//RTK平台连接状态 |
| | | // tv_imei = view.findViewById(R.id.tv_rtk_imei); |
| | | // tv_login = view.findViewById(R.id.tv_rtk_login);//RTK平台登录结果 |
| | | // tv_model = view.findViewById(R.id.tv_rtk_model); |
| | | // tv_reg = view.findViewById(R.id.tv_rtk_reg);//RTK平台注册状态 |
| | | // tv_sn = view.findViewById(R.id.tv_rtk_sn); |
| | | } |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | switch (v.getId()) { |
| | | case R.id.btn_inpsect_signal: |
| | | ((BaseSettingFragment)getParentFragment()).startBrotherFragment(InspectSignalFragment.newInstance()); |
| | | break; |
| | | case R.id.btn_signal_conf: |
| | | ((BaseSettingFragment)getParentFragment()).startBrotherFragment(SignalConfigFragment.newInstance()); |
| | | break; |
| | | case R.id.btn_mcu_upgrade: |
| | | |
| | | |
| | | |
| | | try { |
| | | byte[] datas =FileUtil.readLocalFile(getActivity(),"dfu.bin"); |
| | | if (datas != null){ |
| | | Log.i(TAG,ByteUtil.byte2hex(datas)); |
| | | |
| | | String strs = new String(datas, Charset.forName("ISO-8859-1")); |
| | | Log.i(TAG, "onClick: datas.legnth=="+strs.getBytes("ISO-8859-1").length); |
| | | AYSdk.getInstance().sendCmd(Constant.UPGRADE_MCU_CONTENT_FILE, strs); |
| | | }else{ |
| | | MyLog.i(TAG,"mcu升级文件不存在"); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | break; |
| | | case R.id.btn_save_platform: |
| | | if(ExamPlatformData.getInstance().compareIPandPort(et_ip.getText().toString().trim(),Integer.parseInt(et_port.getText().toString().trim()))){ |
| | | ((MainActivity)getActivity()).examPlatformModel.getDataChange().postValue(1); |
| | | ExamPlatformData.getInstance().insertPlatformIp(et_ip.getText().toString().trim()); |
| | | ExamPlatformData.getInstance().insertPlatformPort(Integer.parseInt(et_port.getText().toString().trim())); |
| | | } |
| | | |
| | | if (mRtkConfig != null){ |
| | | mRtkConfig.setPort(Integer.parseInt(et_port_rtk.getText().toString().trim())); |
| | | mRtkConfig.setCity(Integer.parseInt(et_city_id.getText().toString().trim())); |
| | | mRtkConfig.setProvince(Integer.parseInt(et_city_province.getText().toString().trim())); |
| | | mRtkConfig.setIp(et_ip_rtk.getText().toString().trim()); |
| | | mRtkConfig.setPhone(et_phone.getText().toString().trim()); |
| | | rtkConfigViewModel.insertRTKConfig(mRtkConfig); |
| | | } |
| | | break; |
| | | case R.id.btn_car_select://车辆模型和地图公用一套代码 区别在于REQUEST_CODE |
| | | request_code = REQUEST_CODE_CAR; |
| | | openFileMgr(); |
| | | break; |
| | | case R.id.btn_map_select: |
| | | request_code = REQUEST_CODE_MAP; |
| | | openFileMgr(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void openFileMgr() { |
| | | Intent intent = new Intent(); |
| | | intent.setAction(Intent.ACTION_GET_CONTENT); |
| | | intent.setType("*/*"); |
| | | intent.addCategory(Intent.CATEGORY_OPENABLE); |
| | | try { |
| | | startActivityForResult(intent, request_code); |
| | | } catch (android.content.ActivityNotFoundException e) { |
| | | e.printStackTrace(); |
| | | Toast.makeText(_mActivity, "请安装文件管理器", Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| | | if (REQUEST_CODE_MAP == requestCode){ |
| | | if (data != null){ |
| | | final Uri uri= data.getData(); |
| | | Log.i(TAG, "onActivityResult: "+uri.getPath()); |
| | | ExamPlatformData.getInstance().setNewMapPath(uri.getPath()); |
| | | CThreadPoolExecutor.runInBackground(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | byte[] fileContent = FileUtil.readFile(uri.getPath()); |
| | | if (fileContent != null){ |
| | | String str = new String(fileContent); |
| | | Log.i(TAG, "文件内容:"+str); |
| | | AYSdk.getInstance().sendCmd(Constant.PUSH_MAP_INFO,str); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | }else if (requestCode == REQUEST_CODE_CAR){ |
| | | if (data != null){ |
| | | final Uri uri= data.getData(); |
| | | Log.i(TAG, "onActivityResult: "+uri.getPath()); |
| | | ExamPlatformData.getInstance().setCarModelPath(uri.getPath()); |
| | | CThreadPoolExecutor.runInBackground(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | byte[] fileContent = FileUtil.readFile(uri.getPath()); |
| | | if (fileContent != null){ |
| | | String str = new String(fileContent); |
| | | Log.i(TAG, "文件内容:"+str); |
| | | AYSdk.getInstance().sendCmd(Constant.PUSH_VECHILE_PROFILE,str); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onAttach(Context context) { |
| | | super.onAttach(context); |