From bcc29632e9c2226480d2cf7372c6fa53dc815980 Mon Sep 17 00:00:00 2001 From: Andrew Chen Date: Tue, 18 Dec 2012 16:18:00 -0800 Subject: [PATCH] Disable Cryptography setup menu if APG isn't installed. --- res/values/strings.xml | 1 + .../k9/activity/setup/AccountSettings.java | 56 +++++++++---------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index cfbe215a7..012e43859 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -555,6 +555,7 @@ Please submit bug reports, contribute new features and ask questions at Use the account\'s email address to guess the signature key. Auto-encrypt Automatically set encrypt if a public key matches a recipient. + APG not installed Folder poll frequency diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java index 85cc932fb..233133200 100644 --- a/src/com/fsck/k9/activity/setup/AccountSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSettings.java @@ -108,6 +108,7 @@ public class AccountSettings extends K9PreferenceActivity { private static final String PREFERENCE_REPLY_AFTER_QUOTE = "reply_after_quote"; private static final String PREFERENCE_STRIP_SIGNATURE = "strip_signature"; private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions"; + private static final String PREFERENCE_CRYPTO = "crypto"; private static final String PREFERENCE_CRYPTO_APP = "crypto_app"; private static final String PREFERENCE_CRYPTO_AUTO_SIGNATURE = "crypto_auto_signature"; private static final String PREFERENCE_CRYPTO_AUTO_ENCRYPT = "crypto_auto_encrypt"; @@ -682,38 +683,37 @@ public class AccountSettings extends K9PreferenceActivity { } }); - mCryptoApp = (ListPreference) findPreference(PREFERENCE_CRYPTO_APP); - CharSequence cryptoAppEntries[] = mCryptoApp.getEntries(); - if (!new Apg().isAvailable(this)) { - int apgIndex = mCryptoApp.findIndexOfValue(Apg.NAME); - if (apgIndex >= 0) { - cryptoAppEntries[apgIndex] = "APG (" + getResources().getString(R.string.account_settings_crypto_app_not_available) + ")"; - mCryptoApp.setEntries(cryptoAppEntries); - } - } - mCryptoApp.setValue(String.valueOf(mAccount.getCryptoApp())); - mCryptoApp.setSummary(mCryptoApp.getEntry()); - mCryptoApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - public boolean onPreferenceChange(Preference preference, Object newValue) { - String value = newValue.toString(); - int index = mCryptoApp.findIndexOfValue(value); - mCryptoApp.setSummary(mCryptoApp.getEntries()[index]); - mCryptoApp.setValue(value); - handleCryptoAppDependencies(); - if (Apg.NAME.equals(value)) { - Apg.createInstance(null).test(AccountSettings.this); + final boolean hasCryptoAvailable = new Apg().isAvailable(this); + if (hasCryptoAvailable) { + mCryptoApp = (ListPreference) findPreference(PREFERENCE_CRYPTO_APP); + mCryptoApp.setValue(String.valueOf(mAccount.getCryptoApp())); + mCryptoApp.setSummary(mCryptoApp.getEntry()); + mCryptoApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + public boolean onPreferenceChange(Preference preference, Object newValue) { + String value = newValue.toString(); + int index = mCryptoApp.findIndexOfValue(value); + mCryptoApp.setSummary(mCryptoApp.getEntries()[index]); + mCryptoApp.setValue(value); + handleCryptoAppDependencies(); + if (Apg.NAME.equals(value)) { + Apg.createInstance(null).test(AccountSettings.this); + } + return false; } - return false; - } - }); + }); - mCryptoAutoSignature = (CheckBoxPreference) findPreference(PREFERENCE_CRYPTO_AUTO_SIGNATURE); - mCryptoAutoSignature.setChecked(mAccount.getCryptoAutoSignature()); + mCryptoAutoSignature = (CheckBoxPreference) findPreference(PREFERENCE_CRYPTO_AUTO_SIGNATURE); + mCryptoAutoSignature.setChecked(mAccount.getCryptoAutoSignature()); - mCryptoAutoEncrypt = (CheckBoxPreference) findPreference(PREFERENCE_CRYPTO_AUTO_ENCRYPT); - mCryptoAutoEncrypt.setChecked(mAccount.isCryptoAutoEncrypt()); + mCryptoAutoEncrypt = (CheckBoxPreference) findPreference(PREFERENCE_CRYPTO_AUTO_ENCRYPT); + mCryptoAutoEncrypt.setChecked(mAccount.isCryptoAutoEncrypt()); - handleCryptoAppDependencies(); + handleCryptoAppDependencies(); + } else { + final Preference mCryptoMenu = findPreference(PREFERENCE_CRYPTO); + mCryptoMenu.setEnabled(false); + mCryptoMenu.setSummary(R.string.account_settings_crypto_apg_not_installed); + } } private void handleCryptoAppDependencies() {