lizhanwei
2020-03-02 7a621d952fb83005ce7b6db82f9b2206746562be
app/src/main/java/safeluck/drive/evaluation/fragment/InspectSignalFragment.java
@@ -5,6 +5,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -13,8 +14,13 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
import com.anyun.im_lib.util.ByteUtil;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.Constant;
@@ -22,6 +28,8 @@
import safeluck.drive.evaluation.bean.MCUInfo;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.databinding.LayoutCheckSignalBinding;
import safeluck.drive.evaluation.databinding.LayoutSignalSliceBinding;
/**
 * MyApplication2
@@ -31,20 +39,52 @@
 */
public class InspectSignalFragment extends SupportFragment {
    private static final String TAG = "InspectSignalFragment";
    private static final int  VALIAD_NUM = 1;//1高电平有效
    private TextView textView_turnLight,tv_speed,tv_engine;
    private Toolbar toolbar;
    private Gson gson= new Gson();
    private LayoutCheckSignalBinding bingding;
    private List<Integer> gpios = new ArrayList<>();
    Drawable leftGreen ;
    Drawable leftGray ;
    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() {
                    bingding.getRoot().post(new Runnable() {
                        @Override
                        public void run() {
                            tv_engine.setText(String.valueOf(mcuInfo.getEngine()));
                            tv_speed.setText(String.valueOf(mcuInfo.getSpeed()));
                            for (int i = 0; i < 16; i++) {
                                gpios.add(      ByteUtil.getBitStatus(mcuInfo.getGpio(),i));
                            }
                            bingding.tvRoateSpeed.setText(String.valueOf(mcuInfo.getEngine()));
                            bingding.tvDangweiNum.setText(String.valueOf(mcuInfo.getSpeed()));
                            bingding.inpsetSignalSlice.tvSeatBelt.setCompoundDrawablesWithIntrinsicBounds(gpios.get(0)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvTrunLeft.setCompoundDrawablesWithIntrinsicBounds(gpios.get(1)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvTurnRight.setCompoundDrawablesWithIntrinsicBounds(gpios.get(2)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvParkingBrake.setCompoundDrawablesWithIntrinsicBounds(gpios.get(3)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvFootBrake.setCompoundDrawablesWithIntrinsicBounds(gpios.get(4)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvLowLamp.setCompoundDrawablesWithIntrinsicBounds(gpios.get(5)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvHighBeam.setCompoundDrawablesWithIntrinsicBounds(gpios.get(6)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvGateLock.setCompoundDrawablesWithIntrinsicBounds(gpios.get(7)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvNullEngine.setCompoundDrawablesWithIntrinsicBounds(gpios.get(8)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvGearOne.setCompoundDrawablesWithIntrinsicBounds(gpios.get(9)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvGearTwo.setCompoundDrawablesWithIntrinsicBounds(gpios.get(10)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvGearThree.setCompoundDrawablesWithIntrinsicBounds(gpios.get(11)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvGearFour.setCompoundDrawablesWithIntrinsicBounds(gpios.get(12)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvGearFive.setCompoundDrawablesWithIntrinsicBounds(gpios.get(13)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvWindingOne.setCompoundDrawablesWithIntrinsicBounds(gpios.get(14)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                            bingding.inpsetSignalSlice.tvWindingTwo.setCompoundDrawablesWithIntrinsicBounds(gpios.get(15)==VALIAD_NUM?leftGreen:leftGray,null,null,null);
                        }
                    });
                }
@@ -60,15 +100,18 @@
    @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;
        bingding = DataBindingUtil.inflate(inflater,R.layout.layout_check_signal,container,false);
        initView();
        leftGreen = getResources().getDrawable(R.drawable.green_light,null);
        leftGray = getResources().getDrawable(R.drawable.gray_light,null);
        return bingding.getRoot();
    }
    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);
    private void initView() {
        toolbar = bingding.inpsectSignalToolbar.toolbar;
        toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp,null));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
@@ -77,14 +120,7 @@
            }
        });
        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