- Snackbar.make(logcatTextView, getString(R.string.save_failed) + " " + exception.toString(), Snackbar.LENGTH_INDEFINITE).show();
- }
- }
-
- // The activity result is called after browsing for a file in the save alert dialog.
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- // Run the default commands.
- super.onActivityResult(requestCode, resultCode, data);
-
- // Don't do anything if the user pressed back from the file picker.
- if (resultCode == Activity.RESULT_OK) {
- // Get a handle for the save dialog fragment.
- DialogFragment saveDialogFragment = (DialogFragment) getSupportFragmentManager().findFragmentByTag(getString(R.string.save_logcat));
-
- // Only update the file name if the dialog still exists.
- if (saveDialogFragment != null) {
- // Get a handle for the save dialog.
- Dialog saveDialog = saveDialogFragment.getDialog();
-
- // Remove the lint warning below that the save dialog might be null.
- assert saveDialog != null;
-
- // Get a handle for the dialog views.
- EditText fileNameEditText = saveDialog.findViewById(R.id.file_name_edittext);
- TextView fileExistsWarningTextView = saveDialog.findViewById(R.id.file_exists_warning_textview);
-
- // Instantiate the file name helper.
- FileNameHelper fileNameHelper = new FileNameHelper();
-
- // Get the file name URI from the intent.
- Uri fileNameUri= data.getData();
-
- // Process the file name URI if it is not null.
- if (fileNameUri != null) {
- // Convert the file name URI to a file name path.
- String fileNamePath = fileNameHelper.convertUriToFileNamePath(fileNameUri);
-
- // Set the file name path as the text of the file name edit text.
- fileNameEditText.setText(fileNamePath);
-
- // Move the cursor to the end of the file name edit text.
- fileNameEditText.setSelection(fileNamePath.length());
-
- // Hide the file exists warning.
- fileExistsWarningTextView.setVisibility(View.GONE);
- }
- }