From ed0bc77b9c7168b8c3690f018da9aef230e34c61 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期二, 14 一月 2020 11:17:26 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/endian11/DriveJudge --- app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java | 156 +++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 131 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java index 6b2620d..1b59726 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java @@ -2,6 +2,8 @@ import android.os.Bundle; +import android.os.Handler; +import android.os.Message; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -17,26 +19,24 @@ import androidx.lifecycle.ViewModelProviders; import com.anyun.exam.lib.AYSdk; -import com.anyun.exam.lib.MyLog; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import me.yokeyword.fragmentation.SupportFragment; import safeluck.drive.evaluation.Constant; +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.DB.exam_status.ExamStatus; import safeluck.drive.evaluation.bean.ScoreBean; -import safeluck.drive.evaluation.cEventCenter.CEventCenter; +import safeluck.drive.evaluation.customview.ArrowView; +import safeluck.drive.evaluation.customview.HouseView; /** * 鑱旂綉璁粌UI @@ -48,11 +48,17 @@ public class NetWorkTrainFragment extends SupportFragment implements View.OnClickListener { private static final String TAG = NetWorkTrainFragment.class.getSimpleName(); - private ListView mListView ; + private ListView mListView; private Button btn_start_exam; private ScoreAdapter mScoreAdapter; + 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 int item_id;//鎵e垎鍒嗘暟鎬诲拰 + private ExamStatusViewModel examStatusViewModel; + private static final int ADD_DATA = 1; private List<ScoreBean> mArrayList = new ArrayList<>(); @@ -60,10 +66,25 @@ return new NetWorkTrainFragment(); } + private Handler mHandler = new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(Message msg) { + if (msg.what == ADD_DATA){ + av_curve.setColor(whatPaintColor(examStatusList.get(3))); + av_zhijiao.setColor(whatPaintColor(examStatusList.get(4))); + av_podao.setColor(whatPaintColor(examStatusList.get(1))); + av_park.setColor(whatPaintColor(examStatusList.get(2))); + houseView.setColor(whatPaintColor(examStatusList.get(0))); + } + return false; + } + }); + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.layout_train_fragment,container,false); + View view = inflater.inflate(R.layout.layout_train_fragment, container, false); + item_conents.add("渚ф柟鍋滆溅"); initView(view); FailedProjViewModel failedProjViewModel = ViewModelProviders.of(this).get(FailedProjViewModel.class); @@ -72,22 +93,108 @@ public void onChanged(List<FailedProj_select> failedProj_selects) { 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())); + 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); } } }); + 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(); + + } + }); + return view; } + 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); + } + private void initView(View view) { - sendRTKConfig2RemoteService(); + + av_curve = view.findViewById(R.id.av2); + av_park = view.findViewById(R.id.av3); + av_podao = view.findViewById(R.id.av4); + av_zhijiao = view.findViewById(R.id.av1); + houseView = view.findViewById(R.id.hv); +//绮夌孩鑹叉鍦ㄨ繘琛岃椤圭洰鐨勮�冭瘯 +// examStatusList.add(new ExamStatus(1, 0)); +// examStatusList.add(new ExamStatus(2, 1)); +// examStatusList.add(new ExamStatus(3, 0)); +// examStatusList.add(new ExamStatus(4, 2)); +// examStatusList.add(new ExamStatus(5, 1)); + + +// mHandler.obtainMessage(ADD_DATA).sendToTarget(); +// av_curve.setColor(whatPaintColor(examStatusList.get(3))); +// av_zhijiao.setColor(whatPaintColor(examStatusList.get(4))); +// av_podao.setColor(whatPaintColor(examStatusList.get(1))); +// av_park.setColor(whatPaintColor(examStatusList.get(2))); +// houseView.setColor(whatPaintColor(examStatusList.get(0))); + mListView = view.findViewById(R.id.lv); mListView.setFocusable(false); view.findViewById(R.id.view_map).setOnClickListener(this); @@ -96,23 +203,22 @@ btn_start_exam = view.findViewById(R.id.btn_start); btn_start_exam.setOnClickListener(this); view.findViewById(R.id.tv_stop).setOnClickListener(this); - mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item,null)); + mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item, null)); } - private void sendRTKConfig2RemoteService() { -// MyLog.d(TAG,"涓诲姩鎺ㄩ�丷TKConfig"); -// CEventCenter.dispatchEvent(Constant.BIND_RTKCONFIG_TOPIC,Constant.FETCH_RTK_PLATFORM_INFO,0,""); - } + + + @Override public void onClick(View v) { - switch (v.getId()){ + switch (v.getId()) { case R.id.btn_start: try { JSONObject jsonObject = new JSONObject(); - jsonObject.put("exam",1); + jsonObject.put("exam", 1); String examJson = jsonObject.toString(); - Log.i(TAG, "onClick: "+examJson); - AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS,examJson); + Log.i(TAG, "onClick: " + examJson); + AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS, examJson); } catch (JSONException e) { e.printStackTrace(); } @@ -121,18 +227,18 @@ Toast.makeText(_mActivity, "缁撴潫鑰冭瘯", Toast.LENGTH_SHORT).show(); try { JSONObject jsonObject = new JSONObject(); - jsonObject.put("exam",0); + jsonObject.put("exam", 0); String examJson = jsonObject.toString(); - Log.i(TAG, "onClick: "+examJson); - AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS,examJson); + Log.i(TAG, "onClick: " + examJson); + AYSdk.getInstance().sendCmd(Constant.EXAM_STATUS, examJson); } catch (JSONException e) { e.printStackTrace(); } break; case R.id.view_map: MapFragment mapFragment = findFragment(MapFragment.class); - if (mapFragment==null){ - mapFragment = (MapFragment)MapFragment.newInstance(); + if (mapFragment == null) { + mapFragment = (MapFragment) MapFragment.newInstance(); } start(mapFragment); break; -- Gitblit v1.8.0