+ public void onClickRadioButton(View view) {
+ // Get handles for the views.
+ Spinner encryptionSpinner = findViewById(R.id.encryption_spinner);
+ LinearLayout fileNameLinearLayout = findViewById(R.id.file_name_linearlayout);
+ EditText passwordEncryptionEditText = findViewById(R.id.password_encryption_edittext);
+ EditText fileNameEditText = findViewById(R.id.file_name_edittext);
+ TextView fileDoesNotExistTextView = findViewById(R.id.file_does_not_exist_textview);
+ TextView fileExistsWarningTextView = findViewById(R.id.file_exists_warning_textview);
+ TextView openKeychainImportInstructionTextView = findViewById(R.id.openkeychain_import_instructions_textview);
+ Button importExportButton = findViewById(R.id.import_export_button);
+
+ // Get the current file name.
+ String fileNameString = fileNameEditText.getText().toString();
+
+ // Convert the file name string to a file.
+ File file = new File(fileNameString);
+
+ // Check to see if import or export was selected.
+ switch (view.getId()) {
+ case R.id.import_radiobutton:
+ // Check to see if OpenPGP encryption is selected.
+ if (encryptionSpinner.getSelectedItemPosition() == OPENPGP_ENCRYPTION) { // OpenPGP encryption selected.
+ // Show the OpenKeychain import instructions.
+ openKeychainImportInstructionTextView.setVisibility(View.VISIBLE);
+
+ // Set the text on the import/export button to be `Decrypt`.
+ importExportButton.setText(R.string.decrypt);
+ } else { // OpenPGP encryption not selected.
+ // Hide the OpenKeychain import instructions.
+ openKeychainImportInstructionTextView.setVisibility(View.GONE);
+
+ // Set the text on the import/export button to be `Import`.
+ importExportButton.setText(R.string.import_button);
+ }
+
+ // Hide the file exists warning text view.
+ fileExistsWarningTextView.setVisibility(View.GONE);
+
+ // Display the file name views.
+ fileNameLinearLayout.setVisibility(View.VISIBLE);
+ importExportButton.setVisibility(View.VISIBLE);
+
+ // Check to see if the file exists.
+ if (file.exists()) { // The file exists.
+ // Hide the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+
+ // Check to see if password encryption is selected.
+ if (encryptionSpinner.getSelectedItemPosition() == PASSWORD_ENCRYPTION) { // Password encryption is selected.
+ // Enable the import button if the encryption password is populated.
+ importExportButton.setEnabled(!passwordEncryptionEditText.getText().toString().isEmpty());
+ } else { // Password encryption is not selected.
+ // Enable the import/decrypt button.
+ importExportButton.setEnabled(true);
+ }
+ } else { // The file does not exist.
+ // Show the notification that the file does not exist.
+ fileDoesNotExistTextView.setVisibility(View.VISIBLE);
+
+ // Disable the import/decrypt button.
+ importExportButton.setEnabled(false);
+ }
+ break;
+
+ case R.id.export_radiobutton:
+ // Hide the OpenKeychain import instructions.
+ openKeychainImportInstructionTextView.setVisibility(View.GONE);
+
+ // Set the text on the import/export button to be `Export`.
+ importExportButton.setText(R.string.export);
+
+ // Show the import/export button.
+ importExportButton.setVisibility(View.VISIBLE);
+
+ // Check to see if OpenPGP encryption is selected.
+ if (encryptionSpinner.getSelectedItemPosition() == OPENPGP_ENCRYPTION) { // OpenPGP encryption is selected.
+ // Hide the file name views.
+ fileNameLinearLayout.setVisibility(View.GONE);
+ fileDoesNotExistTextView.setVisibility(View.GONE);
+ fileExistsWarningTextView.setVisibility(View.GONE);
+
+ // Enable the export button.
+ importExportButton.setEnabled(true);
+ } else { // OpenPGP encryption is not selected.
+ // Show the file name view.
+ fileNameLinearLayout.setVisibility(View.VISIBLE);
+
+ // Hide the notification that the file name 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);
+ }
+
+ // Check the encryption type.
+ if (encryptionSpinner.getSelectedItemPosition() == NO_ENCRYPTION) { // No encryption is selected.
+ // Enable the export button if the file name is populated.
+ importExportButton.setEnabled(!fileNameString.isEmpty());
+ } else { // Password encryption is selected.
+ // Enable the export button if the file name and the password are populated.
+ importExportButton.setEnabled(!fileNameString.isEmpty() && !passwordEncryptionEditText.getText().toString().isEmpty());
+ }
+ }
+ break;