endian11
2020-09-18 b41f9db09c0145d4530e78c0c53d0a1cacd29e03
app/src/main/java/safeluck/drive/evaluation/fragment/TrainFragment.java
@@ -7,15 +7,11 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
@@ -30,8 +26,7 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
@@ -107,6 +102,8 @@
    private static final String TAG = TrainFragment.class.getSimpleName();
    private static final int ROUTE_COLLECT = 5;//线路采集标志
    private RouteBean currRouteBean;
    private ScrollView scrollView;
    public static SupportFragment newInstance() {
@@ -131,6 +128,11 @@
    private static final int ADD_DATA = 1;
    private TextView tv_speed,tv_total_score,tv_name
            ,tv_start_time,tv_coach_name;
    //主要用来展示线路采集时的信息
    private TextView tv_route_collect_info;
    private StringBuilder stringBuilder = new StringBuilder();
    private double speed=0.0;
    private ImageView iv_head,iv_coach_head;
    WokViewModel wokViewModel;
@@ -143,6 +145,12 @@
    private String content;//用以生成二维码的内容
    RouteCollectController routeCollectController;
    //要插入数据库的路口信息
    private RouteCross routeCross;
    //要插入数据库的触发线信息
    private RouteTriggerLine routeTriggerLine;
private List<Integer> btn_ids = new ArrayList<Integer>();
private HashMap<String,Integer> routeCollect_btn_ids = new HashMap<>();
@@ -375,6 +383,7 @@
        }else{
            if (exam_type == ROUTE_COLLECT){
                items_score.setVisibility(View.GONE);
                items.setVisibility(View.GONE);
                route_collect.setVisibility(View.VISIBLE);
@@ -397,6 +406,17 @@
                    mRouteBeans.clear();
                if (routeBeans.size()>0){
                    for (int i = 0; i < routeBeans.size(); i++) {
                        if (routeBeans.get(i).getCurrentCollectFlag()==1){
                            currRouteBean = routeBeans.get(i);
                            ExamPlatformData.getInstance().setRouteCollectLineName(currRouteBean.getRouteName());
                            stringBuilder.delete(0,stringBuilder.length());
                            stringBuilder.append("当前采集线路名称:"+currRouteBean.getRouteName());
                            stringBuilder.append("\n");
                            tv_route_collect_info.setText(stringBuilder.toString());
                            break;
                        }
                    }
                    mRouteBeans.addAll(routeBeans);
                }
            }
@@ -553,6 +573,8 @@
    private void initView(View view) {
        tv_route_collect_info = view.findViewById(R.id.tv_route_info);
        routeCollectController = new RouteCollectController(this);
        items = view.findViewById(R.id.items);
        items_score=view.findViewById(R.id.items_score);
@@ -681,10 +703,12 @@
                                            if (string.equalsIgnoreCase(bean.getRouteName())){
                                                //有重名的线路,提示用户并不开启线路采集
                                                Toast.makeText(_mActivity, "继续采集"+bean.getRouteName(), Toast.LENGTH_SHORT).show();
                                                routeLineViewModel.updateCurrCollectFlag(string);
                                                flag = true;
                                                break;
                                            }
                                        }
                                        Toast.makeText(_mActivity, "线路采集", Toast.LENGTH_SHORT).show();
                                        ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.ROUTE_MODE);
                                        exam_type = 5;
@@ -693,8 +717,11 @@
                                        items_score.setVisibility(View.GONE);
                                        route_collect.setVisibility(View.VISIBLE);
                                        if (!flag){
                                            RouteBean routeBean = new RouteBean();
                                            routeBean.setRouteName(string);
                                            routeBean.setCurrentCollectFlag(1);
                                            ExamPlatformData.getInstance().setRouteCollectLineName(string);
                                            routeLineViewModel.insertRouteBean(routeBean);
                                        }
@@ -715,7 +742,7 @@
                    if (exam_type == ROUTE_COLLECT){
                        Toast.makeText(_mActivity, "结束采集", Toast.LENGTH_SHORT).show();
                        routeLineViewModel.updateCurrCollectFlag("");
                        ExamPlatformData.getInstance().setTrainingMode(ExamPlatformData.MODE_NONE);
                        exam_type = 0;
                        examStatusViewModel.updateStartExam(exam_type);
@@ -791,6 +818,34 @@
                    Map.Entry<String, Integer> next = iterator.next();
                    if (next.getValue()== v.getId()){
                routeCollectController.startCollect();
                switch (next.getKey()){
                    case "超车":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_OVERTAKE);
                        break;
                        case "变更车道":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_CHANGE_LANE);
                        break;
                        case "直线行驶":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_STRAIGHT);
                        break;
                        case "加减档":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_OPERATE_GEAR);
                        break;
                        case "靠边停车":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_PARK_SIDE);
                        break;
                        case "通过人行横道":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_CROSS_WALK);
                        break;
                        case "通过学校区域":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_SCHOOL_AREA);
                        break;
                        case "通过公共汽车站":
                        ExamPlatformData.getInstance().setCurrRouteItem(ExamPlatformData.ROAD_ITEM_BUS_AREA);
                        break;
                }
                        stringBuilder.append("当前采集项目:"+next.getKey());
                        stringBuilder.append("\n");
                Toast.makeText(_mActivity, String.format("点击了%s",next.getKey()), Toast.LENGTH_SHORT).show();
                break;
                    }
