From cf3561da5cb9a15fca4bc13c2c1b003b1b10b0e0 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Sun, 27 Jul 2014 00:59:28 -0400 Subject: [PATCH] Trigger certificate chooser when check box checked For convenience. Implemented in onCheckChanged(). As a consequence, onCheckChanged() must not be triggered when the instance state is restored (would occur if the check box state was checked when saved), otherwise the certificate chooser would pop up once the state was restored. Therefore, all listeners have been moved into initializeViewListeners() which is invoked after the state has been restored. Because onCheckChanged() is no longer triggered in onRestoreInstanceState(), updateViewVisibility() was implemented to restore the view visibility. --- .../k9/activity/setup/AccountSetupBasics.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java index 4d5e99ab6..d230d423b 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java @@ -87,18 +87,19 @@ public class AccountSetupBasics extends K9Activity mNextButton.setOnClickListener(this); mManualSetupButton.setOnClickListener(this); + if (savedInstanceState == null) { + initializeViewListeners(); + validateFields(); + } + } + + private void initializeViewListeners() { mEmailView.addTextChangedListener(this); mPasswordView.addTextChangedListener(this); mClientCertificateCheckBox.setOnCheckedChangeListener(this); mClientCertificateSpinner.setOnClientCertificateChangedListener(this); } - @Override - public void onResume() { - super.onResume(); - validateFields(); - } - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -125,6 +126,18 @@ public class AccountSetupBasics extends K9Activity } mCheckedIncoming = savedInstanceState.getBoolean(STATE_KEY_CHECKED_INCOMING); + + updateViewVisibility(mClientCertificateCheckBox.isChecked()); + + /* + * We wait until now to initialize the listeners because we didn't want + * the OnCheckedChangeListener active while the + * mClientCertificateCheckBox state was being restored because it could + * trigger the pop-up of a ClientCertificateSpinner.chooseCertificate() + * dialog. + */ + initializeViewListeners(); + validateFields(); } public void afterTextChanged(Editable s) { @@ -147,7 +160,17 @@ public class AccountSetupBasics extends K9Activity */ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + updateViewVisibility(isChecked); + validateFields(); + + // Have the user select (or confirm) the client certificate if (isChecked) { + mClientCertificateSpinner.chooseCertificate(); + } + } + + private void updateViewVisibility(boolean usingCertificates) { + if (usingCertificates) { // hide password fields, show client certificate spinner mPasswordView.setVisibility(View.GONE); mClientCertificateSpinner.setVisibility(View.VISIBLE); @@ -156,7 +179,6 @@ public class AccountSetupBasics extends K9Activity mPasswordView.setVisibility(View.VISIBLE); mClientCertificateSpinner.setVisibility(View.GONE); } - validateFields(); } private void validateFields() {