use of org.openbot.utils.Constants.PERMISSION_LOCATION in project OpenBot by isl-org.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
mViewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class);
vehicle = mViewModel.getVehicle().getValue();
connection = findPreference("connection");
if (connection != null) {
connection.setTitle("No Device");
if (vehicle != null && vehicle.isUsbConnected()) {
connection.setChecked(true);
connection.setTitle(vehicle.getUsbConnection().getProductName());
} else {
connection.setTitle("No Device");
connection.setChecked(false);
}
connection.setOnPreferenceClickListener(preference -> {
Timber.d(String.valueOf(connection.isChecked()));
if (vehicle != null) {
if (connection.isChecked()) {
vehicle.connectUsb();
if (vehicle.isUsbConnected())
connection.setTitle(vehicle.getUsbConnection().getProductName());
else {
connection.setTitle("No Device");
connection.setChecked(false);
Toast.makeText(requireContext().getApplicationContext(), "Please check the USB connection.", Toast.LENGTH_SHORT).show();
}
} else {
vehicle.disconnectUsb();
connection.setTitle("No Device");
}
mViewModel.setUsbStatus(vehicle.isUsbConnected());
}
return true;
});
}
camera = findPreference("camera");
if (camera != null) {
camera.setChecked(PermissionUtils.hasCameraPermission(requireActivity()));
camera.setOnPreferenceChangeListener((preference, newValue) -> {
if (camera.isChecked())
startInstalledAppDetailsActivity(requireActivity());
else {
if (!PermissionUtils.shouldShowRational(requireActivity(), Constants.PERMISSION_CAMERA)) {
startInstalledAppDetailsActivity(requireActivity());
} else {
requestPermissionLauncher.launch(new String[] { Constants.PERMISSION_CAMERA });
}
}
return false;
});
}
storage = findPreference("storage");
if (storage != null) {
storage.setChecked(PermissionUtils.hasStoragePermission(requireActivity()));
storage.setOnPreferenceChangeListener((preference, newValue) -> {
if (storage.isChecked())
startInstalledAppDetailsActivity(requireActivity());
else {
if (!PermissionUtils.shouldShowRational(requireActivity(), Constants.PERMISSION_STORAGE)) {
startInstalledAppDetailsActivity(requireActivity());
} else
requestPermissionLauncher.launch(new String[] { Constants.PERMISSION_STORAGE });
}
return false;
});
}
location = findPreference("location");
if (location != null) {
location.setChecked(PermissionUtils.hasLocationPermission(requireActivity()));
location.setOnPreferenceChangeListener((preference, newValue) -> {
if (location.isChecked())
startInstalledAppDetailsActivity(requireActivity());
else {
if (!PermissionUtils.shouldShowRational(requireActivity(), PERMISSION_LOCATION)) {
startInstalledAppDetailsActivity(requireActivity());
} else
requestPermissionLauncher.launch(new String[] { PERMISSION_LOCATION });
}
return false;
});
}
mic = findPreference("mic");
if (mic != null) {
mic.setChecked(PermissionUtils.hasAudioPermission(requireActivity()));
mic.setOnPreferenceChangeListener((preference, newValue) -> {
if (mic.isChecked())
startInstalledAppDetailsActivity(requireActivity());
else {
if (!PermissionUtils.shouldShowRational(requireActivity(), Constants.PERMISSION_AUDIO)) {
startInstalledAppDetailsActivity(requireActivity());
} else
requestPermissionLauncher.launch(new String[] { Constants.PERMISSION_AUDIO });
}
return false;
});
}
ListPreference streamMode = findPreference("video_server");
if (streamMode != null)
streamMode.setOnPreferenceChangeListener((preference, newValue) -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
builder.setTitle(R.string.confirm_title);
builder.setMessage(R.string.stream_change_body);
builder.setPositiveButton("Yes", (dialog, id) -> {
streamMode.setValue(newValue.toString());
restartApp();
});
builder.setNegativeButton("Cancel", (dialog, id) -> streamMode.setValue(streamMode.getEntry().toString()));
AlertDialog dialog = builder.create();
dialog.show();
return false;
});
}
Aggregations