@@ -1050,26 +1105,128 @@
    @Override
    public void beginCollectView() {
        Log.i(TAG,"BIND_RTK_INFO_MAP");
        CThreadPoolExecutor.runOnMainThread(()->{
            StatusDialog.with(_mActivity).setType(StatusDialog.Type.PROGRESS).setCancelable(true).show();
        });
    }
    @Override
    public void endCollectView() {
        Log.i(TAG,"endCollectView");
        CThreadPoolExecutor.runOnMainThread(()->{
//            StatusDialog.with(_mActivity).setType(StatusDialog.Type.PROGRESS).dismiss();
        });
        routeCollectController.endCollect();
    }
    @Override
    public void routeItem(CollectPointResult collectPointResult) {
        Log.i(TAG,String.format("x=%f,y=%f",collectPointResult.getX(),collectPointResult.getY()));
        RoadInfo roadInfo = ExamPlatformData.getInstance().getRouteCollectRoadInfo();
        if (roadInfo != null && roadInfo.getStatus()==1){
            Log.i(TAG,"在某个路里面"+roadInfo.getRoad_id());
            routeTriggerLine.setX(collectPointResult.getX());
            routeTriggerLine.setY(collectPointResult.getY());
            routeTriggerLine.setType(ExamPlatformData.getInstance().getCurrRouteItem());
            routeTriggerLine.setRoad(roadInfo.getRoad_id());
            routeTriggerLine.setRouteline_id(currRouteBean.getId());
            routeLineViewModel.insertRouteTriggerLine(routeTriggerLine);
        }
        stringBuilder.append(String.format("x=%f,y=%f",collectPointResult.getX(),collectPointResult.getY()));
        stringBuilder.append("\n");
        showRouteCollectInfoText();
    }
    private void showRouteCollectInfoText(){
        CThreadPoolExecutor.runOnMainThread(new Runnable() {
            @Override
            public void run() {
                tv_route_collect_info.setText(stringBuilder.toString());
            }
        });
    }
    @Override
    public void roadinfo(RoadInfo roadInfo) {
            Log.i(TAG,String.format("道路信息%s",roadInfo.toString()));
            //道路信息是没有进行本地保存的,如果崩溃的话,就有问题
            ExamPlatformData.getInstance().setRouteCollectRoadInfo(roadInfo);
            stringBuilder.append(String.format("道路信息%s",roadInfo.toString()));
            stringBuilder.append("\n");
            showRouteCollectInfoText();
    }
    @Override
    public void roadcrossInfo(RoadCrossInfo roadCrossInfo) {
        Log.i(TAG,String.format("道路路口信息%s",roadCrossInfo.toString()));
        stringBuilder.append(String.format("道路路口信息%s",roadCrossInfo.toString()));
        stringBuilder.append("\n");
        showRouteCollectInfoText();
        CThreadPoolExecutor.runInBackground(new Runnable() {
            @Override
            public void run() {
                routeCross = new RouteCross();
                routeCross.setRouteline_id(currRouteBean.getId());
                routeCross.setRoad(roadCrossInfo.getRoad_id());
                routeCross.setIdx(roadCrossInfo.getCrossing_index());
                if (roadCrossInfo.getStatus() == 1){
                    CThreadPoolExecutor.runOnMainThread(new Runnable() {
                        @Override
                        public void run() {
                            SelectDialogThree selectDialogThree = SelectDialogThree.newInstance("路口直行","路口左转弯","路口右转弯","路口掉头");
                            selectDialogThree.show(getFragmentManager(),"aaa");
                            selectDialogThree.setSelectedListener(new SelectDialogThree.OnSelectedListener() {
                                @Override
                                public void makeYourChoice(int res) {
                                    switch (res){
                                        case 0:
                                            //直行
                                            routeCross.setActive(1);
                                            break;
                                        case 1:
                                            //左转弯
                                            routeCross.setActive(2);
                                            break;
                                        case 2:
                                            //右转弯
                                            routeCross.setActive(4);
                                            break;
                                        case 3:
                                            //调头
                                            routeCross.setActive(8);
                                            break;
                                    }
                                    if (res != SelectDialogThree.SELECT_NONE){
                                        routeLineViewModel.insertRouteCross(routeCross);
                                    }else{
                                        Log.i(TAG,"在路口没有做出选择");
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    }
    private int getRouteLine_id() {
        for (int i = 0; i < mRouteBeans.size(); i++){
            if (mRouteBeans.get(i).getRouteName().equalsIgnoreCase(ExamPlatformData.getInstance().getRouteLineName())){
                return mRouteBeans.get(i).getId();
            }
        }
        return -1;
    }
}