Merge "Purge views after they're supposed to be destroyed to avoid spurious callbacks" into jb-ub-mail-ur10

This commit is contained in:
Tony Mantler 2013-09-12 16:28:07 +00:00 committed by Android (Google) Code Review
commit 4f63f1eec1

View File

@ -82,6 +82,8 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
// Delete policy as loaded from the device // Delete policy as loaded from the device
private int mLoadedDeletePolicy; private int mLoadedDeletePolicy;
private TextWatcher mValidationTextWatcher;
// Support for lifecycle // Support for lifecycle
private boolean mStarted; private boolean mStarted;
private boolean mLoaded; private boolean mLoaded;
@ -146,7 +148,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
}); });
// After any text edits, call validateFields() which enables or disables the Next button // After any text edits, call validateFields() which enables or disables the Next button
final TextWatcher validationTextWatcher = new TextWatcher() { mValidationTextWatcher = new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
validateFields(); validateFields();
@ -162,10 +164,10 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
makeTextViewUneditable(mUsernameView, makeTextViewUneditable(mUsernameView,
getString(R.string.account_setup_username_uneditable_error)); getString(R.string.account_setup_username_uneditable_error));
} }
mUsernameView.addTextChangedListener(validationTextWatcher); mUsernameView.addTextChangedListener(mValidationTextWatcher);
mPasswordView.addTextChangedListener(validationTextWatcher); mPasswordView.addTextChangedListener(mValidationTextWatcher);
mServerView.addTextChangedListener(validationTextWatcher); mServerView.addTextChangedListener(mValidationTextWatcher);
mPortView.addTextChangedListener(validationTextWatcher); mPortView.addTextChangedListener(mValidationTextWatcher);
// Only allow digits in the port field. // Only allow digits in the port field.
mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789")); mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
@ -279,6 +281,41 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
mStarted = false; mStarted = false;
} }
@Override
public void onDestroyView() {
// Make sure we don't get callbacks after the views are supposed to be destroyed
// and also don't hold onto them longer than we need
if (mUsernameView != null) {
mUsernameView.removeTextChangedListener(mValidationTextWatcher);
}
mUsernameView = null;
if (mPasswordView != null) {
mPasswordView.removeTextChangedListener(mValidationTextWatcher);
}
mPasswordView = null;
mServerLabelView = null;
if (mServerView != null) {
mServerView.removeTextChangedListener(mValidationTextWatcher);
}
mServerView = null;
if (mPortView != null) {
mPortView.removeTextChangedListener(mValidationTextWatcher);
}
mPortView = null;
if (mSecurityTypeView != null) {
mSecurityTypeView.setOnItemSelectedListener(null);
}
mSecurityTypeView = null;
mDeletePolicyLabelView = null;
mDeletePolicyView = null;
mImapPathPrefixSectionView = null;
mDeviceIdSectionView = null;
mImapPathPrefixView = null;
mClientCertificateSelector = null;
super.onDestroyView();
}
/** /**
* Called when the fragment is no longer in use. * Called when the fragment is no longer in use.
*/ */