Search in sources :

Example 1 with ControlMode

use of org.openbot.utils.Enums.ControlMode in project OpenBot by isl-org.

the class FreeRoamFragment method onViewCreated.

@SuppressLint("RestrictedApi")
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    phoneController = PhoneController.getInstance(requireContext());
    binding.voltageInfo.setText(getString(R.string.voltageInfo, "--.-"));
    binding.controllerContainer.speedInfo.setText(getString(R.string.speedInfo, "---,---"));
    binding.sonarInfo.setText(getString(R.string.distanceInfo, "---"));
    setSpeedMode(SpeedMode.getByID(preferencesManager.getSpeedMode()));
    setControlMode(ControlMode.getByID(preferencesManager.getControlMode()));
    setDriveMode(DriveMode.getByID(preferencesManager.getDriveMode()));
    binding.controllerContainer.controlMode.setOnClickListener(v -> {
        ControlMode controlMode = ControlMode.getByID(preferencesManager.getControlMode());
        if (controlMode != null)
            setControlMode(Enums.switchControlMode(controlMode));
    });
    binding.controllerContainer.driveMode.setOnClickListener(v -> setDriveMode(Enums.switchDriveMode(vehicle.getDriveMode())));
    binding.controllerContainer.speedMode.setOnClickListener(v -> setSpeedMode(Enums.toggleSpeed(Enums.Direction.CYCLIC.getValue(), SpeedMode.getByID(preferencesManager.getSpeedMode()))));
    binding.speed.getSections().clear();
    binding.speed.addSections(new Section(0f, 0.7f, getResources().getColor(R.color.green), ViewUtils.dpToPx(requireContext(), 24)), new Section(0.7f, 0.8f, getResources().getColor(R.color.yellow), ViewUtils.dpToPx(requireContext(), 24)), new Section(0.8f, 1.0f, getResources().getColor(R.color.red), ViewUtils.dpToPx(requireContext(), 24)));
    mViewModel.getUsbStatus().observe(getViewLifecycleOwner(), status -> binding.usbToggle.setChecked(status));
    binding.usbToggle.setChecked(vehicle.isUsbConnected());
    binding.usbToggle.setOnClickListener(v -> {
        binding.usbToggle.setChecked(vehicle.isUsbConnected());
        Navigation.findNavController(requireView()).navigate(R.id.open_settings_fragment);
    });
}
Also used : ControlMode(org.openbot.utils.Enums.ControlMode) Section(com.github.anastr.speedviewlib.components.Section) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Section (com.github.anastr.speedviewlib.components.Section)1 ControlMode (org.openbot.utils.Enums.ControlMode)1