删除MainActivity的MainViewModel示例调用;单机训练和联网考试加入speed显示;速度保留小数点后两位
7个文件已修改
84 ■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/Constant.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/MainActivity.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/app.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values/strings.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/Constant.java
@@ -65,5 +65,6 @@
    public static final int HAS_BEEN_START_EXAM = 1;
    public static final int REAL_TIME_CAR_POS = 0x000E;
    public static final String REAL_TIME_POS_CAR_TOPIC = "real_time_car_pos_topic";
    public static final String BIND_SPEED_TOPIC = "BIND_SPEED_TOPIC";
    public static String exam_enter_exitdata="exam_enter_exitdata";
}
app/src/main/java/safeluck/drive/evaluation/MainActivity.java
@@ -163,15 +163,6 @@
        MyLog.i(TAG, "onCreate");
        MainViewModel mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
        mainViewModel.getJson().observe(this, new Observer<String>() {
            @Override
            public void onChanged(@Nullable String json) {
                Toast.makeText(MainActivity.this, json, Toast.LENGTH_SHORT).show();
                MyLog.i(TAG, "json==========" + json + " ThreadName:" + Thread.currentThread().getName());
            }
        });
        //加载根Fragment
        if (findFragment(HomeFragment.class) == null) {
app/src/main/java/safeluck/drive/evaluation/app.java
@@ -207,6 +207,13 @@
                WorkManager.getInstance(getApplicationContext()).enqueue(examStatusWorker);
                break;
            case Constant.REAL_TIME_CAR_POS:
                try {
                    JSONObject jsSpeed = new JSONObject(json);
                    double speed = jsSpeed.getDouble("speed");
                    CEventCenter.dispatchEvent(Constant.BIND_SPEED_TOPIC,cmd,0,speed);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                CEventCenter.dispatchEvent(Constant.REAL_TIME_POS_CAR_TOPIC,cmd,0,json);
                break;
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java
@@ -25,8 +25,6 @@
import com.anyun.exam.lib.MyLog;
import com.google.gson.Gson;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.List;
app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java
@@ -1,5 +1,6 @@
package safeluck.drive.evaluation.fragment;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
@@ -40,6 +41,8 @@
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.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.customview.ArrowView;
import safeluck.drive.evaluation.customview.HouseView;
@@ -66,8 +69,10 @@
    private ExamStatusViewModel examStatusViewModel;
    private static final int ADD_DATA = 1;
    private TextView tv_speed;
    private double speed=0.0;
    private List<ScoreBean> mArrayList = new ArrayList<>();
    private static final int SPEED_DATA = 2;
    public static SupportFragment newInstance() {
        return new NetWorkTrainFragment();
@@ -82,6 +87,9 @@
                av_park.setColor(whatPaintColor(examStatusList.get(2)));
                av_curve.setColor(whatPaintColor(examStatusList.get(3)));
                av_zhijiao.setColor(whatPaintColor(examStatusList.get(4)));
            }
            if (msg.what == SPEED_DATA){
                tv_speed.setText(getResources().getString(R.string.speed,speed));
            }
            return false;
        }
@@ -204,7 +212,7 @@
        houseView = view.findViewById(R.id.hv);
        tv_speed = view.findViewById(R.id.tv_speed);
        tv_speed.setText(getResources().getString(R.string.speed,56.5));
        tv_speed.setText(getResources().getString(R.string.speed,speed));
        view.findViewById(R.id.btn_return).setOnClickListener(this);
        mListView = view.findViewById(R.id.lv);
@@ -264,5 +272,22 @@
        }
    }
    private ICEventListener icEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
            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);
    }
}
app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java
@@ -69,11 +69,12 @@
    private ExamStatusViewModel examStatusViewModel;
    private static final int ADD_DATA = 1;
    private static final int SPEED_DATA = 2;
    private List<ScoreBean> mArrayList = new ArrayList<>();
    private View tv_stop;
    private TextView tv_speed;
    private double speed=0.0;
    private Handler mHandler = new Handler(new Handler.Callback() {
        @Override
@@ -85,20 +86,14 @@
                av_curve.setColor(whatPaintColor(examStatusList.get(3)));
                av_zhijiao.setColor(whatPaintColor(examStatusList.get(4)));
            }
            if (msg.what == SPEED_DATA){
                tv_speed.setText(getResources().getString(R.string.speed,speed));
            }
            return false;
        }
    });
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }
    @Override
    public void onDetach() {
        super.onDetach();
    }
    public static SupportFragment newInstance(){
        return new TrainFragment();
@@ -175,7 +170,7 @@
        houseView = view.findViewById(R.id.hv);
        tv_speed = view.findViewById(R.id.tv_speed);
        tv_speed.setText(getResources().getString(R.string.speed,123.4));
        tv_speed.setText(getResources().getString(R.string.speed,speed));
        view.findViewById(R.id.btn_return).setOnClickListener(this);
        mListView = view.findViewById(R.id.lv);
        tv_stop = view.findViewById(R.id.tv_stop);
@@ -283,4 +278,23 @@
                break;
        }
    }
    private ICEventListener icEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
            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);
    }
}
app/src/main/res/values/strings.xml
@@ -24,6 +24,6 @@
    <string name="rtk_config_sn">SN:%1$s</string>
    <string name="rtk_connect_status">RTK连接状态:%1$d</string>
    <string name="rtk_config_login">RTK登录结果:%1$d</string>
    <string name="speed">车速:%1$.1fkm/h</string>
    <string name="speed">车速:%1$.2fkm/h</string>
    <string name="licheng">已行驶:451km</string>
</resources>