package safeluck.drive.evaluation.fragment; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.AlarmManagerCompat; 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 android.os.Handler; import android.os.Message; import android.os.SystemClock; import android.text.TextUtils; 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.RelativeLayout; import android.widget.TableRow; import android.widget.TextView; import android.widget.Toast; import com.anyun.exam.lib.AYSdk; import com.anyun.exam.lib.MyLog; import com.google.gson.Gson; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.Collections; 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.DB.Student; import safeluck.drive.evaluation.DB.WokViewModel; import safeluck.drive.evaluation.DB.appstatusdb.AppStatus; import safeluck.drive.evaluation.DB.appstatusdb.AppStatusViewModel; 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.adapter.ScoreAdapter; import safeluck.drive.evaluation.bean.ExamPlatformData; import safeluck.drive.evaluation.bean.ScoreBean; import safeluck.drive.evaluation.bean.SimulateNightBean; import safeluck.drive.evaluation.cEventCenter.CEventCenter; import safeluck.drive.evaluation.cEventCenter.ICEventListener; import safeluck.drive.evaluation.customview.ArrowView; import safeluck.drive.evaluation.customview.HouseView; import safeluck.drive.evaluation.customview.MyDialogFragment; import safeluck.drive.evaluation.im.MessageProcessor; import safeluck.drive.evaluation.platformMessage.JKMessage0201; import safeluck.drive.evaluation.platformMessage.JKMessage0202; import safeluck.drive.evaluation.platformMessage.JKMessage0203; import safeluck.drive.evaluation.platformMessage.JKMessage0204; import safeluck.drive.evaluation.util.Utils; import safeluck.drive.evaluation.viewmodels.TimeViewModel; import safeluck.drive.evaluation.worker.TimeWorker; import static androidx.work.PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS; /**单机训练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 { private static final String TAG = TrainFragment.class.getSimpleName(); private static final int REQUEST_CODE = 1000; private static final String ALARM_ACTION_CODE = "com.anyun.alermbroadcast"; public static SupportFragment newInstance() { return new TrainFragment(); } private RelativeLayout relativeLayout;//场考还是路考 private int exam_type = 2;//2 场地;3 道路,模拟夜考;4 道路,实际夜考; private ListView mListView; private Button btn_start_exam; private TextView tv_stop;//呼叫请求(结束考试) private Gson gson = new Gson(); private ScoreAdapter mScoreAdapter; private ArrowView av_zhijiao, av_curve, av_park, av_podao; private HouseView houseView; 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_sat_num,tv_name,tv_id,tv_work_platform,tv_network_time ,tv_qf; private double speed=0.0; private ImageView iv_rtk_status,iv_head; private int currTotalScore = 100; private List mArrayList = new ArrayList<>(); private static final int SPEED_DATA = 2; private FailedProjViewModel failedProjViewModel; String icson;//返回的ic卡信息 json private List tempQs= new ArrayList<>(); private TableRow tableRow1,tableRow2,tableRow3; private Button btn_1,btn_2; private List btn_ids = new ArrayList(); 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); tv_total_score.setText(getResources().getString(R.string.total_score,currTotalScore)); 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)); 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)).setBackgroundColor(100+i+1); } } 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 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{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过倒车入库合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("倒车入库合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } 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{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过坡道定点停车和起步合格合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("坡道定点停车和起步合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } 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{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过侧方停车合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("侧方停车合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } 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{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过曲线行驶合格"); }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{ if (examStatus.getResult() ==1){ MyLog.i("已经播放过直角转弯合格"); }else{ ExamPlatformData.getInstance().getTTS().speak("直角转弯合格"); examStatusViewModel.updateItemExamResult(1,examStatus.getMap_id()); } return getResources().getColor(R.color.train_btn_return); } } }else{ return getResources().getColor(R.color.examing); } } } } return getResources().getColor(R.color.examing); } /** * 路考项目 每个项目的颜色变化 * @param type * @return */ private int 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().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); } String ss=ExamPlatformData.getInstance().getItemStatusStr(type); if (item_conents.contains(ss)) { MyLog.i("该项考试失败,type="+type); return getResources().getColor(R.color.colorAccent); }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().getColor(R.color.train_btn_return); } }else{ return getResources().getColor(R.color.examing); } } } } return getResources().getColor(R.color.examing); } private void showChangKaoOrLukao(int exam_type){ if (exam_type > ExamPlatformData.EXAM_TYPE_ChangKAO){ //show路考 view.findViewById(R.id.lukao).setVisibility(View.VISIBLE); view.findViewById(R.id.changkao).setVisibility(View.GONE); }else{ //show场考 view.findViewById(R.id.lukao).setVisibility(View.GONE); view.findViewById(R.id.changkao).setVisibility(View.VISIBLE); } } View view; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.layout_train_fragment, container, false); initView(view); failedProjViewModel = ViewModelProviders.of(this).get(FailedProjViewModel.class); failedProjViewModel.getFailedProjectsForIII(Constant.TEST_STU_ID).observe(this, new Observer>() { @Override public void onChanged(List failedProj_selects) { if (ExamPlatformData.getInstance().getExamType()>ExamPlatformData.EXAM_TYPE_ChangKAO){ MyLog.i("现在是路考状态,监视路考数据失败项目"); 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())); item_conents.add(f.getItem_content()); Collections.reverse(mArrayList); mScoreAdapter.addDatas(mArrayList); MyLog.i("item_score="+item_id); } MyLog.i("没扣分之前得分:"+currTotalScore); currTotalScore -=item_id; MyLog.i("路考当前得分:"+currTotalScore); if (currTotalScore < Constant.PASSING_SCORE){ MyLog.i("路考低于80,不合格"+currTotalScore); } MyLog.i("路考监测到有失败项目加入,通知UI更新颜色"); mHandler.obtainMessage(ADD_DATA).sendToTarget(); }else{ MyLog.i(TAG,"路考失败项目数据表被清空更新UI"); item_id = 0; mArrayList.clear(); item_conents.clear(); Collections.reverse(mArrayList); mScoreAdapter.addDatas(mArrayList); mHandler.obtainMessage(ADD_DATA).sendToTarget(); } } } }); failedProjViewModel.getFailedProjectsForI(Constant.TEST_STU_ID).observe(this, new Observer>() { @Override public void onChanged(List failedProj_selects) { if (ExamPlatformData.getInstance().getExamType()<=ExamPlatformData.EXAM_TYPE_ChangKAO){ 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())); item_conents.add(f.getItem_content()); Collections.reverse(mArrayList); mScoreAdapter.addDatas(mArrayList); MyLog.i("item_score="+item_id); } MyLog.i("没扣分之前得分:"+currTotalScore); currTotalScore -=item_id; MyLog.i("当前得分:"+currTotalScore); if (currTotalScore < Constant.PASSING_SCORE){ MyLog.i("低于80,不合格"+currTotalScore); } MyLog.i("监测到有失败项目加入,通知UI更新颜色"); mHandler.obtainMessage(ADD_DATA).sendToTarget(); }else{ MyLog.i(TAG,"失败项目数据表被清空更新UI"); item_id = 0; mArrayList.clear(); item_conents.clear(); Collections.reverse(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) { Log.i(TAG, "ExamStatus onChanged: "); if (examStatus!=null && examStatus.size()>0){ showChangKaoOrLukao(examStatus.get(0).getStartExam()); MyLog.i(TAG,"考试状态更新"); examStatusList.clear(); examStatusList.addAll(examStatus); mHandler.obtainMessage(ADD_DATA).sendToTarget(); if (examStatus.get(0).getStartExam() != Constant.NONE_BEEN_START_EXAM){ btn_start_exam.setEnabled(false); tv_stop.setEnabled(true); }else{ btn_start_exam.setEnabled(true); tv_stop.setEnabled(false); } exam_type = examStatus.get(0).getStartExam(); } } }); WokViewModel 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 (!TextUtils.isEmpty(student.getName())){ tv_name.setText(getString(R.string.name)+student.getName()); tv_id.setText(getString(R.string.user_id)+student.getID()); ExamPlatformData.getInstance().setId(student.getID()); } } } }); AppStatusViewModel appStatusViewModel = ViewModelProviders.of(this).get(AppStatusViewModel.class); appStatusViewModel.getAppStatus().observe(this, new Observer() { @Override public void onChanged(AppStatus appStatus) { if (appStatus != null){ Log.i(TAG, "onChanged: "+appStatus.toString()); iv_rtk_status.getDrawable().setLevel(appStatus.getRtk_connect_status()); tv_work_platform.setText(getString(R.string.platform_status,ExamPlatformData.getInstance().getExamplatformStatusStr(appStatus.getWork_platform()))); tv_sat_num.setText(String.valueOf(appStatus.getSat_num()).length()==1?"0"+appStatus.getSat_num():String.valueOf(appStatus.getSat_num())); tv_qf.setText(getResources().getStringArray(R.array.qf_status)[appStatus.getQf()]); } } }); TimeViewModel timeViewModel = ViewModelProviders.of(this).get(TimeViewModel.class); timeViewModel.getLiveDataTime().observe(this, new Observer() { @Override public void onChanged(String s) { tv_network_time.setText(s); } }); return view; } private void initView(View view) { 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); view.findViewById(R.id.iv_head).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_id = view.findViewById(R.id.tv_ID); tv_work_platform = view.findViewById(R.id.platform); iv_rtk_status = view.findViewById(R.id.iv_rtk_connect); iv_rtk_status.getDrawable().setLevel(0); iv_head = view.findViewById(R.id.iv_head); tv_sat_num = view.findViewById(R.id.tv_sat_num_instatus); tv_qf = view.findViewById(R.id.tv_qf); 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); tableRow1 = view.findViewById(R.id.first); tableRow2 = view.findViewById(R.id.second); tableRow3 = view.findViewById(R.id.third); tv_network_time.setText(Utils.getHHmm()); tv_speed.setText(getResources().getString(R.string.speed,speed)); view.findViewById(R.id.btn_return).setOnClickListener(this); 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); mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item, null)); } MyDialogFragment myDialogFragment; SimulateNightBean simulateNightBean = null; @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_start: //TODO 发送JKMessage0202 给平台,开始考试 final JKMessage0202 jkMessage0202 = new JKMessage0202(); jkMessage0202.timeBCD = new Date(); jkMessage0202.ID = ExamPlatformData.getInstance().getID(); jkMessage0202.exam_id = ExamPlatformData.getInstance().getExam_id(); if (myDialogFragment == null){ myDialogFragment = new MyDialogFragment(); } myDialogFragment.show(getFragmentManager(),"dialog"); myDialogFragment.setCallback(new MyDialogFragment.Callback() { @Override public void changKao() { exam_type = 2; iv_head.getDrawable().setLevel(1); ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.TRAINING_MODE); ExamPlatformData.getInstance().setExamType(exam_type); examStatusViewModel.updateStartExam(exam_type); sendExamJson(1,exam_type); ExamPlatformData.getInstance().getTTS().speak("开始训练"); jkMessage0202.curr_exam = 0; ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.TRAINING_MODE);//设置为训练模式 MessageProcessor.getInstance().sendMessage(jkMessage0202); } @Override public void luKao() { exam_type = 3; ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.TRAINING_MODE); ExamPlatformData.getInstance().setExamType(exam_type); examStatusViewModel.updateStartExam(exam_type); sendExamJson(1,exam_type); jkMessage0202.curr_exam = 1; MessageProcessor.getInstance().sendMessage(jkMessage0202); } }); break; case R.id.tv_stop: Toast.makeText(_mActivity, "结束考试", Toast.LENGTH_SHORT).show(); stopExam(); break; case R.id.view_map: if (ExamPlatformData.getInstance().getExamType()>ExamPlatformData.EXAM_TYPE_ChangKAO){ RoadDriveMapFragmentaa mapFragment = findFragment(RoadDriveMapFragmentaa.class); MyLog.i(TAG,"查看路考地图"); if (mapFragment == null) { mapFragment = (RoadDriveMapFragmentaa) RoadDriveMapFragmentaa.newInstance(); } start(mapFragment); }else{ MapFragment mapFragment = findFragment(MapFragment.class); MyLog.i(TAG,"查看场考地图"); if (mapFragment == null) { mapFragment = (MapFragment) MapFragment.newInstance(); } start(mapFragment); } break; case R.id.btn_return: _mActivity.onBackPressed(); break; case R.id.iv_head: MyLog.i(TAG,"签到,获取身份证物理卡号"); AYSdk.getInstance().sendCmd(Constant.READ_PHYSICAL_ID,""); //TODO 获得物理卡号 发送JKMessage0201给平台,获取姓名、身份证、head_url 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,"结束训练"); //设置模式为NONE 0 ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.MODE_NONE); //恢复初始数据 OneTimeWorkRequest examStatusInitWork = OneTimeWorkRequest.from(ExamStatusInitWorker.class); WorkManager.getInstance(_mActivity).enqueue(examStatusInitWork); item_id = 0; currTotalScore = 100; failedProjViewModel.deleteAll(); tv_total_score.setText(String.valueOf(currTotalScore)); iv_head.getDrawable().setLevel(0); ExamPlatformData.getInstance().getTTS().speak("结束训练"); examStatusViewModel.updateStartExam(Constant.NONE_BEEN_START_EXAM); sendExamJson(0,0);//结束考试 exstart=0 } 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(); CEventCenter.onBindEvent(false,icEventListener,Constant.BIND_SPEED_TOPIC); } }