+ // Display the encryption information when the spinner changes.
+ encryptionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ switch (position) {
+ case NO_ENCRYPTION:
+ // Hide the unneeded layout items.
+ passwordEncryptionTextInputLayout.setVisibility(View.GONE);
+ kitKatPasswordEncryptionTextView.setVisibility(View.GONE);
+ openKeychainRequiredTextView.setVisibility(View.GONE);
+ openKeychainImportInstructionsTextView.setVisibility(View.GONE);
+
+ // Show the file location card.
+ fileLocationCardView.setVisibility(View.VISIBLE);
+
+ // Show the file name linear layout if either import or export is checked.
+ if (importRadioButton.isChecked() || exportRadioButton.isChecked()) {
+ fileNameLinearLayout.setVisibility(View.VISIBLE);
+ }
+
+ // Reset the text of the import button, which may have been changed to `Decrypt`.
+ if (importRadioButton.isChecked()) {
+ importExportButton.setText(R.string.import_button);
+ }
+
+ // Reset the default file path.
+ fileNameEditText.setText(defaultFilePath);
+
+ // Enable the import/export button if a file name exists.
+ importExportButton.setEnabled(!fileNameEditText.getText().toString().isEmpty());
+ break;
+
+ case PASSWORD_ENCRYPTION:
+ if (runningKitKat) {
+ // Show the KitKat password encryption message.
+ kitKatPasswordEncryptionTextView.setVisibility(View.VISIBLE);
+
+ // Hide the OpenPGP required text view and the file location card.
+ openKeychainRequiredTextView.setVisibility(View.GONE);
+ fileLocationCardView.setVisibility(View.GONE);
+ } else {
+ // Hide the OpenPGP layout items.
+ openKeychainRequiredTextView.setVisibility(View.GONE);
+ openKeychainImportInstructionsTextView.setVisibility(View.GONE);
+
+ // Show the password encryption layout items.
+ passwordEncryptionTextInputLayout.setVisibility(View.VISIBLE);
+
+ // Show the file location card.
+ fileLocationCardView.setVisibility(View.VISIBLE);
+
+ // Show the file name linear layout if either import or export is checked.
+ if (importRadioButton.isChecked() || exportRadioButton.isChecked()) {
+ fileNameLinearLayout.setVisibility(View.VISIBLE);
+ }
+
+ // Reset the text of the import button, which may have been changed to `Decrypt`.
+ if (importRadioButton.isChecked()) {
+ importExportButton.setText(R.string.import_button);
+ }
+
+ // Update the default file path.
+ fileNameEditText.setText(defaultPasswordEncryptionFilePath);
+
+ // Enable the import/export button if a password exists.
+ importExportButton.setEnabled(!encryptionPasswordEditText.getText().toString().isEmpty());
+ }
+ break;
+
+ case OPENPGP_ENCRYPTION:
+ // Hide the password encryption layout items.
+ passwordEncryptionTextInputLayout.setVisibility(View.GONE);
+ kitKatPasswordEncryptionTextView.setVisibility(View.GONE);
+
+ // Updated items based on the installation status of OpenKeychain.
+ if (openKeychainInstalled) { // OpenKeychain is installed.
+ // Remove the default file path.
+ fileNameEditText.setText("");
+
+ // Show the file location card.
+ fileLocationCardView.setVisibility(View.VISIBLE);
+
+ if (importRadioButton.isChecked()) {
+ // Show the file name linear layout and the OpenKeychain import instructions.
+ fileNameLinearLayout.setVisibility(View.VISIBLE);
+ openKeychainImportInstructionsTextView.setVisibility(View.VISIBLE);
+
+ // Set the text of the import button to be `Decrypt`.
+ importExportButton.setText(R.string.decrypt);
+
+ // Disable the import/export button. The user needs to select a file to import first.
+ importExportButton.setEnabled(false);
+ } else if (exportRadioButton.isChecked()) {
+ // Hide the file name linear layout and the OpenKeychain import instructions.
+ fileNameLinearLayout.setVisibility(View.GONE);
+ openKeychainImportInstructionsTextView.setVisibility(View.GONE);
+
+ // Enable the import/export button.
+ importExportButton.setEnabled(true);
+ }
+ } else { // OpenKeychain is not installed.
+ // Show the OpenPGP required layout item.
+ openKeychainRequiredTextView.setVisibility(View.VISIBLE);
+
+ // Hide the file location card.
+ fileLocationCardView.setVisibility(View.GONE);
+ }
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+
+ }
+ });
+
+ // Update the status of the import/export button when the password changes.
+ encryptionPasswordEditText.addTextChangedListener(new TextWatcher() {