+ encryptionSpinner = findViewById(R.id.encryption_spinner);
+ encryptionPasswordTextInputLayout = findViewById(R.id.encryption_password_textinputlayout);
+ encryptionPasswordEditText = findViewById(R.id.encryption_password_edittext);
+ kitKatPasswordEncryptionTextView = findViewById(R.id.kitkat_password_encryption_textview);
+ openKeychainRequiredTextView = findViewById(R.id.openkeychain_required_textview);
+ fileLocationCardView = findViewById(R.id.file_location_cardview);
+ importRadioButton = findViewById(R.id.import_radiobutton);
+ RadioButton exportRadioButton = findViewById(R.id.export_radiobutton);
+ fileNameLinearLayout = findViewById(R.id.file_name_linearlayout);
+ fileNameEditText = findViewById(R.id.file_name_edittext);
+ openKeychainImportInstructionsTextView = findViewById(R.id.openkeychain_import_instructions_textview);
+ importExportButton = findViewById(R.id.import_export_button);
+
+ // 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);
+
+ // 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.
+ encryptionPasswordTextInputLayout.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);
+ }
+
+ // Enable the import/export button if the file name is populated.
+ 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.
+ encryptionPasswordTextInputLayout.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);
+ }
+
+ // Enable the import/button if both the password and the file name are populated.
+ importExportButton.setEnabled(!fileNameEditText.getText().toString().isEmpty() && !encryptionPasswordEditText.getText().toString().isEmpty());
+ }
+ break;
+
+ case OPENPGP_ENCRYPTION:
+ // Hide the password encryption layout items.
+ encryptionPasswordTextInputLayout.setVisibility(View.GONE);
+ kitKatPasswordEncryptionTextView.setVisibility(View.GONE);
+
+ // Updated items based on the installation status of OpenKeychain.
+ if (openKeychainInstalled) { // OpenKeychain is installed.
+ // 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);
+
+ // Enable the import button if the file name is populated.
+ importExportButton.setEnabled(!fileNameEditText.getText().toString().isEmpty());
+ } 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 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() {