+ // Get the current file name.
+ String fileNameString = fileNameEditText.getText().toString();
+
+ // Convert the file name string to a file.
+ File file = new File(fileNameString);
+
+ // Adjust the UI according to the encryption spinner position.
+ switch (encryptionSpinner.getSelectedItemPosition()) {
+ case NO_ENCRYPTION:
+ // Determine if import or export is checked.
+ if (exportRadioButton.isChecked()) { // The export radio button is checked.
+ // Hide the file does not exist text view.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+
+ // Display a warning if the file already exists.
+ if (file.exists()) {
+ fileExistsWarningTextView.setVisibility(View.VISIBLE);
+ } else {
+ fileExistsWarningTextView.setVisibility(View.GONE);
+ }
+
+ // Enable the export button if the file name is populated.
+ importExportButton.setEnabled(!fileNameString.isEmpty());
+ } else if (importRadioButton.isChecked()) { // The import radio button is checked.
+ // Hide the file exists warning text view.
+ fileExistsWarningTextView.setVisibility(View.GONE);
+
+ // Check if the file exists.
+ if (file.exists()) { // The file exists.
+ // Hide the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+
+ // Enable the import button.
+ importExportButton.setEnabled(true);
+ } else { // The file does not exist.
+ // Show a notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.VISIBLE);
+
+ // Disable the import button.
+ importExportButton.setEnabled(false);
+ }
+ } else { // Neither radio button is checked.
+ // Hide the file notification text views.
+ fileExistsWarningTextView.setVisibility(View.GONE);
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+ }
+ break;
+
+ case PASSWORD_ENCRYPTION:
+ // Determine if import or export is checked.
+ if (exportRadioButton.isChecked()) { // The export radio button is checked.
+ // Hide the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+
+ // Display a warning if the file already exists.
+ if (file.exists()) {
+ fileExistsWarningTextView.setVisibility(View.VISIBLE);
+ } else {
+ fileExistsWarningTextView.setVisibility(View.GONE);
+ }
+
+ // Enable the export button if the file name and the password are populated.
+ importExportButton.setEnabled(!fileNameString.isEmpty() && !encryptionPasswordEditText.getText().toString().isEmpty());
+ } else if (importRadioButton.isChecked()) { // The import radio button is checked.
+ // Hide the file exists warning text view.
+ fileExistsWarningTextView.setVisibility(View.GONE);
+
+ // Check if the file exists.
+ if (file.exists()) { // The file exists.
+ // Hide the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+
+ // Enable the import button if the password is populated.
+ importExportButton.setEnabled(!encryptionPasswordEditText.getText().toString().isEmpty());
+ } else { // The file does not exist.
+ // Show a notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.VISIBLE);
+
+ // Disable the import button.
+ importExportButton.setEnabled(false);
+ }
+ } else { // Neither radio button is checked.
+ // Hide the file notification text views.
+ fileExistsWarningTextView.setVisibility(View.GONE);
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+ }
+ break;
+
+ case OPENPGP_ENCRYPTION:
+ // Hide the file exists warning text view.
+ fileExistsWarningTextView.setVisibility(View.GONE);
+
+ if (importRadioButton.isChecked()) { // The import radio button is checked.
+ if (file.exists()) { // The file exists.
+ // Hide the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+
+ // Enable the import button if OpenKeychain is installed.
+ importExportButton.setEnabled(openKeychainInstalled);
+ } else { // The file does not exist.
+ // Show the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.VISIBLE);
+
+ // Disable the import button.
+ importExportButton.setEnabled(false);
+ }
+ } else if (exportRadioButton.isChecked()){ // The export radio button is checked.
+ // Hide the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+
+ // Enable the export button.
+ importExportButton.setEnabled(true);
+ } else { // Neither radio button is checked.
+ // Hide the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+ }
+ break;
+ }