From 26ed6eb5e0c3a15b56f724e8890d33e3b6339882 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期五, 28 二月 2020 17:40:11 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/endian11/DriveJudge

---
 app/src/main/java/safeluck/drive/evaluation/fragment/InspectSignalFragment.java |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/InspectSignalFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/InspectSignalFragment.java
index c0dcab7..d869c7b 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/InspectSignalFragment.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/InspectSignalFragment.java
@@ -1,5 +1,6 @@
 package safeluck.drive.evaluation.fragment;
 
+import android.content.Context;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Handler;
@@ -13,8 +14,14 @@
 import androidx.annotation.Nullable;
 import androidx.appcompat.widget.Toolbar;
 
+import com.google.gson.Gson;
+
 import me.yokeyword.fragmentation.SupportFragment;
+import safeluck.drive.evaluation.Constant;
 import safeluck.drive.evaluation.R;
+import safeluck.drive.evaluation.bean.MCUInfo;
+import safeluck.drive.evaluation.cEventCenter.CEventCenter;
+import safeluck.drive.evaluation.cEventCenter.ICEventListener;
 
 /**
  * MyApplication2
@@ -24,8 +31,26 @@
  */
 public class InspectSignalFragment extends SupportFragment {
 
-    private TextView textView_turnLight;
+    private TextView textView_turnLight,tv_speed,tv_engine;
     private Toolbar toolbar;
+    private Gson gson= new Gson();
+    private ICEventListener icEventListener = new ICEventListener() {
+        @Override
+        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
+            if (msgCode==Constant.MCU_SN){
+                final MCUInfo mcuInfo = gson.fromJson((String)obj, MCUInfo.class);
+                if (mcuInfo != null){
+                    tv_engine.post(new Runnable() {
+                        @Override
+                        public void run() {
+                            tv_engine.setText(String.valueOf(mcuInfo.getEngine()));
+                            tv_speed.setText(String.valueOf(mcuInfo.getSpeed()));
+                        }
+                    });
+                }
+            }
+        }
+    };
 
     public static SupportFragment newInstance(){
         return new InspectSignalFragment();
@@ -41,6 +66,8 @@
     }
 
     private void initView(View view) {
+        tv_engine = view.findViewById(R.id.tv_roate_speed);
+        tv_speed = view.findViewById(R.id.tv_dangwei_num);
         toolbar =view.findViewById(R.id.toolbar);
         toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp,null));
         toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@@ -58,5 +85,17 @@
                 textView_turnLight.setCompoundDrawablesWithIntrinsicBounds(left,null,null,null);
             }
         },5*1000);
+
+    }
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        CEventCenter.onBindEvent(true,icEventListener, Constant.BIND_MCUINFO_TOPIC);
+    }
+
+    @Override
+    public void onDetach() {
+        super.onDetach();
+        CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_MCUINFO_TOPIC);
     }
 }

--
Gitblit v1.8.0