Remove use of SingleServerProfile.
* changes
+ mv SingleServerEditor.java VpnProfileEditor.java
+ Add loadExtraPreferecesTo() to VpnProfileEditor
+ Make L2tpIpsecEditor extend VpnProfileEditor and use loadExtraPreferencesTo()
+ Modify VpnEditor.getEditor() accordingly
diff --git a/src/com/android/settings/vpn/L2tpIpsecEditor.java b/src/com/android/settings/vpn/L2tpIpsecEditor.java
index 5156989..2dee92e 100644
--- a/src/com/android/settings/vpn/L2tpIpsecEditor.java
+++ b/src/com/android/settings/vpn/L2tpIpsecEditor.java
@@ -29,7 +29,7 @@
/**
* The class for editing {@link L2tpIpsecProfile}.
*/
-class L2tpIpsecEditor extends SingleServerEditor {
+class L2tpIpsecEditor extends VpnProfileEditor {
private static final String TAG = L2tpIpsecEditor.class.getSimpleName();
private ListPreference mUserCertificate;
@@ -43,17 +43,15 @@
mProfile = p;
}
- //@Override
- public void loadPreferencesTo(PreferenceGroup subsettings) {
- super.loadPreferencesTo(subsettings);
- Context c = subsettings.getContext();
- subsettings.addPreference(createUserkeyPreference(c));
- subsettings.addPreference(createUserCertificatePreference(c));
- subsettings.addPreference(createCaCertificatePreference(c));
- subsettings.addPreference(createDomainSufficesPreference(c));
+ @Override
+ protected void loadExtraPreferencesTo(PreferenceGroup subpanel) {
+ Context c = subpanel.getContext();
+ subpanel.addPreference(createUserkeyPreference(c));
+ subpanel.addPreference(createUserCertificatePreference(c));
+ subpanel.addPreference(createCaCertificatePreference(c));
}
- //@Override
+ @Override
public String validate(Context c) {
String result = super.validate(c);
if (result != null) {
diff --git a/src/com/android/settings/vpn/SingleServerEditor.java b/src/com/android/settings/vpn/SingleServerEditor.java
deleted file mode 100644
index a7848e0..0000000
--- a/src/com/android/settings/vpn/SingleServerEditor.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.vpn;
-
-import com.android.settings.R;
-
-import android.content.Context;
-import android.net.vpn.SingleServerProfile;
-import android.net.vpn.VpnProfile;
-import android.preference.EditTextPreference;
-import android.preference.Preference;
-import android.preference.PreferenceGroup;
-
-/**
- * The class for editing {@link SingleServerProfile}.
- */
-class SingleServerEditor implements VpnProfileEditor {
- private EditTextPreference mServerName;
- private EditTextPreference mDomainSuffices;
- private SingleServerProfile mProfile;
-
- public SingleServerEditor(SingleServerProfile p) {
- mProfile = p;
- }
-
- //@Override
- public VpnProfile getProfile() {
- return mProfile;
- }
-
- //@Override
- public void loadPreferencesTo(PreferenceGroup subpanel) {
- Context c = subpanel.getContext();
- subpanel.addPreference(createServerNamePreference(c));
- }
-
- //@Override
- public String validate(Context c) {
- return (Util.isNullOrEmpty(mServerName.getText())
- ? c.getString(R.string.vpn_error_server_name_empty)
- : null);
- }
-
- /**
- * Creates a preference for users to input domain suffices.
- */
- protected EditTextPreference createDomainSufficesPreference(Context c) {
- EditTextPreference pref = mDomainSuffices = new EditTextPreference(c);
- pref.setTitle(R.string.vpn_dns_search_list_title);
- pref.setDialogTitle(R.string.vpn_dns_search_list_title);
- pref.setPersistent(true);
- pref.setText(mProfile.getDomainSuffices());
- pref.setSummary(mProfile.getDomainSuffices());
- pref.setOnPreferenceChangeListener(
- new Preference.OnPreferenceChangeListener() {
- public boolean onPreferenceChange(
- Preference pref, Object newValue) {
- String v = ((String) newValue).trim();
- mProfile.setDomainSuffices(v);
- pref.setSummary(checkNull(v, pref.getContext()));
- return true;
- }
- });
- return pref;
- }
-
- private Preference createServerNamePreference(Context c) {
- EditTextPreference serverName = mServerName = new EditTextPreference(c);
- String title = c.getString(R.string.vpn_server_name_title);
- serverName.setTitle(title);
- serverName.setDialogTitle(title);
- serverName.setSummary(checkNull(mProfile.getServerName(), c));
- serverName.setText(mProfile.getServerName());
- serverName.setPersistent(true);
- serverName.setOnPreferenceChangeListener(
- new Preference.OnPreferenceChangeListener() {
- public boolean onPreferenceChange(
- Preference pref, Object newValue) {
- String v = ((String) newValue).trim();
- mProfile.setServerName(v);
- pref.setSummary(checkNull(v, pref.getContext()));
- return true;
- }
- });
- return mServerName;
- }
-
-
- String checkNull(String value, Context c) {
- return ((value != null && value.length() > 0)
- ? value
- : c.getString(R.string.vpn_not_set));
- }
-}
diff --git a/src/com/android/settings/vpn/VpnEditor.java b/src/com/android/settings/vpn/VpnEditor.java
index a37b335..35c91ee 100644
--- a/src/com/android/settings/vpn/VpnEditor.java
+++ b/src/com/android/settings/vpn/VpnEditor.java
@@ -158,10 +158,8 @@
private VpnProfileEditor getEditor(VpnProfile p) {
if (p instanceof L2tpIpsecProfile) {
return new L2tpIpsecEditor((L2tpIpsecProfile) p);
- } else if (p instanceof SingleServerProfile) {
- return new SingleServerEditor((SingleServerProfile) p);
} else {
- throw new RuntimeException("Unknown profile type: " + p.getType());
+ return new VpnProfileEditor(p);
}
}
diff --git a/src/com/android/settings/vpn/VpnProfileEditor.java b/src/com/android/settings/vpn/VpnProfileEditor.java
index 686e513..a245263 100644
--- a/src/com/android/settings/vpn/VpnProfileEditor.java
+++ b/src/com/android/settings/vpn/VpnProfileEditor.java
@@ -16,20 +16,48 @@
package com.android.settings.vpn;
+import com.android.settings.R;
+
import android.content.Context;
import android.net.vpn.VpnProfile;
+import android.preference.EditTextPreference;
+import android.preference.Preference;
import android.preference.PreferenceGroup;
/**
- * The interface to set up preferences for editing a {@link VpnProfile}.
+ * The common class for editing {@link VpnProfile}.
*/
-public interface VpnProfileEditor {
- VpnProfile getProfile();
+class VpnProfileEditor {
+ private EditTextPreference mServerName;
+ private EditTextPreference mDomainSuffices;
+ private VpnProfile mProfile;
+
+ public VpnProfileEditor(VpnProfile p) {
+ mProfile = p;
+ }
+
+ //@Override
+ public VpnProfile getProfile() {
+ return mProfile;
+ }
/**
- * Adds the preferences to the panel.
+ * Adds the preferences to the panel. Subclasses should override
+ * {@link #loadExtraPreferencesTo(PreferenceGroup)} instead of this method.
*/
- void loadPreferencesTo(PreferenceGroup subpanel);
+ public void loadPreferencesTo(PreferenceGroup subpanel) {
+ Context c = subpanel.getContext();
+ subpanel.addPreference(createServerNamePreference(c));
+ loadExtraPreferencesTo(subpanel);
+ subpanel.addPreference(createDomainSufficesPreference(c));
+ }
+
+ /**
+ * Adds the extra preferences to the panel. Subclasses should add
+ * additional preferences in this method.
+ */
+ protected void loadExtraPreferencesTo(PreferenceGroup subpanel) {
+ }
/**
* Validates the inputs in the preferences.
@@ -37,5 +65,60 @@
* @return an error message that is ready to be displayed in a dialog; or
* null if all the inputs are valid
*/
- String validate(Context c);
+ public String validate(Context c) {
+ return (Util.isNullOrEmpty(mServerName.getText())
+ ? c.getString(R.string.vpn_error_server_name_empty)
+ : null);
+ }
+
+ /**
+ * Creates a preference for users to input domain suffices.
+ */
+ protected EditTextPreference createDomainSufficesPreference(Context c) {
+ EditTextPreference pref = mDomainSuffices = new EditTextPreference(c);
+ pref.setTitle(R.string.vpn_dns_search_list_title);
+ pref.setDialogTitle(R.string.vpn_dns_search_list_title);
+ pref.setPersistent(true);
+ pref.setText(mProfile.getDomainSuffices());
+ pref.setSummary(mProfile.getDomainSuffices());
+ pref.setOnPreferenceChangeListener(
+ new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(
+ Preference pref, Object newValue) {
+ String v = ((String) newValue).trim();
+ mProfile.setDomainSuffices(v);
+ pref.setSummary(checkNull(v, pref.getContext()));
+ return true;
+ }
+ });
+ return pref;
+ }
+
+ private Preference createServerNamePreference(Context c) {
+ EditTextPreference serverName = mServerName = new EditTextPreference(c);
+ String title = c.getString(R.string.vpn_server_name_title);
+ serverName.setTitle(title);
+ serverName.setDialogTitle(title);
+ serverName.setSummary(checkNull(mProfile.getServerName(), c));
+ serverName.setText(mProfile.getServerName());
+ serverName.setPersistent(true);
+ serverName.setOnPreferenceChangeListener(
+ new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(
+ Preference pref, Object newValue) {
+ String v = ((String) newValue).trim();
+ mProfile.setServerName(v);
+ pref.setSummary(checkNull(v, pref.getContext()));
+ return true;
+ }
+ });
+ return mServerName;
+ }
+
+
+ String checkNull(String value, Context c) {
+ return ((value != null && value.length() > 0)
+ ? value
+ : c.getString(R.string.vpn_not_set));
+ }
}