| | |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.lifecycle.ViewModelProviders; |
| | | import androidx.work.OneTimeWorkRequest; |
| | | import androidx.work.PeriodicWorkRequest; |
| | | import androidx.work.WorkInfo; |
| | | import androidx.work.WorkManager; |
| | | |
| | | import com.anyun.exam.lib.AYSdk; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.Constant; |
| | |
| | | import safeluck.drive.evaluation.platformMessage.JKMessage0203; |
| | | import safeluck.drive.evaluation.platformMessage.JKMessage0204; |
| | | import safeluck.drive.evaluation.util.Utils; |
| | | import safeluck.drive.evaluation.worker.TimeWorker; |
| | | |
| | | import static androidx.work.PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS; |
| | | |
| | | /** |
| | | * 联网训练UI |
| | |
| | | private int item_id;//扣分分数总和 |
| | | private ExamStatusViewModel examStatusViewModel; |
| | | private static final int ADD_DATA = 1; |
| | | private TextView tv_speed,tv_total_score,tv_sat_num,tv_name,tv_id,tv_work_platform; |
| | | private TextView tv_speed,tv_total_score,tv_sat_num,tv_name,tv_id,tv_work_platform,tv_network_time; |
| | | private double speed=0.0; |
| | | private ImageView iv_rtk_status,iv_head; |
| | | |
| | |
| | | @Override |
| | | public boolean handleMessage(Message msg) { |
| | | if (msg.what == ADD_DATA){ |
| | | MyLog.i("handler add_data totalScore="+currTotalScore); |
| | | tv_total_score.setText(getResources().getString(R.string.total_score,currTotalScore)); |
| | | houseView.setColor(whatPaintColor(examStatusList.get(0))); |
| | | av_podao.setColor(whatPaintColor(examStatusList.get(1))); |
| | | av_park.setColor(whatPaintColor(examStatusList.get(2))); |
| | | av_curve.setColor(whatPaintColor(examStatusList.get(3))); |
| | | av_zhijiao.setColor(whatPaintColor(examStatusList.get(4))); |
| | | houseView.setColor(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_REVERSE));//倒车入库 type =1 |
| | | av_podao.setColor(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_RAMP)); |
| | | av_park.setColor(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_PARK)); |
| | | av_curve.setColor(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_CURVE)); |
| | | av_zhijiao.setColor(aaa(safeluck.drive.evaluation.DB.Constant.EXAM_MAP_TYPE_ANGLE)); |
| | | } |
| | | if (msg.what == SPEED_DATA){ |
| | | tv_speed.setText(getResources().getString(R.string.speed,speed)); |
| | |
| | | if (result == 0) { |
| | | JKMessage0201 jkMessage0201 = new JKMessage0201(); |
| | | jkMessage0201.phone = ExamPlatformData.getInstance().getPhone(); |
| | | jkMessage0201.currentExam = 0; |
| | | if (exam_type==Constant.Chang_di){ |
| | | jkMessage0201.currentExam = 0; |
| | | }else{ |
| | | jkMessage0201.currentExam = 1; |
| | | } |
| | | |
| | | jkMessage0201.id = icStr; |
| | | MessageProcessor.getInstance().sendMessage(jkMessage0201); |
| | | } |
| | |
| | | return false; |
| | | } |
| | | }); |
| | | |
| | | private int 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().getColor(R.color.colorAccent); |
| | | }else{ |
| | | MyLog.i("进入考场,type="+type); |
| | | return getResources().getColor(R.color.pink); |
| | | } |
| | | |
| | | |
| | | }else if (examStatus.getEnter() == safeluck.drive.evaluation.DB.Constant.FINISH_ITEM){ |
| | | |
| | | if (examStatusList.get(0).getStartExam()==Constant.NONE_BEEN_START_EXAM){ |
| | | return getResources().getColor(R.color.examing); |
| | | } |
| | | |
| | | switch (type) { |
| | | case 1://倒库 |
| | | if (item_conents.contains("倒车入库")) { |
| | | MyLog.i("该项考试失败,type="+type); |
| | | |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | ExamPlatformData.getInstance().getTTS().speak("倒车入库合格"); |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 2: |
| | | if (item_conents.contains("坡道定点停车和起步")) { |
| | | MyLog.i("该项考试失败,type="+type); |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | ExamPlatformData.getInstance().getTTS().speak("坡道定点停车和起步合格"); |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 3: |
| | | if (item_conents.contains("侧方停车")) { |
| | | MyLog.i("该项考试失败,type="+type); |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | ExamPlatformData.getInstance().getTTS().speak("侧方停车合格"); |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 4: |
| | | if (item_conents.contains("曲线行驶")) { |
| | | MyLog.i("该项考试失败,type="+type); |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | ExamPlatformData.getInstance().getTTS().speak("曲线行驶合格"); |
| | | examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 5: |
| | | if (item_conents.contains("直角转弯")) { |
| | | MyLog.i("该项考试失败,type="+type); |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | MyLog.i("该项考试成功,type="+type); |
| | | ExamPlatformData.getInstance().getTTS().speak("直角转弯合格"); |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | }else{ |
| | | return getResources().getColor(R.color.examing); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return getResources().getColor(R.color.examing); |
| | | } |
| | | |
| | | @Nullable |
| | | @Override |
| | |
| | | if (failedProj_selects != null && failedProj_selects.size()>0){ |
| | | |
| | | item_id = 0; |
| | | currTotalScore = 100; |
| | | mArrayList.clear(); |
| | | item_conents.clear(); |
| | | for (FailedProj_select f : |
| | |
| | | } |
| | | //TODO 发送JKMessage0203 给平台,这儿有点复杂,看怎么处理 |
| | | sendJKMessage0203(failedProj_selects); |
| | | MyLog.i("没扣分之前得分:"+currTotalScore); |
| | | currTotalScore -=item_id; |
| | | MyLog.i("当前得分:"+currTotalScore); |
| | | if (currTotalScore < Constant.PASSING_SCORE){ |
| | | MyLog.i(TAG,"低于80,不合格"+currTotalScore); |
| | | MyLog.i("低于80,不合格"+currTotalScore); |
| | | ExamPlatformData.getInstance().getTTS().speak("考试不合格"); |
| | | stopExam(); |
| | | // stopExam(); |
| | | } |
| | | MyLog.i(TAG,"监测到有失败项目加入,通知UI更新颜色"); |
| | | MyLog.i("监测到有失败项目加入,通知UI更新颜色"); |
| | | mHandler.obtainMessage(ADD_DATA).sendToTarget(); |
| | | }else{ |
| | | MyLog.i(TAG,"失败项目数据表被清空更新UI"); |
| | |
| | | failedProj_selects.get(i).getScore_deducting()+"分")); |
| | | MyLog.i("没有相同的sn,发送"+failedProj_selects.get(i).getSn()); |
| | | sns.add(failedProj_selects.get(i).getSn()); |
| | | jkMessage0203.timeBCD = failedProj_selects.get(i).getUtc(); |
| | | String utc = failedProj_selects.get(i).getUtc(); |
| | | if (!TextUtils.isEmpty(utc)&&utc.length()>12){ |
| | | utc =utc.substring(0,12); |
| | | } |
| | | jkMessage0203.timeBCD = utc ; |
| | | |
| | | jkMessage0203.fail_item_id = failedProj_selects.get(i).getEmp_id(); |
| | | jkMessage0203.fail_score = failedProj_selects.get(i).getScore_deducting(); |
| | | jkMessage0203.fail_reason = failedProj_selects.get(i).getDeducting_reason(); |
| | |
| | | switch (status) { |
| | | case 0://考试完成 |
| | | switch (map_id) { |
| | | case 863://倒库 |
| | | case 1://倒库 |
| | | if (item_conents.contains("倒车入库")) { |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | |
| | | tv_sat_num = view.findViewById(R.id.tv_sat_num); |
| | | tv_speed = view.findViewById(R.id.tv_speed); |
| | | tv_total_score = view.findViewById(R.id.tv_total_score); |
| | | tv_network_time = view.findViewById(R.id.network_time); |
| | | |
| | | |
| | | PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(TimeWorker.class,MIN_PERIODIC_INTERVAL_MILLIS, TimeUnit.MICROSECONDS).build(); |
| | | WorkManager.getInstance(getContext().getApplicationContext()).enqueue(periodicWorkRequest); |
| | | WorkManager.getInstance(getContext().getApplicationContext()).getWorkInfoByIdLiveData(periodicWorkRequest.getId()) |
| | | .observe(this, new Observer<WorkInfo>() { |
| | | @Override |
| | | public void onChanged(WorkInfo workInfo) { |
| | | if (workInfo!= null&&workInfo.getState().isFinished()){ |
| | | String time = workInfo.getOutputData().getString(Constant.TIME_MINUTE); |
| | | MyLog.i("Time="+time); |
| | | tv_network_time.setText(time); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | tv_network_time.setText(Utils.getHHmm()); |
| | | |
| | | tv_speed.setText(getResources().getString(R.string.speed,speed)); |
| | | |
| | | view.findViewById(R.id.btn_return).setOnClickListener(this); |
| | |
| | | public void onClick(View v) { |
| | | switch (v.getId()) { |
| | | case R.id.btn_start: |
| | | OneTimeWorkRequest examStatusInitWork = OneTimeWorkRequest.from(ExamStatusInitWorker.class); |
| | | WorkManager.getInstance(_mActivity).enqueue(examStatusInitWork); |
| | | item_id = 0; |
| | | currTotalScore = 100; |
| | | //TODO 发送JKMessage0202 给平台,开始考试 |
| | | final JKMessage0202 jkMessage0202 = new JKMessage0202(); |
| | | jkMessage0202.phone = ExamPlatformData.getInstance().getPhone(); |
| | |
| | | @Override |
| | | public void changKao() { |
| | | exam_type = 2; |
| | | examStatusViewModel.updateStartExam(exam_type); |
| | | sendExamJson(1,exam_type); |
| | | ExamPlatformData.getInstance().getTTS().speak("开始考试"); |
| | | jkMessage0202.curr_exam = 0; |
| | |
| | | @Override |
| | | public void luKao() { |
| | | exam_type = 3; |
| | | examStatusViewModel.updateStartExam(exam_type); |
| | | sendExamJson(1,exam_type); |
| | | if (simulateNightBean == null){ |
| | | simulateNightBean = new SimulateNightBean(); |
| | |
| | | |
| | | private void sendExamJson(int i,int type) { |
| | | try { |
| | | examStatusViewModel.updateStartExam(type); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("exam", i); |
| | | jsonObject.put("type", type); |
| | |
| | | |
| | | private void stopExam() { |
| | | MyLog.i(TAG,"结束考试"); |
| | | //清空已经存在的sns |
| | | sns.clear(); |
| | | item_id = 0; |
| | | currTotalScore = 100; |
| | | |
| | | |
| | | tv_total_score.setText(String.valueOf(currTotalScore)); |
| | | iv_head.getDrawable().setLevel(0); |
| | | OneTimeWorkRequest examStatusInitWork = OneTimeWorkRequest.from(ExamStatusInitWorker.class); |
| | | WorkManager.getInstance(_mActivity).enqueue(examStatusInitWork); |
| | | |
| | | ExamPlatformData.getInstance().getTTS().speak("结束考试"); |
| | | sendExamJson(0,exam_type); |
| | | examStatusViewModel.updateStartExam(Constant.NONE_BEEN_START_EXAM); |
| | | sendExamJson(0,0);//结束考试 exstart=0 |
| | | //TODO 发送JKMessage0204给平台 结束考试 |
| | | JKMessage0204 jkMessage0204 = new JKMessage0204(); |
| | | jkMessage0204.phone = ExamPlatformData.getInstance().getPhone(); |