| | |
| | | import androidx.annotation.Nullable; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.lifecycle.ViewModelProviders; |
| | | import androidx.work.OneTimeWorkRequest; |
| | | import androidx.work.WorkManager; |
| | | |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | |
| | | import android.widget.ListView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.anyun.exam.lib.AYSdk; |
| | | import com.anyun.exam.lib.MyLog; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.EventListener; |
| | |
| | | import safeluck.drive.evaluation.Constant; |
| | | import safeluck.drive.evaluation.DB.Student; |
| | | import safeluck.drive.evaluation.DB.WokViewModel; |
| | | import safeluck.drive.evaluation.DB.exam_status.ExamStatus; |
| | | import safeluck.drive.evaluation.DB.exam_status.ExamStatusInitWorker; |
| | | 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.R; |
| | |
| | | import safeluck.drive.evaluation.bean.ScoreBean; |
| | | import safeluck.drive.evaluation.cEventCenter.CEventCenter; |
| | | import safeluck.drive.evaluation.cEventCenter.ICEventListener; |
| | | import safeluck.drive.evaluation.customview.ArrowView; |
| | | import safeluck.drive.evaluation.customview.HouseView; |
| | | |
| | | /**单机训练UI |
| | | * MyApplication2 |
| | |
| | | private ScoreAdapter mScoreAdapter; |
| | | |
| | | private int item_id;//扣分分数总和 |
| | | private ArrowView av_zhijiao, av_curve, av_park, av_podao; |
| | | private HouseView houseView; |
| | | private List<ExamStatus> examStatusList = new ArrayList<>(); |
| | | private List<String> item_conents = new ArrayList<>();//坡道定点停车和起步 |
| | | |
| | | private ExamStatusViewModel examStatusViewModel; |
| | | private static final int ADD_DATA = 1; |
| | | |
| | | private List<ScoreBean> mArrayList = new ArrayList<>(); |
| | | private View tv_stop; |
| | | |
| | | private ICEventListener eventListener =new ICEventListener() { |
| | | |
| | | private Handler mHandler = new Handler(new Handler.Callback() { |
| | | @Override |
| | | public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { |
| | | Log.i(TAG, "onCEvent: "+(String)obj); |
| | | public boolean handleMessage(Message msg) { |
| | | if (msg.what == ADD_DATA){ |
| | | 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))); |
| | | } |
| | | return false; |
| | | } |
| | | }; |
| | | }); |
| | | |
| | | |
| | | @Override |
| | | public void onAttach(Context context) { |
| | | super.onAttach(context); |
| | | CEventCenter.onBindEvent(true, eventListener,"train"); |
| | | } |
| | | |
| | | @Override |
| | | public void onDetach() { |
| | | super.onDetach(); |
| | | CEventCenter.onBindEvent(false,eventListener,"train"); |
| | | } |
| | | |
| | | public static SupportFragment newInstance(){ |
| | |
| | | failedProjViewModel.getFailedProjectsForI(Constant.TEST_STU_ID).observe(this, new Observer<List<FailedProj_select>>() { |
| | | @Override |
| | | public void onChanged(List<FailedProj_select> failedProj_selects) { |
| | | item_id = 0; |
| | | mArrayList.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())); |
| | | mScoreAdapter.addDatas(mArrayList); |
| | | if (failedProj_selects != null && failedProj_selects.size()>0){ |
| | | |
| | | item_id = 0; |
| | | 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())); |
| | | item_conents.add(f.getItem_content()); |
| | | mScoreAdapter.addDatas(mArrayList); |
| | | } |
| | | |
| | | MyLog.i(TAG,"监测到有失败项目加入,通知UI更新颜色"); |
| | | mHandler.obtainMessage(ADD_DATA).sendToTarget(); |
| | | |
| | | }else { |
| | | Log.i(TAG, "onChanged: 失败项目"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | examStatusViewModel = ViewModelProviders.of(this).get(ExamStatusViewModel.class); |
| | | examStatusViewModel.getExamStatus().observe(this, new Observer<List<ExamStatus>>() { |
| | | @Override |
| | | public void onChanged(List<ExamStatus> examStatus) { |
| | | |
| | | for (ExamStatus e : |
| | | examStatus) { |
| | | Log.i(TAG, "onChanged: e="+e.toString()); |
| | | } |
| | | Log.i(TAG, "onChanged: "); |
| | | examStatusList.clear(); |
| | | examStatusList.addAll(examStatus); |
| | | mHandler.obtainMessage(ADD_DATA).sendToTarget(); |
| | | if (examStatus.get(0).getStartExam() == Constant.HAS_BEEN_START_EXAM){ |
| | | btn_train.setEnabled(false); |
| | | tv_stop.setEnabled(true); |
| | | }else{ |
| | | btn_train.setEnabled(true); |
| | | tv_stop.setEnabled(false); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | |
| | | return view; |
| | | } |
| | | private void initView(View view) { |
| | | sendRTKConfig2RemoteService(); |
| | | |
| | | 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); |
| | | |
| | | view.findViewById(R.id.btn_return).setOnClickListener(this); |
| | | mListView = view.findViewById(R.id.lv); |
| | | tv_stop = view.findViewById(R.id.tv_stop); |
| | | tv_stop.setOnClickListener(this); |
| | | mListView.setFocusable(false);//listview不获取焦点,不然的话scrollview会顶到底部 |
| | | view.findViewById(R.id.view_map).setOnClickListener(this); |
| | | btn_train = view.findViewById(R.id.btn_start); |
| | |
| | | |
| | | } |
| | | |
| | | private void sendRTKConfig2RemoteService() { |
| | | // MyLog.d(TAG,"主动推送RTKConfig"); |
| | | // CEventCenter.dispatchEvent(Constant.BIND_RTKCONFIG_TOPIC,Constant.FETCH_RTK_PLATFORM_INFO,0,""); |
| | | } |
| | | private int whatPaintColor(ExamStatus examStat) { |
| | | int map_id = examStat.getMap_id(); |
| | | int status = examStat.getEnter(); |
| | | Log.i(TAG, "whatPaintColor: map_id="+map_id+" status="+status); |
| | | switch (status) { |
| | | case 0://考试完成 |
| | | switch (map_id) { |
| | | case 1://倒库 |
| | | if (item_conents.contains("倒车入库")) { |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 2: |
| | | if (item_conents.contains("坡道定点停车和起步")) { |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 3: |
| | | if (item_conents.contains("侧方停车")) { |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 4: |
| | | if (item_conents.contains("曲线行驶")) { |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | case 5: |
| | | if (item_conents.contains("直角转弯")) { |
| | | return getResources().getColor(R.color.colorAccent); |
| | | }else{ |
| | | return getResources().getColor(R.color.train_btn_return); |
| | | } |
| | | |
| | | } |
| | | case 1://进入考场项目 |
| | | return getResources().getColor(R.color.pink); |
| | | case 2://待考 |
| | | return getResources().getColor(R.color.examing); |
| | | } |
| | | return getResources().getColor(R.color.examing); |
| | | } |
| | | @Override |
| | | public void onClick(View v) { |
| | | switch (v.getId()){ |
| | |
| | | } |
| | | break; |
| | | case R.id.btn_start: |
| | | Toast.makeText(_mActivity, "开始巽寮", Toast.LENGTH_SHORT).show(); |
| | | examStatusViewModel.updateStartExam(Constant.HAS_BEEN_START_EXAM); |
| | | try { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("exam", 1); |
| | | String examJson = jsonObject.toString(); |
| | | Log.i(TAG, "onClick: " + examJson); |
| | | AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS, examJson); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | break; |
| | | case R.id.tv_stop: |
| | | Toast.makeText(_mActivity, "结束考试", Toast.LENGTH_SHORT).show(); |
| | | OneTimeWorkRequest examStatusInitWork = OneTimeWorkRequest.from(ExamStatusInitWorker.class); |
| | | WorkManager.getInstance(_mActivity).enqueue(examStatusInitWork); |
| | | try { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("exam", 0); |
| | | String examJson = jsonObject.toString(); |
| | | Log.i(TAG, "onClick: " + examJson); |
| | | AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS, examJson); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | break; |
| | | case R.id.btn_return: |
| | | _mActivity.onBackPressed(); |
| | | break; |
| | | } |
| | | } |