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() { @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(); } } }); } }