yy1717
2020-01-21 a889e603481b5f3f6cf0074af1f25f94b571db8c
Merge branch 'master' of https://gitee.com/endian11/DriveJudge
6个文件已修改
146 ■■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/Constant.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/DB/failitems/FailedProjViewModel.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/app.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java 127 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/util/CThreadPoolExecutor.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/Constant.java
@@ -69,5 +69,7 @@
    public static final int PASSING_SCORE = 80;
    public static final int DEBUG_RTCM = 0x000f;
    public static final int DEBUG_TXT = 0x0010;
    public static final String BIND_RTCM_TOPIC = "BIND_RTCM_TOPIC";
    public static final String BIND_DEBUG_TXT = "BIND_DEBUG_TXT";
    public static String exam_enter_exitdata="exam_enter_exitdata";
}
app/src/main/java/safeluck/drive/evaluation/DB/failitems/FailedProjViewModel.java
@@ -32,4 +32,8 @@
    public void insert(FailedProj proj){
        failedProjRepository.insert(proj);
    }
    public void  deleteAll(){
        failedProjRepository.deleteAll();
    }
}
app/src/main/java/safeluck/drive/evaluation/app.java
@@ -66,7 +66,7 @@
        super.onCreate();
        //初始化Fragment 建议在Application onCreate里面初始化
        if (SystemUtil.compareProcessName(this)) {
            Fragmentation.builder().stackViewMode(Fragmentation.BUBBLE).debug(false)
            Fragmentation.builder().stackViewMode(Fragmentation.BUBBLE).debug(true)
                    .handleException(new ExceptionHandler() {
                        @Override
                        public void onException(@NonNull Exception e) {
@@ -166,7 +166,6 @@
                MyLog.d(TAG, "考试开始,复位数据库失败项目表");
                try {
                    failedProjRepository.deleteAll();
                    JSONObject jsonObject =new JSONObject((String)json);
                    int errCode = jsonObject.getInt("error");
                    switch (errCode){
@@ -221,10 +220,10 @@
                CEventCenter.dispatchEvent(Constant.REAL_TIME_POS_CAR_TOPIC,cmd,0,json);
                break;
            case Constant.DEBUG_RTCM:
                CEventCenter.dispatchEvent(Constant.REAL_TIME_POS_CAR_TOPIC,cmd,0,json);
                CEventCenter.dispatchEvent(Constant.BIND_RTCM_TOPIC,cmd,0,json);
                break;
            case Constant.DEBUG_TXT:
                CEventCenter.dispatchEvent(Constant.REAL_TIME_POS_CAR_TOPIC,cmd,0,json);
                CEventCenter.dispatchEvent(Constant.BIND_DEBUG_TXT,cmd,0,json);
                break;
        }
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java
@@ -6,8 +6,8 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
@@ -15,7 +15,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -32,6 +31,9 @@
import java.lang.reflect.Type;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.Constant;
@@ -52,6 +54,36 @@
 */
public class MapFragment extends SupportFragment {
    private boolean isDrawing = false;
    private ICEventListener rtcmicEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, final Object obj) {
            if (msgCode == Constant.DEBUG_RTCM){
                CThreadPoolExecutor.runOnMainThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.i(TAG, "title="+(String)obj);
                        toolbar.setTitle((String)obj);
                    }
                });
                }
        }
    };
    private ICEventListener debugTxticEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, final Object obj) {
            if (msgCode == Constant.DEBUG_TXT){
                CThreadPoolExecutor.runOnMainThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.i(TAG, "subtitle="+(String)obj);
                        toolbar.setSubtitle((String)obj);
                    }
                });
            }
        }
    };
    public static SupportFragment newInstance() {
        return new MapFragment();
@@ -80,6 +112,9 @@
            , {9.278, -1.5330000000000004}, {9.277999999999999, 1.467000000000001}};
    Gson gson;
    private LinearLayout linearLayout;//surfaceview的父容器,为了移动surfaceview而使用,因为scrollto不能移动view,
    private LinkedBlockingQueue queue = new LinkedBlockingQueue(100);
    private ExecutorService producer = Executors.newSingleThreadExecutor();
    private ExecutorService consumer = Executors.newSingleThreadExecutor();
    @Nullable
@@ -88,6 +123,7 @@
        View view = inflater.inflate(R.layout.layout_mapfragment, container, false);
        gson = new Gson();
        initView(view);
        consumer.execute(new CalRunnable());
        return view;
    }
@@ -282,12 +318,12 @@
                    pathText.lineTo(700, 30);
                    canvas2.drawTextOnPath(osd2, pathText, 0, 0, paint);//逆时针生成
                }
                if (osd3 != null) {
                    Path pathText = new Path();
                    pathText.moveTo(10, 240);
                    pathText.lineTo(700, 130);
                    canvas2.drawTextOnPath(osd2, pathText, 0, 0, paint);//逆时针生成
                }
//                if (osd3 != null) {
//                    Path pathText = new Path();
//                    pathText.moveTo(10, 240);
//                    pathText.lineTo(700, 130);
//                    canvas2.drawTextOnPath(osd2, pathText, 0, 0, paint);//逆时针生成
//                }
                // 提交画布
                Canvas canvas = holder.lockCanvas();
