| | |
| | | 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.bean.StationSetting; |
| | | import safeluck.drive.evaluation.fragment.rulefragments.cview.TextEditText; |
| | | import safeluck.drive.evaluation.util.Utils; |
| | | import safeluck.drive.evaluation.viewmodels.CommonSettingViewModel; |
| | | import safeluck.drive.evaluation.viewmodels.StationSettingViewModel; |
| | | |
| | | /** |
| | | * DriveJudge |
| | | * |
| | | * 通过站点设置 |
| | | * Created by lzw on 2020/9/14. 10:16:39 |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | |
| | | public class FragmentSetting5 extends SupportFragment { |
| | | private static final String ARG_NUMBER = "arg_number"; |
| | | private static final String TAG = FragmentSetting5.class.getSimpleName(); |
| | | private Gson gson = new Gson(); |
| | | private StationSetting mStationSetting; |
| | | private StationSettingViewModel mStationSettingViewModel; |
| | | |
| | | private TextEditText te_cross_school_max_speed; |
| | | private TextEditText te_crossing_break_valid_distance; |
| | | private TextEditText te_crossing_stop_valid_distance; |
| | | |
| | | private int mNumber; |
| | | |
| | |
| | | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | View view = inflater.inflate(R.layout.layout_fragment_stationsettin, container, false); |
| | | initView(view); |
| | | mStationSettingViewModel = ViewModelProviders.of(this).get(StationSettingViewModel.class); |
| | | mStationSettingViewModel.getStationSetting().observe(this, new Observer<StationSetting>() { |
| | | @Override |
| | | public void onChanged(StationSetting commonSetting) { |
| | | if (commonSetting != null){ |
| | | mStationSetting = commonSetting; |
| | | setDatas(); |
| | | } |
| | | } |
| | | }); |
| | | return view; |
| | | } |
| | | |
| | | private void initView(View view) { |
| | | te_cross_school_max_speed = view.findViewById(R.id.cross_school_max_speed); |
| | | te_crossing_break_valid_distance = view.findViewById(R.id.crossing_break_valid_distance); |
| | | te_crossing_stop_valid_distance = view.findViewById(R.id.crossing_stop_valid_distance); |
| | | |
| | | view.findViewById(R.id.btn_setting_save).setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | String teCrossSchoolMaxSpeedInput = te_cross_school_max_speed.getInput(); |
| | | String teCrossingBreakValidDistanceInput = te_crossing_break_valid_distance.getInput(); |
| | | String teCrossingStopValidDistanceInput = te_crossing_stop_valid_distance.getInput(); |
| | | if (mStationSetting != null){ |
| | | if (Utils.isDigital(teCrossingBreakValidDistanceInput)){ |
| | | mStationSetting.setCrossing_break_valid_distance(Integer.parseInt(teCrossingBreakValidDistanceInput)); |
| | | } if (Utils.isDigital(teCrossSchoolMaxSpeedInput)){ |
| | | mStationSetting.setCross_school_max_speed(Integer.parseInt(teCrossSchoolMaxSpeedInput)); |
| | | } if (Utils.isNumber(teCrossingStopValidDistanceInput)){ |
| | | mStationSetting.setCrossing_stop_valid_distance(Double.parseDouble(teCrossingStopValidDistanceInput)); |
| | | } |
| | | mStationSettingViewModel.saveCommonSetting(mStationSetting); |
| | | Toast.makeText(_mActivity, "通过站点设置成功", Toast.LENGTH_SHORT).show(); |
| | | AYSdk.getInstance().sendCmd(Constant.ID_judge_args,gson.toJson(mStationSetting)); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | private void setDatas() { |
| | | te_cross_school_max_speed.setInput(String.valueOf(mStationSetting.getCross_school_max_speed())); |
| | | te_crossing_break_valid_distance.setInput(String.valueOf(mStationSetting.getCrossing_break_valid_distance())); |
| | | te_crossing_stop_valid_distance.setInput(String.valueOf(mStationSetting.getCrossing_stop_valid_distance())); |
| | | } |
| | | } |