package safeluck.drive.evaluation.fragment; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProviders; import android.os.Handler; import android.os.Message; import android.text.SpannableString; import android.text.Spanned; import android.text.TextUtils; import android.text.style.AbsoluteSizeSpan; import android.text.style.ForegroundColorSpan; import android.util.Base64; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; import com.anyun.exam.lib.AYSdk; import com.anyun.basecommonlib.MyLog; import com.google.gson.Gson; import org.jetbrains.annotations.NotNull; import org.json.JSONException; import org.json.JSONObject; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import me.yokeyword.fragmentation.SupportFragment; import safeluck.drive.evaluation.Constant; import safeluck.drive.evaluation.DB.Student; import safeluck.drive.evaluation.DB.WokViewModel; import safeluck.drive.evaluation.DB.WorkRoomDataBase; import safeluck.drive.evaluation.DB.exam_status.ExamStatus; import safeluck.drive.evaluation.DB.exam_status.ExamStatusViewModel; import safeluck.drive.evaluation.DB.failitems.FailedProjViewModel; import safeluck.drive.evaluation.DB.failitems.FailedProj_select; import safeluck.drive.evaluation.DB.route.RouteBean; import safeluck.drive.evaluation.DB.route.RouteCross; import safeluck.drive.evaluation.DB.route.RouteLineViewModel; import safeluck.drive.evaluation.DB.route.RouteTriggerLine; import safeluck.drive.evaluation.DB.rtktb.RTKConfigUpdateWorker; import safeluck.drive.evaluation.MainActivity; import safeluck.drive.evaluation.R; import safeluck.drive.evaluation.adapter.ScoreAdapter; import safeluck.drive.evaluation.bean.BaseDataUIBean; import safeluck.drive.evaluation.bean.ExamPlatformData; import safeluck.drive.evaluation.bean.MapInfoHead; import safeluck.drive.evaluation.bean.RemoteRouteCollect; import safeluck.drive.evaluation.bean.RouteCollect; import safeluck.drive.evaluation.bean.ScoreBean; import safeluck.drive.evaluation.cEventCenter.CEventCenter; import safeluck.drive.evaluation.cEventCenter.ICEventListener; import safeluck.drive.evaluation.customview.MyDialog; import safeluck.drive.evaluation.customview.MyInputDialog; import safeluck.drive.evaluation.customview.QRCodeDialog; import safeluck.drive.evaluation.customview.SelectDialog; import safeluck.drive.evaluation.customview.SelectDialogThree; import safeluck.drive.evaluation.customview.SelectMutliDialog; import safeluck.drive.evaluation.im.MessageProcessor; import safeluck.drive.evaluation.platformMessage.JKMessage0201; import safeluck.drive.evaluation.platformMessage.JKMessage0202; import safeluck.drive.evaluation.platformMessage.JKMessage0204; import safeluck.drive.evaluation.platformMessage.PlatFormConstant; import safeluck.drive.evaluation.routecollect.CollectPointResult; import safeluck.drive.evaluation.routecollect.ICollectView; import safeluck.drive.evaluation.routecollect.RouteCollectController; import safeluck.drive.evaluation.routecollect.bean.RoadCrossInfo; import safeluck.drive.evaluation.routecollect.bean.RoadInfo; import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.FileUtil; import safeluck.drive.evaluation.util.Utils; import safeluck.drive.evaluation.viewmodels.ExitExamViewModel; import safeluck.drive.evaluation.widget.StatusDialog; /**单机训练UI * MyApplication2 * Created by lzw on 2019/3/15. 14:32:50 * 邮箱:632393724@qq.com * All Rights Saved! Chongqing AnYun Tech co. LTD */ public class TrainFragment extends SupportFragment implements View.OnClickListener, ICollectView { private static final String TAG = TrainFragment.class.getSimpleName(); private static final int ROUTE_COLLECT = 5;//线路采集标志 private RouteBean currRouteBean; private ScrollView scrollView; public static SupportFragment newInstance() { return new TrainFragment(); } private View route_collect; private View items,items_score; private int exam_type = 2;//2 场地;3 道路,模拟夜考;4 道路,实际夜考 5,线路采集; private ListView mListView; private Button btn_start_exam; private TextView tv_stop;//呼叫请求(结束考试) private ScoreAdapter mScoreAdapter; private Button av_zhijiao, av_curve, av_park, av_podao; private Button houseView; private RouteLineViewModel routeLineViewModel; private List mRouteBeans = new ArrayList<>(); private List examStatusList = new ArrayList<>(); private List item_conents = new ArrayList<>();//坡道定点停车和起步 private int item_id;//扣分分数总和 private ExamStatusViewModel examStatusViewModel; private static final int ADD_DATA = 1; private TextView tv_speed,tv_total_score,tv_name ,tv_start_time,tv_coach_name; //主要用来展示线路采集时的信息 private TextView tv_route_collect_info; private StringBuilder stringBuilder = new StringBuilder(); private double speed=0.0; private ImageView iv_head,iv_coach_head; WokViewModel wokViewModel; private int currTotalScore = 100; private List mArrayList = new ArrayList<>(); private static final int SPEED_DATA = 2; private FailedProjViewModel failedProjViewModel; String icson;//返回的ic卡信息 json private String content;//用以生成二维码的内容 RouteCollectController routeCollectController; //要插入数据库的路口信息 private RouteCross routeCross; //要插入数据库的触发线信息 private RouteTriggerLine routeTriggerLine = new RouteTriggerLine(); private List btn_ids = new ArrayList(); private HashMap routeCollect_btn_ids = new HashMap<>(); private Handler mHandler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { if (msg.what == ADD_DATA){ MyLog.i("handler add_data totalScore="+currTotalScore); setTotalScoreText(); houseView.setBackground(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_REVERSE));//倒车入库 type =1 av_podao.setBackground(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_RAMP)); av_park.setBackground(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_PARK)); av_curve.setBackground(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_CURVE)); av_zhijiao.setBackground(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_ANGLE)); for (int i = 0; i < btn_ids.size(); i++) { int viewId = getResources().getIdentifier(String.valueOf(btn_ids.get(i)),"id",_mActivity.getPackageName()); ((Button) view.findViewById(viewId)).setBackground(bbb(101+i)); } } if (msg.what == SPEED_DATA){ tv_speed.setText(_mActivity.getApplicationContext().getResources().getString(R.string.speed,speed)); } if (msg.what == Constant.IC_ID){ try { JSONObject jsSpeed = new JSONObject(icson); int result = jsSpeed.getInt("result"); String icStr = jsSpeed.getString("serialno"); if (result == 0) { JKMessage0201 jkMessage0201 = new JKMessage0201(); jkMessage0201.phone = ExamPlatformData.getInstance().getPhone(); if (exam_type==Constant.Chang_di){ jkMessage0201.currentExam = 0; }else{ jkMessage0201.currentExam = 1; } jkMessage0201.id = icStr; MessageProcessor.getInstance().sendMessage(jkMessage0201); } }catch (JSONException e){ } } return false; } }); private Drawable aaa(int type) { if (examStatusList!=null &&examStatusList.size()>0){ for (ExamStatus examStatus: examStatusList) { if (type == examStatus.getMap_item()){ if (examStatus.getEnter() == safeluck.drive.evaluation.DB.Constant.BEGIN_ITEM){ //进入考场 if (examStatusList.get(0).getStartExam() == Constant.NONE_BEEN_START_EXAM){ //结束考试了 MyLog.i("进入考场结束考试,startexam="+examStatus.getStartExam()); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ MyLog.i(TAG,"进入考场,type="+type); return getResources().getDrawable(R.drawable.ic_btn_examing); } }else if (examStatus.getEnter() == safeluck.drive.evaluation.DB.Constant.FINISH_ITEM){ if (examStatusList.get(0).getStartExam()==Constant.NONE_BEEN_START_EXAM){ return getResources().getDrawable(R.drawable.ic_btn_daikao); } switch (type) { case 1://倒库 if (item_conents.contains("倒车入库")) { MyLog.i("该项考试失败,type="+type); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过倒车入库合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("倒车入库合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getDrawable(R.drawable.ic_btn_succ); } case 2: if (item_conents.contains("坡道定点停车和起步")) { MyLog.i("该项考试失败,type="+type); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过坡道定点停车和起步合格合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("坡道定点停车和起步合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getDrawable(R.drawable.ic_btn_succ); } case 3: if (item_conents.contains("侧方停车")) { MyLog.i("该项考试失败,type="+type); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过侧方停车合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("侧方停车合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getDrawable(R.drawable.ic_btn_succ); } case 4: if (item_conents.contains("曲线行驶")) { MyLog.i("该项考试失败,type="+type); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过曲线行驶合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("曲线行驶合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getDrawable(R.drawable.ic_btn_succ); } case 5: if (item_conents.contains("直角转弯")) { MyLog.i("该项考试失败,type="+type); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过直角转弯合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("直角转弯合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getDrawable(R.drawable.ic_btn_succ); } } }else{ return getResources().getDrawable(R.drawable.ic_btn_daikao); } } } } return getResources().getDrawable(R.drawable.ic_btn_daikao); } /** * 路考项目 每个项目的颜色变化 * @param type * @return */ private Drawable bbb(int type) { if (examStatusList!=null &&examStatusList.size()>0){ for (ExamStatus examStatus: examStatusList) { if (type == examStatus.getMap_item()){ if (examStatus.getEnter() == safeluck.drive.evaluation.DB.Constant.BEGIN_ITEM){ //进入考场 if (examStatusList.get(0).getStartExam() == Constant.NONE_BEEN_START_EXAM){ //结束考试了 MyLog.i("进入考场结束考试,startexam="+examStatus.getStartExam()); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ MyLog.i("进入考场,type="+type); return getResources().getDrawable(R.drawable.ic_btn_examing); } }else if (examStatus.getEnter() == safeluck.drive.evaluation.DB.Constant.FINISH_ITEM){ if (examStatusList.get(0).getStartExam()==Constant.NONE_BEEN_START_EXAM){ return getResources().getDrawable(R.drawable.ic_btn_daikao); } String ss=ExamPlatformData.getInstance().getItemStatusStr(type); if (item_conents.contains(ss)) { MyLog.i("该项考试失败,type="+type); return getResources().getDrawable(R.drawable.ic_btn_fail); }else{ if (examStatus.getResult() ==1){ MyLog.i(String.format("已经播放过%s合格",ss)); }else{ // ExamPlatformData.getInstance().getTTS().speak(String.format("%s合格",ss)); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getDrawable(R.drawable.ic_btn_succ); } }else{ return getResources().getDrawable(R.drawable.ic_btn_daikao); } } } } return getResources().getDrawable(R.drawable.ic_btn_daikao); } private void showChangKaoOrLukao(int exam_type){ if (exam_type >= ExamPlatformData.EXAM_TYPE_ChangKAO && exam_type>() { @Override public void onChanged(List routeBeans) { mRouteBeans.clear(); if (routeBeans.size()>0){ for (int i = 0; i < routeBeans.size(); i++) { if (routeBeans.get(i).getCurrentCollectFlag()==1){ currRouteBean = routeBeans.get(i); routeCollectController.checkWetherRoadIn(); ExamPlatformData.getInstance().setRouteCollectLineName(currRouteBean.getRouteName()); stringBuilder.delete(0,stringBuilder.length()); stringBuilder.append("当前采集线路名称:"+currRouteBean.getRouteName()); stringBuilder.append("\n"); tv_route_collect_info.setText(stringBuilder.toString()); break; } } mRouteBeans.addAll(routeBeans); } } }); failedProjViewModel.getFailedProjects(Constant.TEST_STU_ID).observe(this, new Observer>() { @Override public void onChanged(List failedProj_selects) { if (failedProj_selects != null && failedProj_selects.size()>0){ item_id = 0; currTotalScore = 100; mArrayList.clear(); item_conents.clear(); for (FailedProj_select f : failedProj_selects) { item_id += f.getScore_deducting(); Log.i(TAG, "onChanged: " + f.toString()); mArrayList.add(new ScoreBean(f.getScore_deducting(), f.getItem_content(), f.getDeducting_reason(),f.getUtc(),f.getEmp_id())); item_conents.add(f.getItem_content()); Collections.sort(mArrayList); mScoreAdapter.addDatas(mArrayList); } MyLog.i("没扣分之前得分:"+currTotalScore); currTotalScore -=item_id; MyLog.i("当前得分:"+currTotalScore); if (currTotalScore < Constant.PASSING_SCORE){ MyLog.i("低于80,不合格"+currTotalScore); } if (currTotalScore<0){ ExamPlatformData.getInstance().setCurTotalScore(0); }else{ ExamPlatformData.getInstance().setCurTotalScore(currTotalScore); } MyLog.i("监测到有失败项目加入,通知UI更新颜色"); mHandler.obtainMessage(ADD_DATA).sendToTarget(); }else{ MyLog.i(TAG,"失败项目数据表被清空更新UI"); item_id = 0; mArrayList.clear(); item_conents.clear(); Collections.sort(mArrayList); mScoreAdapter.addDatas(mArrayList); mHandler.obtainMessage(ADD_DATA).sendToTarget(); } } }); examStatusViewModel = ViewModelProviders.of(this).get(ExamStatusViewModel.class); examStatusViewModel.getExamStatus().observe(this, new Observer>() { @Override public void onChanged(List examStatus) { MyLog.i(TAG, "ExamStatus onChanged: "); if (examStatus!=null && examStatus.size()>0){ showChangKaoOrLukao(examStatus.get(0).getStartExam()); MyLog.i(TAG,"考试状态更新"+examStatus.get(0).getStartExam()); examStatusList.clear(); examStatusList.addAll(examStatus); mHandler.obtainMessage(ADD_DATA).sendToTarget(); exam_type = examStatus.get(0).getStartExam(); if (exam_type != Constant.NONE_BEEN_START_EXAM){ if (ROUTE_COLLECT == exam_type){ btn_start_exam.setText("结束采集"); routeCollectController.startRoadListener(); }else{ btn_start_exam.setText("结束训练"); } }else{ btn_start_exam.setText("开始训练"); } } } }); wokViewModel = ViewModelProviders.of(this).get(WokViewModel.class); wokViewModel.getStudents().observe(this, new Observer>() { @Override public void onChanged(List students) { for (Student student : students) { MyLog.i(TAG, "onChanged: " + student.toString()); if (ExamPlatformData.getInstance().getSign_mode()==ExamPlatformData.SIGN_MODE_TRAIN){ if (!TextUtils.isEmpty(student.getName())&&student.getStu_id()==ExamPlatformData.STU_ID){ tv_name.setText(getNameColor(student.getName())); ExamPlatformData.getInstance().setId(student.getID()); tv_start_time.setText(getString(R.string.begin_time)+Utils.formatTimeYYMMDDHHmmSS(student.getBegin_time())); }else if (!TextUtils.isEmpty(student.getName())&&student.getStu_id()==ExamPlatformData.COACH_ID){ ExamPlatformData.getInstance().setCoachID(student.getID()); tv_coach_name.setText(getNameColor(student.getName())); } } } } }); return view; } private void initView(View view) { tv_route_collect_info = view.findViewById(R.id.tv_route_info); // routeCollectController = new RouteCollectController(this); routeCollectController = RouteCollectController.getInstance(); routeCollectController.setRouteCollectController(this); items = view.findViewById(R.id.items); items_score=view.findViewById(R.id.items_score); route_collect=view.findViewById(R.id.route_collect); 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); } btn_ids.add(R.id.btn_1); btn_ids.add(R.id.btn_2); btn_ids.add(R.id.btn_3); btn_ids.add(R.id.btn_4); btn_ids.add(R.id.btn_5); btn_ids.add(R.id.btn_6); btn_ids.add(R.id.btn_7); btn_ids.add(R.id.btn_8); btn_ids.add(R.id.btn_9); btn_ids.add(R.id.btn_10); routeCollect_btn_ids.put(getResources().getString(R.string.pull_over),R.id.btn_route_1); routeCollect_btn_ids.put(getResources().getString(R.string.add_subtract),R.id.btn_route_2); routeCollect_btn_ids.put(getResources().getString(R.string.turn_around),R.id.btn_route_3); routeCollect_btn_ids.put(getResources().getString(R.string.by_crossing),R.id.btn_route_4); routeCollect_btn_ids.put(getResources().getString(R.string.lane_change),R.id.btn_route_5); routeCollect_btn_ids.put(getResources().getString(R.string.side_by_side),R.id.btn_route_6); routeCollect_btn_ids.put(getResources().getString(R.string.over_take),R.id.btn_route_7); routeCollect_btn_ids.put(getResources().getString(R.string.school_area),R.id.btn_route_8); routeCollect_btn_ids.put(getResources().getString(R.string.bus_area),R.id.btn_route_9); routeCollect_btn_ids.put(getResources().getString(R.string.junction_left),R.id.btn_route_10); routeCollect_btn_ids.put(getResources().getString(R.string.junction_right),R.id.btn_route_11); routeCollect_btn_ids.put(getResources().getString(R.string.crosswalk),R.id.btn_route_12); routeCollect_btn_ids.put(getResources().getString(R.string.straight_line),R.id.btn_route_13); Iterator> iterator = routeCollect_btn_ids.entrySet().iterator(); while (iterator.hasNext()){ Map.Entry next = iterator.next(); int viewId = getResources().getIdentifier(String.valueOf( next.getValue()),"id",_mActivity.getPackageName()); ((Button) view.findViewById(viewId)).setOnClickListener(this); } av_curve = view.findViewById(R.id.av3); av_park = view.findViewById(R.id.av2); av_podao = view.findViewById(R.id.av1); av_zhijiao = view.findViewById(R.id.av4); houseView = view.findViewById(R.id.hv); tv_name = view.findViewById(R.id.tv_name); tv_coach_name = view.findViewById(R.id.tv_coach_name); tv_start_time = view.findViewById(R.id.tv_start_time); iv_head = view.findViewById(R.id.iv_head); iv_head.setOnClickListener(this); iv_coach_head = view.findViewById(R.id.iv_coach_head); iv_coach_head.setOnClickListener(this); tv_speed = view.findViewById(R.id.tv_speed); tv_total_score = view.findViewById(R.id.tv_total_score); tv_speed.setText(getResources().getString(R.string.speed,speed)); mListView = view.findViewById(R.id.lv); mListView.setFocusable(false); mListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: mListView.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mListView.getParent().requestDisallowInterceptTouchEvent(false); break; } return false; } }); view.findViewById(R.id.view_map).setOnClickListener(this); mScoreAdapter = new ScoreAdapter(_mActivity); mListView.setAdapter(mScoreAdapter); btn_start_exam = view.findViewById(R.id.btn_start); btn_start_exam.setText("开始训练"); btn_start_exam.setOnClickListener(this); tv_stop = view.findViewById(R.id.tv_stop); tv_stop.setText("结束训练"); tv_stop.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_start: // //TODO 发送JKMessage0202 给平台,开始考试 if (btn_start_exam.getText().toString().equalsIgnoreCase("开始训练")){ SelectDialogThree selectDialog = SelectDialogThree.newInstance("场地训练","道路训练","道路训练(不含灯光)","线路采集"); selectDialog.setSelectedListener((int res)->{ if (res != SelectDialog.SELECT_NONE){ if (res== SelectDialogThree.FIRST){ sendJK0202(2); }else if (res== SelectDialogThree.SECOND){ sendJK0202(3); }else if (res == SelectDialogThree.THIRD){ sendJK0202(4); }else{ MyInputDialog myDialog = MyInputDialog.Companion.newInstance("您将退出系统,请确认数据已保存"); myDialog.show(getFragmentManager(),"MyInputDialog"); myDialog.setOnClick(new MyInputDialog.MyOnClickListener() { @Override public void onSure(@NotNull String string) { //输入线路名称之后 点击确定才能认为是开始采集 boolean flag = false;//标记是否有重名的线路,如果有则为true for (RouteBean bean:mRouteBeans){ if (string.equalsIgnoreCase(bean.getRouteName())){ //有重名的线路,提示用户并不开启线路采集 Toast.makeText(_mActivity, "继续采集"+bean.getRouteName(), Toast.LENGTH_SHORT).show(); routeLineViewModel.updateCurrCollectFlag(string); flag = true; break; } } ; Toast.makeText(_mActivity, "线路采集", Toast.LENGTH_SHORT).show(); ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.ROUTE_MODE); exam_type = 5; sendExamJson(1,exam_type); examStatusViewModel.updateStartExam(exam_type); items.setVisibility(View.GONE); items_score.setVisibility(View.GONE); route_collect.setVisibility(View.VISIBLE); if (!flag){ RouteBean routeBean = new RouteBean(); routeBean.setRouteName(string); routeBean.setCurrentCollectFlag(1); ExamPlatformData.getInstance().setRouteCollectLineName(string); routeLineViewModel.insertRouteBean(routeBean); } } @Override public void onCancle() { } }); } } }); selectDialog.show(getFragmentManager(),"selectdialog"); }else{ if (exam_type == ROUTE_COLLECT){ Toast.makeText(_mActivity, "结束采集", Toast.LENGTH_SHORT).show(); routeLineViewModel.updateCurrCollectFlag(""); routeCollectController.endRoadListener(); exam_type = 0; examStatusViewModel.updateStartExam(exam_type); items.setVisibility(View.VISIBLE); items_score.setVisibility(View.VISIBLE); route_collect.setVisibility(View.GONE); stopRouteCollect(); }else{ stopExam(); } } break; case R.id.view_map: String url = getArcGisUrl(ExamPlatformData.getInstance().getExamType()); MyLog.i(TAG,"map head arcgis url="+url); startArcGisMapFragment(url); break; case R.id.iv_head: MyLog.i(TAG,"学员签到"); if (ExamPlatformData.getInstance().getSign_mode() == ExamPlatformData.SIGN_MODE_EXAM){ Toast.makeText(_mActivity, "您已经在\"联网考试\"页面下签到", Toast.LENGTH_SHORT).show(); return; } if (ExamPlatformData.getInstance().IsStuSign()){ ExamPlatformData.getInstance().setStuSign(false); qrcode(1,false); }else{ ExamPlatformData.getInstance().setStuSign(true); qrcode(1,true); ExamPlatformData.getInstance().setSingnMode(ExamPlatformData.SIGN_MODE_TRAIN); } break; case R.id.iv_coach_head: MyLog.i(PlatFormConstant.HTTPTAG,"教练签到"); if (ExamPlatformData.getInstance().getSign_mode() == ExamPlatformData.SIGN_MODE_EXAM){ Toast.makeText(_mActivity, "您已经在\"联网考试\"页面下签到", Toast.LENGTH_SHORT).show(); return; } if (ExamPlatformData.getInstance().IsCoachSign()){ ExamPlatformData.getInstance().setCoachSign(false); qrcode(0,false); }else{ ExamPlatformData.getInstance().setCoachSign(true); qrcode(0,true); ExamPlatformData.getInstance().setSingnMode(ExamPlatformData.SIGN_MODE_TRAIN); } break; case R.id.btn_route_1: case R.id.btn_route_2: case R.id.btn_route_3: case R.id.btn_route_4: case R.id.btn_route_5: case R.id.btn_route_6: case R.id.btn_route_7: case R.id.btn_route_8: case R.id.btn_route_9: case R.id.btn_route_10: case R.id.btn_route_11: case R.id.btn_route_12: case R.id.btn_route_13: Iterator> iterator = routeCollect_btn_ids.entrySet().iterator(); while (iterator.hasNext()){ Map.Entry next = iterator.next(); if (next.getValue()== v.getId()){ routeCollectController.startCollect(); switch (next.getKey()){ case "超车": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_OVERTAKE); break; case "变更车道": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_CHANGE_LANE); break; case "直线行驶": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_STRAIGHT); break; case "加减档": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_OPERATE_GEAR); break; case "靠边停车": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_PARK_SIDE); break; case "通过人行横道": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_CROSS_WALK); break; case "通过学校区域": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_SCHOOL_AREA); break; case "通过公共汽车站": ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_BUS_AREA); break; } stringBuilder.append("当前采集项目:"+next.getKey()); stringBuilder.append("\n"); Toast.makeText(_mActivity, String.format("点击了%s",next.getKey()), Toast.LENGTH_SHORT).show(); break; } } break; } } private void stopRouteCollect() { //设置模式为NONE 0 ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.MODE_NONE); ExamPlatformData.getInstance().getTTS().speak("结束采集"); sendExamJson(0,0); } private void startArcGisMapFragment(String url) { if (url==null){ url =""; } ArcGisMapFragment jiaXiaoFragment = findFragment(ArcGisMapFragment.class); if (jiaXiaoFragment == null) { jiaXiaoFragment = (ArcGisMapFragment) ArcGisMapFragment.newInstance(url); } start(jiaXiaoFragment); // }else{ // Toast.makeText(_mActivity, "错误:ArcGIS URL 为空!", Toast.LENGTH_SHORT).show(); // // MapFragment jiaXiaoFragment = findFragment(MapFragment.class); // if (jiaXiaoFragment == null) { // jiaXiaoFragment = (MapFragment) MapFragment.newInstance(); // } // start(jiaXiaoFragment); // } } private String getArcGisUrl(int examType) { MapInfoHead mapInfoHead; HashMap mapInfoHeads = ExamPlatformData.getInstance().getMapInfoHeads(); if (mapInfoHeads == null){ return null; } if (examType>ExamPlatformData.EXAM_TYPE_ChangKAO){ mapInfoHead= mapInfoHeads.get(BaseDataUIBean.TYPE_.road); }else{ mapInfoHead= mapInfoHeads.get(BaseDataUIBean.TYPE_.yard); } if (mapInfoHead != null){ return mapInfoHead.getArcgis_url(); } return null; } private void qrcode(int type,boolean isSign) { content = "87,"+String.valueOf(type)+ ","+ExamPlatformData.getInstance().getPhone() +(isSign?",signin":",signout"); Log.i(TAG,String.format("二维码内容:%s",content)); byte[] bytes = Utils.qrencrypt(content.getBytes(Charset.forName("utf-8")),"safeluck"); String str = Base64.encodeToString(bytes,Base64.DEFAULT); QRCodeDialog qrCodeDialog = QRCodeDialog.newInstance(str); qrCodeDialog.show(getFragmentManager(),"qrdialog" ); } private void sendJK0202(int type) { exam_type = type; if (type==3|| type==4){ sendRouteLine(); }else{ changeUi(type); } } private void changeUi(int type) { //隐藏采集项目 items_score.setVisibility(View.VISIBLE); items.setVisibility(View.VISIBLE); route_collect.setVisibility(View.GONE); MyLog.i(TAG,String.format("根据type=%d,来调整ui",exam_type)); ExamPlatformData.getInstance().setExamType(exam_type); ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.TRAINING_MODE); examStatusViewModel.updateStartExam(exam_type); ExamPlatformData.getInstance().getTTS().speak("开始训练"); sendMessage(); } private void sendMessage() { sendExamJson(1,exam_type); final JKMessage0202 jkMessage0202 = new JKMessage0202(); Date date = new Date(); wokViewModel.updateBeginTime(date.getTime()); jkMessage0202.timeBCD = date; ExamPlatformData.getInstance().setExam_id(Utils.parseUnsignedInt(String.valueOf(date.getTime()/1000),10)); jkMessage0202.stu_id = ExamPlatformData.getInstance().getID(); jkMessage0202.coach_id = ExamPlatformData.getInstance().getCoachID(); jkMessage0202.exam_id = ExamPlatformData.getInstance().getExam_id(); if (exam_type > ExamPlatformData.EXAM_TYPE_ChangKAO){ jkMessage0202.curr_exam = 1;// 跟移动站服务定义的场考是2 ,平台是0 ; 移动站路考是3 ,平台是1 }else{ jkMessage0202.curr_exam = 0;// 跟移动站服务定义的场考是2 ,平台是0 ; 移动站路考是3 ,平台是1 } jkMessage0202.mode = ExamPlatformData.getInstance().getTrainingMode()==ExamPlatformData.TRAINING_MODE?1:0; MessageProcessor.getInstance().sendMessage(jkMessage0202); } private void sendRouteLine() { SelectMutliDialog selectMutliDialog = SelectMutliDialog.newInstance(mRouteBeans); selectMutliDialog.show(getFragmentManager(),"multidialog"); selectMutliDialog.setSelectedListener(new SelectMutliDialog.OnSelectedListener() { @Override public void makeYourChoice(int res) { List crossingActiveBeans = new ArrayList<>(); List triggerLineBeans = new ArrayList<>(); RemoteRouteCollect remoteRouteCollect = new RemoteRouteCollect(); RouteCollect routeCollect = new RouteCollect(); List routeCollects = new ArrayList<>(); int id = res; CThreadPoolExecutor.runInBackground(new Runnable() { @Override public void run() { for (RouteBean bean:mRouteBeans){ if (id==bean.getId()){ ExamPlatformData.getInstance().setExamRoute(id); routeCollect.setName(bean.getRouteName()); List routeTriggerLines = WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getRouteTriggerLineDao().getAllRouteTriggerLine(id); List routeCrosses = WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getRouteCrooDao().getAllRouteCross(id); for (RouteTriggerLine line:routeTriggerLines){ List xy = new ArrayList<>(); RouteCollect.TriggerLineBean triggerLineBean = new RouteCollect.TriggerLineBean(); int road = line.getRoad(); int type = line.getType(); double x = line.getX(); double y = line.getY(); Log.i(TAG,String.format("x=%f,y=%f",x,y)); Log.i(TAG, "before add"+FileUtil.ListToString(xy)); xy.clear(); xy.add(x); xy.add(y); Log.i(TAG, FileUtil.ListToString(xy)); triggerLineBean.setRoad(road); triggerLineBean.setType(type); triggerLineBean.setX_y(xy); triggerLineBeans.add(triggerLineBean); } routeCollect.setTrigger_line(triggerLineBeans); for (RouteCross routeCross:routeCrosses){ int idx = routeCross.getIdx(); int road = routeCross.getRoad(); int active = routeCross.getActive(); RouteCollect.CrossingActiveBean crossingActiveBean = new RouteCollect.CrossingActiveBean(); crossingActiveBean.setActive(active); crossingActiveBean.setIdx(idx); crossingActiveBean.setRoad(road); crossingActiveBeans.add(crossingActiveBean); } routeCollect.setCrossing_active(crossingActiveBeans); routeCollects.add(routeCollect); remoteRouteCollect.setScheme(routeCollects); String str = new Gson().toJson(remoteRouteCollect); Log.i(TAG,"json====="+str); AYSdk.getInstance().sendCmd(0x8017,str); changeUi(exam_type); break; } } } }); } }); } private void sendExamJson(int i,int type) { try { JSONObject jsonObject = new JSONObject(); jsonObject.put("exam", i); jsonObject.put("type", type); String examJson = jsonObject.toString(); Log.i(TAG, "onClick: " + examJson); AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS, examJson); } catch (JSONException e) { e.printStackTrace(); } } private void stopExam() { MyLog.i(TAG,"结束训练"); JKMessage0204 jkMessage0204 = new JKMessage0204(); jkMessage0204.timeBCD = new Date(); jkMessage0204.score = currTotalScore<0?0:currTotalScore; jkMessage0204.stop = JKMessage0204.SUCC_STOP; jkMessage0204.exam_id = ExamPlatformData.getInstance().getExam_id(); MessageProcessor.getInstance().sendMessage(jkMessage0204); //设置模式为NONE 0 ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.MODE_NONE); //恢复初始数据exam_status表 examStatusViewModel.deleteAll(); examStatusViewModel.updateItemExamResult(1, safeluck.drive.evaluation.DB.Constant.EXAM_STATUS_MAP_ID); examStatusViewModel.updateStartExam(0); examStatusViewModel.updateExamStatus(2, safeluck.drive.evaluation.DB.Constant.EXAM_STATUS_MAP_ID); item_id = 0; currTotalScore = 100; failedProjViewModel.deleteAll(); setTotalScoreText(); ExamPlatformData.getInstance().getTTS().speak("结束训练"); examStatusViewModel.updateStartExam(Constant.NONE_BEEN_START_EXAM); sendExamJson(0,0);//结束考试 exstart=0 } private void setTotalScoreText() { String totalstr=String.format(getString(R.string.total_score),currTotalScore); SpannableString msp = new SpannableString(totalstr); msp.setSpan(new ForegroundColorSpan(Color.parseColor("#A1A1A3")),totalstr.length()-1,totalstr.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); msp.setSpan(new AbsoluteSizeSpan(13),totalstr.length()-1,totalstr.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tv_total_score.setText(msp); } private ICEventListener icEventListener = new ICEventListener() { @Override public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { if (msgCode == Constant.IC_ID){ icson = (String)obj; mHandler.obtainMessage(msgCode).sendToTarget(); }else{ speed = (double)obj; mHandler.obtainMessage(SPEED_DATA).sendToTarget(); } } }; @Override public void onAttach(Context context) { super.onAttach(context); CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_SPEED_TOPIC); } @Override public void onDetach() { super.onDetach(); Log.i(TAG,"onDetach"); CEventCenter.onBindEvent(false,icEventListener,Constant.BIND_SPEED_TOPIC); routeCollectController.endRoadListener(); } @Override public void onDestroyView() { super.onDestroyView(); Log.i(TAG,"onDestroyView"); ((MainActivity)_mActivity).viewtitle.setVisibility(View.GONE); ((MainActivity)_mActivity).btn_return.setVisibility(View.GONE); } private SpannableString getNameColor(String str) { SpannableString spannableString = new SpannableString(str); spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#60FFFF")),0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; } @Override public void beginCollectView() { Log.i(TAG,"BIND_RTK_INFO_MAP"); // CThreadPoolExecutor.runOnMainThread(()->{ // StatusDialog.with(_mActivity).setType(StatusDialog.Type.PROGRESS).setCancelable(true).show(); // }); } @Override public void endCollectView() { Log.i(TAG,"endCollectView"); CThreadPoolExecutor.runOnMainThread(()->{ // StatusDialog.with(_mActivity).setType(StatusDialog.Type.PROGRESS).dismiss(); }); routeCollectController.endCollect(); } @Override public void routeItem(CollectPointResult collectPointResult) { Log.i(TAG,String.format("x=%f,y=%f",collectPointResult.getX(),collectPointResult.getY())); RoadInfo roadInfo = ExamPlatformData.getInstance().getRouteCollectRoadInfo(); if (roadInfo != null && roadInfo.getStatus()==1){ Log.i(TAG,"在某个路里面"+roadInfo.getRoad_id()); stringBuilder.append(String.format("在%d号路里面",roadInfo.getRoad_id())); stringBuilder.append("\n"); routeTriggerLine.setX(collectPointResult.getX()); routeTriggerLine.setY(collectPointResult.getY()); routeTriggerLine.setType(ExamPlatformData.getInstance().getCurrRouteItem()); routeTriggerLine.setRoad(roadInfo.getRoad_id()); routeTriggerLine.setRouteline_id(currRouteBean.getId()); routeLineViewModel.insertRouteTriggerLine(routeTriggerLine); } stringBuilder.append(String.format("x=%f,y=%f",collectPointResult.getX(),collectPointResult.getY())); stringBuilder.append("\n"); showRouteCollectInfoText(); } private void showRouteCollectInfoText(){ CThreadPoolExecutor.runOnMainThread(new Runnable() { @Override public void run() { tv_route_collect_info.setText(stringBuilder.toString()); } }); } @Override public void roadinfo(RoadInfo roadInfo) { Log.i(TAG,String.format("道路信息%s",roadInfo.toString())); //道路信息是没有进行本地保存的,如果崩溃的话,就有问题 stringBuilder.append(String.format("道路信息%s",roadInfo.toString())); stringBuilder.append("\n"); ExamPlatformData.getInstance().getTTS().speak(String.format("%s%d路",roadInfo.getStatus()==1?"进入":"退出", roadInfo.getRoad_id())); showRouteCollectInfoText(); } SelectDialogThree roadCrossDialog; //标记是否已经插入了该路口方向 已经插入=true private boolean hasInsertRoadCrossDirect = false; @Override public void roadcrossInfo(RoadCrossInfo roadCrossInfo) { Log.i(TAG,String.format("道路路口信息%s",roadCrossInfo.toString())); stringBuilder.append(String.format("道路路口信息%s",roadCrossInfo.toString())); stringBuilder.append("\n"); showRouteCollectInfoText(); CThreadPoolExecutor.runInBackground(new Runnable() { @Override public void run() { ExamPlatformData.getInstance().getTTS().speak(String.format("%s%d号路第%d个路口",roadCrossInfo.getStatus()==1?"进入":"退出", roadCrossInfo.getRoad_id(),roadCrossInfo.getCrossing_index()+1)); if (roadCrossInfo.getStatus() == 1){ List roadCrosses = routeLineViewModel.getRoadCrosses(currRouteBean.getId()); routeCross = new RouteCross(); routeCross.setRouteline_id(currRouteBean.getId()); routeCross.setRoad(roadCrossInfo.getRoad_id()); routeCross.setIdx(roadCrossInfo.getCrossing_index()); CThreadPoolExecutor.runOnMainThread(new Runnable() { @Override public void run() { for (RouteCross routeCross:roadCrosses){ if (routeCross.getIdx()==roadCrossInfo.getCrossing_index()&&routeCross.getRoad()==roadCrossInfo.getRoad_id()){ Log.i(TAG,"该路口已经选择了行驶方向,确定要覆盖以前?"); MyDialog myDialog = MyDialog.Companion.newInstance("该路口已经选择了行驶方向,确定要覆盖以前?"); myDialog.setCancelable(false); hasInsertRoadCrossDirect = true; myDialog.setOnClick(new MyDialog.MyOnClickListener() { @Override public void onSure() { selectRoadCrossDirect(routeCross); } @Override public void onCancle() { hasInsertRoadCrossDirect = false; } }); myDialog.show(getFragmentManager(),"tarindialog"); break; } } if (!hasInsertRoadCrossDirect){ selectRoadCrossDirect(routeCross); } } }); }else{ if (roadCrossDialog != null) roadCrossDialog.dismiss(); } } }); } private void selectRoadCrossDirect(RouteCross routeCross) { roadCrossDialog = SelectDialogThree.newInstance("路口直行","路口左转弯","路口右转弯","路口掉头"); roadCrossDialog.show(getFragmentManager(),"aaa"); roadCrossDialog.setSelectedListener(new SelectDialogThree.OnSelectedListener() { @Override public void makeYourChoice(int res) { switch (res){ case 0: //直行 routeCross.setActive(1); break; case 1: //左转弯 routeCross.setActive(2); break; case 2: //右转弯 routeCross.setActive(4); break; case 3: //调头 routeCross.setActive(8); break; } if (res != SelectDialogThree.SELECT_NONE){ if (!hasInsertRoadCrossDirect){ routeLineViewModel.insertRouteCross(routeCross); }else{ hasInsertRoadCrossDirect = false; routeLineViewModel.updateRouteCrossActive(currRouteBean.getId(),routeCross.getRoad(),routeCross.getIdx(),routeCross.getActive()); } }else{ Log.i(TAG,"在路口没有做出选择"); } } }); } }