endian11
2020-10-26 a5c2e37286dd29b02fff10247e6f3201ad5f58cd
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package safeluck.drive.evaluation.fragment.rulefragments;
 
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
 
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
 
import com.anyun.exam.lib.AYSdk;
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.CommonSetting;
import safeluck.drive.evaluation.fragment.rulefragments.cview.TextEditText;
import safeluck.drive.evaluation.util.Utils;
import safeluck.drive.evaluation.viewmodels.CommonSettingViewModel;
 
/**
 * DriveJudge
 * Created by lzw on 2020/9/14. 10:16:39
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class FragmentSetting2 extends SupportFragment {
    private static final String ARG_NUMBER = "arg_number";
    private static final String TAG = FragmentSetting2.class.getSimpleName();
    private Gson gson = new Gson();
    private CommonSetting mCommonSetting;
    private CommonSettingViewModel commonSettingViewModel;
 
    private TextEditText te_road_pause_time;
    private TextEditText te_crash_dotted_line_time;
    private TextEditText te_slide_yellow_distance;
    private TextEditText te_slide_red_distance;
    private TextEditText te_lane_min_time;
    private TextEditText te_change_lane_dis;
 
    private int mNumber;
 
    public static FragmentSetting2 newInstance(String number) {
        FragmentSetting2 fragment = new FragmentSetting2();
        Bundle args = new Bundle();
        args.putInt(ARG_NUMBER, Integer.parseInt(number));
        fragment.setArguments(args);
        return fragment;
    }
 
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            mNumber =args.getInt(ARG_NUMBER) ;
            Log.i(TAG,"mNumber="+mNumber);
        }
    }
 
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_common_judge_1, container, false);
        initView(view);
        commonSettingViewModel = ViewModelProviders.of(this).get(CommonSettingViewModel.class);
        commonSettingViewModel.getCommonSetting().observe(this, new Observer<CommonSetting>() {
            @Override
            public void onChanged(CommonSetting commonSetting) {
                if (commonSetting != null){
                    mCommonSetting = commonSetting;
                    setDatas();
                }
            }
        });
        return view;
    }
 
    private void setDatas() {
        if (mCommonSetting != null){
            te_change_lane_dis.setInput(String.valueOf(mCommonSetting.getChange_lane_limit_distance()));
            te_crash_dotted_line_time.setInput(String.valueOf(mCommonSetting.getCrash_dotted_line_cumulative_time()));
            te_lane_min_time.setInput(String.valueOf(mCommonSetting.getContinuous_change_lane_min_time()));
            te_road_pause_time.setInput(String.valueOf(mCommonSetting.getRoad_pause_criteria()));
            te_slide_red_distance.setInput(String.valueOf(mCommonSetting.getRoad_slide_red_distance()));
            te_slide_yellow_distance.setInput(String.valueOf(mCommonSetting.getRoad_slide_yellow_distance()));
        }
    }
 
    private void initView(View view) {
    te_change_lane_dis = view.findViewById(R.id.road_change_lane_dist);
    te_crash_dotted_line_time = view.findViewById(R.id.road_crash_dotted_line_time);
    te_lane_min_time = view.findViewById(R.id.road_lane_min_time);
    te_road_pause_time = view.findViewById(R.id.road_pause_time);
    te_slide_red_distance = view.findViewById(R.id.road_slide_red_distance);
    te_slide_yellow_distance = view.findViewById(R.id.road_slide_yellow_distance);
 
    view.findViewById(R.id.btn_setting_save).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String change_lane_dis_str = te_change_lane_dis.getInput();
            String crash_dotted_line_time_str = te_crash_dotted_line_time.getInput();
            String lane_min_time_str = te_lane_min_time.getInput();
            String road_pause_time_str = te_road_pause_time.getInput();
            String slide_red_distance_str = te_slide_red_distance.getInput();
            String slide_yellow_distance_str = te_slide_yellow_distance.getInput();
 
            if (mCommonSetting != null){
 
                if (Utils.isDigital(change_lane_dis_str)){
 
                     mCommonSetting.setChange_lane_limit_distance(Integer.parseInt(change_lane_dis_str));
                }
                if (Utils.isDigital(crash_dotted_line_time_str)){
                    mCommonSetting.setCrash_dotted_line_cumulative_time(Integer.parseInt(crash_dotted_line_time_str));
                }
                if (Utils.isDigital(lane_min_time_str)){
                    mCommonSetting.setContinuous_change_lane_min_time(Integer.parseInt(lane_min_time_str));
                }
                if (Utils.isDigital(road_pause_time_str)){
 
                    mCommonSetting.setRoad_pause_criteria(Integer.parseInt(road_pause_time_str));
                }
                if (Utils.isNumber(slide_red_distance_str)){
                    mCommonSetting.setRoad_slide_red_distance(Double.parseDouble(slide_red_distance_str));
                }
                if (Utils.isNumber(slide_yellow_distance_str)){
                    mCommonSetting.setRoad_slide_yellow_distance(Double.parseDouble(slide_yellow_distance_str));
                }
 
 
 
 
 
                commonSettingViewModel.saveCommonSetting(mCommonSetting);
                AYSdk.getInstance().sendCmd(Constant.ID_judge_args,gson.toJson(mCommonSetting));
                Toast.makeText(_mActivity, "通用设置成功", Toast.LENGTH_SHORT).show();
            }
        }
    });
    }
 
}