yy1717
2020-03-02 d534b3b9b056fff3bcc887d72ed11f4256cdd2fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package safeluck.drive.evaluation.fragment;
 
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
 
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import androidx.annotation.NonNull;
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
 * Created by lzw on 2019/3/22. 11:07:11
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class InspectSignalFragment extends SupportFragment {
 
    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();
    }
 
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 
        View view = inflater.inflate(R.layout.layout_check_signal,container,false);
        initView(view);
        return view;
    }
 
    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() {
            @Override
            public void onClick(View v) {
                _mActivity.onBackPressed();
            }
        });
        toolbar.setTitle("查看车载信号输入");
        textView_turnLight = view.findViewById(R.id.tv_fog_lamp);
        final Drawable left = getResources().getDrawable(R.drawable.green_light,null);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                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);
    }
}