@@ -329,54 +365,54 @@
    int line = 0;
    int map_line = 0;
    private StringBuffer stringBuffer = new StringBuffer();
    class MessageRemoteService{
        public int msgCode;
        public String json;
        public MessageRemoteService(int msgCode, Object obj) {
            this.json = (String) obj;
            this.msgCode = msgCode;
        }
    }
    private ICEventListener icEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
        public void onCEvent(String topic, final int msgCode, int resultCode, final Object obj) {
            CThreadPoolExecutor.runInBackground(new CalRunnable(msgCode,(String)obj));
            producer.execute(new Runnable() {
                @Override
                public void run() {
                    queue.offer(new MessageRemoteService(msgCode,obj));
                }
            });
        }
    };
    boolean flag = true;
    class CalRunnable implements Runnable{
        private String json;
        private int cmd;
        public CalRunnable(int cmd,String obj) {
           this.json = obj;
           this.cmd = cmd;
        }
        @Override
        public void run() {
            while (flag){
                MessageRemoteService messageRemoteService = (MessageRemoteService) queue.peek();
                if (messageRemoteService == null){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                messageRemoteService = (MessageRemoteService) queue.poll();
                if (messageRemoteService != null){
                    this.cmd = messageRemoteService.msgCode;
                    this.json = messageRemoteService.json;
            MyLog.i(TAG, json);
            if (!(cmd == Constant.REAL_TIME_CAR_POS)){
                if (cmd == Constant.DEBUG_RTCM){
                    stringBuffer.append("\tRTCM:");
                    try {
                        JSONObject jsonObject = new JSONObject(json);
                        int length = jsonObject.getInt("length");
                        stringBuffer.append(length);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                if (cmd == Constant.DEBUG_TXT){
                    try {
                        JSONObject jsonObject = new JSONObject(json);
                        String info = jsonObject.getString("info");
                        stringBuffer.append("\tinfo:");
                        stringBuffer.append(info);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
            osd3 = stringBuffer.toString();
            if (osd3!=null && osd3.contains("info:")&&osd3.contains("RTCM:")){
                stringBuffer.delete(0,stringBuffer.length());
            }
            RealTimeCarPos timeCarPos = gson.fromJson((String) json, RealTimeCarPos.class);
            List<Double> points = timeCarPos.getPoint();
            switch (timeCarPos.getMove()){
@@ -453,16 +489,27 @@
            }
            DrawMap(map,car);
        }
            }
        }
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        CEventCenter.onBindEvent(true, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC);
        CEventCenter.onBindEvent(true, rtcmicEventListener, Constant.BIND_RTCM_TOPIC);
        CEventCenter.onBindEvent(true, debugTxticEventListener, Constant.BIND_DEBUG_TXT);
    }
    @Override
    public void onDetach() {
        super.onDetach();
        flag = false;
        producer.shutdown();
        consumer.shutdown();
        CEventCenter.onBindEvent(false, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC);
        CEventCenter.onBindEvent(false, icEventListener, Constant.BIND_RTCM_TOPIC);
        CEventCenter.onBindEvent(false, icEventListener, Constant.BIND_DEBUG_TXT);
    }
}
app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java
@@ -79,6 +79,7 @@
    private int currTotalScore = 100;
    private List<ScoreBean> mArrayList = new ArrayList<>();
    private static final int SPEED_DATA = 2;
    private FailedProjViewModel failedProjViewModel;
    public static SupportFragment newInstance() {
        return new NetWorkTrainFragment();
@@ -109,7 +110,7 @@
        View view = inflater.inflate(R.layout.layout_train_fragment, container, false);
        initView(view);
        FailedProjViewModel failedProjViewModel = ViewModelProviders.of(this).get(FailedProjViewModel.class);
        failedProjViewModel = ViewModelProviders.of(this).get(FailedProjViewModel.class);
        failedProjViewModel.getFailedProjectsForI(Constant.TEST_STU_ID).observe(this, new Observer<List<FailedProj_select>>() {
            @Override
            public void onChanged(List<FailedProj_select> failedProj_selects) {
@@ -288,6 +289,7 @@
        switch (v.getId()) {
            case R.id.btn_start:
                examStatusViewModel.updateStartExam(Constant.HAS_BEEN_START_EXAM);
                failedProjViewModel.deleteAll();
                sendExamJson(1);
                iv_head.getDrawable().setLevel(1);
                break;
@@ -297,6 +299,7 @@
                break;
            case R.id.view_map:
                MapFragment mapFragment = findFragment(MapFragment.class);
                MyLog.i(TAG,"查看地图");
                if (mapFragment == null) {
                    mapFragment = (MapFragment) MapFragment.newInstance();
                }
app/src/main/java/safeluck/drive/evaluation/util/CThreadPoolExecutor.java
@@ -208,6 +208,7 @@
    public static void runInBackground(Runnable runnable) {
        if (pool == null) {
            Log.i(TAG, "runInBackground: ");
            createThreadPoolExecutor();
        }