+ // Create an array adapter for the spinner.
+ ArrayAdapter<CharSequence> encryptionArrayAdapter = ArrayAdapter.createFromResource(this, R.array.encryption_type, R.layout.spinner_item);
+
+ // Set the drop down view resource on the spinner.
+ encryptionArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_items);
+
+ // Set the array adapter for the spinner.
+ encryptionSpinner.setAdapter(encryptionArrayAdapter);
+
+ // Instantiate the download location helper.
+ DownloadLocationHelper downloadLocationHelper = new DownloadLocationHelper();
+
+ // Get the default file path.
+ String defaultFilePath = downloadLocationHelper.getDownloadLocation(this) + "/" + getString(R.string.settings) + " " + BuildConfig.VERSION_NAME + ".pbs";
+
+ // Set the other default file paths.
+ String defaultPasswordEncryptionFilePath = defaultFilePath + ".aes";
+ String defaultPgpFilePath = defaultFilePath + ".pgp";
+
+ // Set the default file path.
+ fileNameEditText.setText(defaultFilePath);
+
+ // Hide the storage permission text view if the permission has already been granted.
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ storagePermissionTextView.setVisibility(View.GONE);
+ }
+
+ // Update the UI 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);
+ 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);
+ }
+ 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.
+ // Update the default file path.
+ fileNameEditText.setText(defaultPgpFilePath);
+
+ // 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);
+ } else if (exportRadioButton.isChecked()) {
+ // Hide the file name linear layout and the OpenKeychain import instructions.
+ fileNameLinearLayout.setVisibility(View.GONE);
+ openKeychainImportInstructionsTextView.setVisibility(View.GONE);
+ }
+ } 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;
+ }
+ }