Restore Vpn advanced options on re-init or rotate

Visibility isn't restored as part of instance state by default.

Bug: 22183281
Change-Id: I86a7165e918251bc32f6884b9ad5f9c5987ca075
This commit is contained in:
Robin Lee
2015-07-01 19:10:22 -07:00
parent 66b5a58a68
commit 6f4951a1fa

View File

@@ -71,6 +71,7 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
private Spinner mIpsecCaCert; private Spinner mIpsecCaCert;
private Spinner mIpsecServerCert; private Spinner mIpsecServerCert;
private CheckBox mSaveLogin; private CheckBox mSaveLogin;
private CheckBox mShowOptions;
ConfigDialog(Context context, DialogInterface.OnClickListener listener, ConfigDialog(Context context, DialogInterface.OnClickListener listener,
VpnProfile profile, boolean editing, boolean exists) { VpnProfile profile, boolean editing, boolean exists) {
@@ -106,6 +107,7 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
mIpsecCaCert = (Spinner) mView.findViewById(R.id.ipsec_ca_cert); mIpsecCaCert = (Spinner) mView.findViewById(R.id.ipsec_ca_cert);
mIpsecServerCert = (Spinner) mView.findViewById(R.id.ipsec_server_cert); mIpsecServerCert = (Spinner) mView.findViewById(R.id.ipsec_server_cert);
mSaveLogin = (CheckBox) mView.findViewById(R.id.save_login); mSaveLogin = (CheckBox) mView.findViewById(R.id.save_login);
mShowOptions = (CheckBox) mView.findViewById(R.id.show_options);
// Second, copy values from the profile. // Second, copy values from the profile.
mName.setText(mProfile.name); mName.setText(mProfile.name);
@@ -140,8 +142,9 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
mRoutes.addTextChangedListener(this); mRoutes.addTextChangedListener(this);
mIpsecSecret.addTextChangedListener(this); mIpsecSecret.addTextChangedListener(this);
mIpsecUserCert.setOnItemSelectedListener(this); mIpsecUserCert.setOnItemSelectedListener(this);
mShowOptions.setOnClickListener(this);
// Forth, determine to do editing or connecting. // Fourth, determine whether to do editing or connecting.
boolean valid = validate(true); boolean valid = validate(true);
mEditing = mEditing || !valid; mEditing = mEditing || !valid;
@@ -154,13 +157,10 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
// Show type-specific fields. // Show type-specific fields.
changeType(mProfile.type); changeType(mProfile.type);
// Show advanced options directly if any of them is set. // Switch to advanced view immediately if any advanced options are on
View showOptions = mView.findViewById(R.id.show_options); if (!mProfile.searchDomains.isEmpty() || !mProfile.dnsServers.isEmpty() ||
if (mProfile.searchDomains.isEmpty() && mProfile.dnsServers.isEmpty() && !mProfile.routes.isEmpty()) {
mProfile.routes.isEmpty()) { showAdvancedOptions();
showOptions.setOnClickListener(this);
} else {
onClick(showOptions);
} }
// Create a button to forget the profile if it has already been saved.. // Create a button to forget the profile if it has already been saved..
@@ -199,6 +199,17 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} }
@Override
public void onRestoreInstanceState(Bundle savedState) {
super.onRestoreInstanceState(savedState);
// Visibility isn't restored by super.onRestoreInstanceState, so re-show the advanced
// options here if they were already revealed or set.
if (mShowOptions.isChecked()) {
showAdvancedOptions();
}
}
@Override @Override
public void afterTextChanged(Editable field) { public void afterTextChanged(Editable field) {
getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing)); getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
@@ -213,9 +224,10 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
} }
@Override @Override
public void onClick(View showOptions) { public void onClick(View view) {
showOptions.setVisibility(View.GONE); if (view == mShowOptions) {
mView.findViewById(R.id.options).setVisibility(View.VISIBLE); showAdvancedOptions();
}
} }
@Override @Override
@@ -230,6 +242,11 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
public void onNothingSelected(AdapterView<?> parent) { public void onNothingSelected(AdapterView<?> parent) {
} }
private void showAdvancedOptions() {
mView.findViewById(R.id.options).setVisibility(View.VISIBLE);
mShowOptions.setVisibility(View.GONE);
}
private void changeType(int type) { private void changeType(int type) {
// First, hide everything. // First, hide everything.
mMppe.setVisibility(View.GONE); mMppe.setVisibility(View.GONE);