diff options
author | Daisuke Miyakawa <dmiyakawa@google.com> | 2010-09-10 18:04:02 -0700 |
---|---|---|
committer | Daisuke Miyakawa <dmiyakawa@google.com> | 2010-09-15 16:48:25 -0700 |
commit | b5647c5720ab65a72de7744fb1e7ec7e6dec0b12 (patch) | |
tree | 000b9ae581cac4b20eb2b522af86f9772f004c88 /src | |
parent | 1b31dc029daacfb21cbb288ede39dd9aa9213190 (diff) | |
download | packages_apps_Settings-b5647c5720ab65a72de7744fb1e7ec7e6dec0b12.zip packages_apps_Settings-b5647c5720ab65a72de7744fb1e7ec7e6dec0b12.tar.gz packages_apps_Settings-b5647c5720ab65a72de7744fb1e7ec7e6dec0b12.tar.bz2 |
Fragmentize VpnSettings and relevant Activities.
Add startFragment() to SettingsFragmentPreference.
Change-Id: Ifab93b2e68892d5f6da559f337c94d62629780c8
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/Settings.java | 19 | ||||
-rw-r--r-- | src/com/android/settings/SettingsPreferenceFragment.java | 78 | ||||
-rw-r--r-- | src/com/android/settings/vpn/VpnEditor.java | 76 | ||||
-rw-r--r-- | src/com/android/settings/vpn/VpnSettings.java | 124 | ||||
-rw-r--r-- | src/com/android/settings/vpn/VpnTypeSelection.java | 16 |
5 files changed, 214 insertions, 99 deletions
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 50aa1df..cc3f7ea 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -41,7 +41,8 @@ import java.util.ArrayList; */ public class Settings extends Activity implements PreferenceFragment.OnPreferenceStartFragmentCallback, - SettingsPreferenceFragment.OnStateListener { + SettingsPreferenceFragment.OnStateListener, + SettingsPreferenceFragment.FragmentStarter { private static final boolean DBG = false; @@ -143,7 +144,9 @@ public class Settings extends Activity if (DBG) Log.d(TAG, "showFragment"); Fragment f = Fragment.instantiate(this, fragmentClass, extras); if (f instanceof SettingsPreferenceFragment) { - ((SettingsPreferenceFragment) f).setOnStateListener(this); + SettingsPreferenceFragment spf = (SettingsPreferenceFragment) f; + spf.setOnStateListener(this); + spf.setFragmentStarter(this); } mBreadCrumbs.clear(); getFragmentManager().popBackStack(BACK_STACK_PREFS, POP_BACK_STACK_INCLUSIVE); @@ -176,9 +179,17 @@ public class Settings extends Activity public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { if (DBG) Log.d(TAG, "onPreferenceStartFragment"); - Fragment f = Fragment.instantiate(this, pref.getFragment(), pref.getExtras()); + return startFragment(caller, pref.getFragment(), -1, pref.getExtras()); + } + + public boolean startFragment( + Fragment caller, String fragmentClass, int requestCode, Bundle extras) { + Fragment f = Fragment.instantiate(this, fragmentClass, extras); + caller.setTargetFragment(f, requestCode); if (f instanceof SettingsPreferenceFragment) { - ((SettingsPreferenceFragment) f).setOnStateListener(this); + SettingsPreferenceFragment spf = (SettingsPreferenceFragment) f; + spf.setOnStateListener(this); + spf.setFragmentStarter(this); } getFragmentManager().openTransaction().replace(R.id.prefs, f) .addToBackStack(BACK_STACK_PREFS).commit(); diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java index 935c72a..f41561e 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -19,6 +19,7 @@ package com.android.settings; import android.app.Activity; import android.app.Dialog; import android.app.DialogFragment; +import android.app.Fragment; import android.content.ContentResolver; import android.content.Intent; import android.content.pm.PackageManager; @@ -58,6 +59,10 @@ public class SettingsPreferenceFragment extends PreferenceFragment private SettingsDialogFragment mDialogFragment; private OnStateListener mOnStateListener; + private FragmentStarter mFragmentStarter; + + private int mResultCode = Activity.RESULT_CANCELED; + private Intent mResultData; private Button mNextButton; @@ -74,6 +79,43 @@ public class SettingsPreferenceFragment extends PreferenceFragment mOnStateListener = listener; } + /** + * Letting the class, assumed to be Fragment, start another Fragment object. + * The target Fragment object is stored in the caller Fragment using + * {@link Fragment#setTargetFragment(Fragment, int)}. The caller + * is able to obtain result code and result data via + * {@link SettingsPreferenceFragment#getResultCode()} and + * {@link SettingsPreferenceFragment#getResultData()} accordingly. + */ + interface FragmentStarter { + public boolean startFragment( + Fragment caller, String fragmentClass, int requestCode, Bundle extras); + } + + public void setFragmentStarter(FragmentStarter starter) { + mFragmentStarter = starter; + } + + @Override + public void onResume() { + super.onResume(); + + final Fragment f = getTargetFragment(); + final int requestCode = getTargetRequestCode(); + + // TargetFragment becomes invalid when this object is resumed. Notify it to + // FragmentManager. Without this code, FragmentManager wrongly take the TargetFragment + // as live, and throws IllegalStateException. + setTargetFragment(null, -1); + + if (f != null && (f instanceof SettingsPreferenceFragment)) { + final SettingsPreferenceFragment spf = (SettingsPreferenceFragment)f; + final int resultCode = spf.getResultCode(); + final Intent resultData = spf.getResultData(); + onActivityResult(requestCode, resultCode, resultData); + } + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -86,6 +128,32 @@ public class SettingsPreferenceFragment extends PreferenceFragment setupButtonBar(); } + public final void setResult(int resultCode) { + mResultCode = resultCode; + mResultData = null; + } + + public final void setResult(int resultCode, Intent data) { + mResultCode = resultCode; + mResultData = data; + } + + public final int getResultCode() { + return mResultCode; + } + + public final Intent getResultData() { + return mResultData; + } + + /* + * The name is intentionally made different from Activity#finish(), so that + * users won't misunderstand its meaning. + */ + public final void finishFragment() { + getActivity().onBackPressed(); + } + @Override public void onDestroy() { super.onDestroy(); @@ -179,6 +247,16 @@ public class SettingsPreferenceFragment extends PreferenceFragment getActivity().onBackPressed(); } + public boolean startFragment( + Fragment caller, String fragmentClass, int requestCode, Bundle extras) { + if (mFragmentStarter != null) { + return mFragmentStarter.startFragment(caller, fragmentClass, requestCode, extras); + } else { + Log.w(TAG, "FragmentStarter is not set."); + return false; + } + } + /** * Sets up Button Bar possibly required in the Fragment. Probably available only in * phones. diff --git a/src/com/android/settings/vpn/VpnEditor.java b/src/com/android/settings/vpn/VpnEditor.java index 349befb..3ab0b90 100644 --- a/src/com/android/settings/vpn/VpnEditor.java +++ b/src/com/android/settings/vpn/VpnEditor.java @@ -17,7 +17,9 @@ package com.android.settings.vpn; import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; @@ -27,22 +29,19 @@ import android.net.vpn.L2tpIpsecPskProfile; import android.net.vpn.L2tpProfile; import android.net.vpn.PptpProfile; import android.net.vpn.VpnProfile; -import android.net.vpn.VpnType; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; -import android.preference.PreferenceActivity; -import android.preference.PreferenceGroup; import android.text.TextUtils; -import android.view.KeyEvent; +import android.util.Log; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; -import android.view.View; /** * The activity class for editing a new or existing VPN profile. */ -public class VpnEditor extends PreferenceActivity { +public class VpnEditor extends SettingsPreferenceFragment { private static final int MENU_SAVE = Menu.FIRST; private static final int MENU_CANCEL = Menu.FIRST + 1; private static final int CONFIRM_DIALOG_ID = 0; @@ -56,59 +55,75 @@ public class VpnEditor extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - VpnProfile p = (VpnProfile) ((savedInstanceState == null) - ? getIntent().getParcelableExtra(VpnSettings.KEY_VPN_PROFILE) - : savedInstanceState.getParcelable(KEY_PROFILE)); - mProfileEditor = getEditor(p); - mAddingProfile = TextUtils.isEmpty(p.getName()); // Loads the XML preferences file addPreferencesFromResource(R.xml.vpn_edit); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + VpnProfile p; + if (savedInstanceState != null) { + p = (VpnProfile)savedInstanceState.getParcelable(KEY_PROFILE); + } else { + p = (VpnProfile)getArguments().getParcelable(VpnSettings.KEY_VPN_PROFILE); + if (p == null) { + p = getActivity().getIntent().getParcelableExtra(VpnSettings.KEY_VPN_PROFILE); + } + } + + mProfileEditor = getEditor(p); + mAddingProfile = TextUtils.isEmpty(p.getName()); initViewFor(p); Parcel parcel = Parcel.obtain(); p.writeToParcel(parcel, 0); mOriginalProfileData = parcel.marshall(); + + registerForContextMenu(getListView()); + setHasOptionsMenu(true); } @Override - protected synchronized void onSaveInstanceState(Bundle outState) { + public synchronized void onSaveInstanceState(Bundle outState) { if (mProfileEditor == null) return; outState.putParcelable(KEY_PROFILE, getProfile()); } @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); menu.add(0, MENU_SAVE, 0, R.string.vpn_menu_done) .setIcon(android.R.drawable.ic_menu_save); menu.add(0, MENU_CANCEL, 0, mAddingProfile ? R.string.vpn_menu_cancel : R.string.vpn_menu_revert) .setIcon(android.R.drawable.ic_menu_close_clear_cancel); - return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_SAVE: - if (validateAndSetResult()) finish(); + if (validateAndSetResult()) finishFragment(); return true; case MENU_CANCEL: if (profileChanged()) { showDialog(CONFIRM_DIALOG_ID); } else { - finish(); + finishFragment(); } return true; } return super.onOptionsItemSelected(item); } + /* @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { @@ -117,7 +132,7 @@ public class VpnEditor extends PreferenceActivity { return true; } return super.onKeyDown(keyCode, event); - } + }*/ private void initViewFor(VpnProfile profile) { setTitle(profile); @@ -125,10 +140,11 @@ public class VpnEditor extends PreferenceActivity { } private void setTitle(VpnProfile profile) { + final Activity activity = getActivity(); String formatString = mAddingProfile - ? getString(R.string.vpn_edit_title_add) - : getString(R.string.vpn_edit_title_edit); - setTitle(String.format(formatString, + ? activity.getString(R.string.vpn_edit_title_add) + : activity.getString(R.string.vpn_edit_title_edit); + activity.setTitle(String.format(formatString, profile.getType().getDisplayName())); } @@ -140,7 +156,7 @@ public class VpnEditor extends PreferenceActivity { String errorMsg = mProfileEditor.validate(); if (errorMsg != null) { - Util.showErrorMessage(this, errorMsg); + Util.showErrorMessage(getActivity(), errorMsg); return false; } @@ -149,9 +165,9 @@ public class VpnEditor extends PreferenceActivity { } private void setResult(VpnProfile p) { - Intent intent = new Intent(this, VpnSettings.class); + Intent intent = new Intent(getActivity(), VpnSettings.class); intent.putExtra(VpnSettings.KEY_VPN_PROFILE, (Parcelable) p); - setResult(RESULT_OK, intent); + setResult(Activity.RESULT_OK, intent); } private VpnProfileEditor getEditor(VpnProfile p) { @@ -175,10 +191,9 @@ public class VpnEditor extends PreferenceActivity { @Override - protected Dialog onCreateDialog(int id) { - + public Dialog onCreateDialog(int id) { if (id == CONFIRM_DIALOG_ID) { - return new AlertDialog.Builder(this) + return new AlertDialog.Builder(getActivity()) .setTitle(android.R.string.dialog_alert_title) .setIcon(android.R.drawable.ic_dialog_alert) .setMessage(mAddingProfile @@ -187,7 +202,7 @@ public class VpnEditor extends PreferenceActivity { .setPositiveButton(R.string.vpn_yes_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int w) { - finish(); + finishFragment(); } }) .setNegativeButton(R.string.vpn_mistake_button, null) @@ -197,8 +212,9 @@ public class VpnEditor extends PreferenceActivity { return super.onCreateDialog(id); } + /* @Override - protected void onPrepareDialog(int id, Dialog dialog) { + public void onPrepareDialog(int id, Dialog dialog) { super.onPrepareDialog(id, dialog); if (id == CONFIRM_DIALOG_ID) { @@ -206,7 +222,7 @@ public class VpnEditor extends PreferenceActivity { ? getString(R.string.vpn_confirm_add_profile_cancellation) : getString(R.string.vpn_confirm_edit_profile_cancellation)); } - } + }*/ private VpnProfile getProfile() { return mProfileEditor.getProfile(); diff --git a/src/com/android/settings/vpn/VpnSettings.java b/src/com/android/settings/vpn/VpnSettings.java index 7b8d433..e9a4c3d 100644 --- a/src/com/android/settings/vpn/VpnSettings.java +++ b/src/com/android/settings/vpn/VpnSettings.java @@ -17,11 +17,14 @@ package com.android.settings.vpn; import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.content.ComponentName; +import android.app.Fragment; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -37,12 +40,10 @@ import android.net.vpn.VpnType; import android.os.Bundle; import android.os.ConditionVariable; import android.os.IBinder; -import android.os.Parcelable; import android.preference.Preference; -import android.preference.PreferenceActivity; +import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceCategory; import android.preference.PreferenceScreen; -import android.preference.Preference.OnPreferenceClickListener; import android.security.Credentials; import android.security.KeyStore; import android.text.TextUtils; @@ -69,8 +70,8 @@ import java.util.Map; /** * The preference activity for configuring VPN settings. */ -public class VpnSettings extends PreferenceActivity implements - DialogInterface.OnClickListener { +public class VpnSettings extends SettingsPreferenceFragment + implements DialogInterface.OnClickListener { // Key to the field exchanged for profile editing. static final String KEY_VPN_PROFILE = "vpn_profile"; @@ -122,7 +123,7 @@ public class VpnSettings extends PreferenceActivity implements private KeyStore mKeyStore = KeyStore.getInstance(); - private VpnManager mVpnManager = new VpnManager(this); + private VpnManager mVpnManager; private ConnectivityReceiver mConnectivityReceiver = new ConnectivityReceiver(); @@ -137,7 +138,13 @@ public class VpnSettings extends PreferenceActivity implements public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.vpn_settings); + } + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mVpnManager = new VpnManager(getActivity()); // restore VpnProfile list and construct VpnPreference map mVpnListContainer = (PreferenceCategory) findPreference(PREF_VPN_LIST); @@ -168,22 +175,24 @@ public class VpnSettings extends PreferenceActivity implements if ((mUnlockAction != null) && isKeyStoreUnlocked()) { Runnable action = mUnlockAction; mUnlockAction = null; - runOnUiThread(action); + getActivity().runOnUiThread(action); } } @Override - protected void onDestroy() { - super.onDestroy(); + public void onDestroyView() { unregisterForContextMenu(getListView()); mVpnManager.unregisterConnectivityReceiver(mConnectivityReceiver); if ((mShowingDialog != null) && mShowingDialog.isShowing()) { mShowingDialog.dismiss(); } + // This should be called after the procedure above as ListView inside this Fragment + // will be deleted here. + super.onDestroyView(); } @Override - protected Dialog onCreateDialog (int id) { + public Dialog onCreateDialog (int id) { switch (id) { case DIALOG_CONNECT: return createConnectDialog(); @@ -203,13 +212,14 @@ public class VpnSettings extends PreferenceActivity implements } private Dialog createConnectDialog() { - return new AlertDialog.Builder(this) + final Activity activity = getActivity(); + return new AlertDialog.Builder(activity) .setView(mConnectingActor.createConnectView()) - .setTitle(String.format(getString(R.string.vpn_connect_to), + .setTitle(String.format(activity.getString(R.string.vpn_connect_to), mActiveProfile.getName())) - .setPositiveButton(getString(R.string.vpn_connect_button), + .setPositiveButton(activity.getString(R.string.vpn_connect_button), this) - .setNegativeButton(getString(android.R.string.cancel), + .setNegativeButton(activity.getString(android.R.string.cancel), this) .setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { @@ -291,7 +301,7 @@ public class VpnSettings extends PreferenceActivity implements } private AlertDialog.Builder createCommonDialogBuilder() { - return new AlertDialog.Builder(this) + return new AlertDialog.Builder(getActivity()) .setTitle(android.R.string.dialog_alert_title) .setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(R.string.vpn_yes_button, @@ -364,9 +374,9 @@ public class VpnSettings extends PreferenceActivity implements } @Override - protected void onActivityResult(final int requestCode, final int resultCode, + public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { - if ((resultCode == RESULT_CANCELED) || (data == null)) { + if ((resultCode == Activity.RESULT_CANCELED) || (data == null)) { Log.d(TAG, "no result returned by editor"); return; } @@ -381,11 +391,12 @@ public class VpnSettings extends PreferenceActivity implements return; } + final Activity activity = getActivity(); int index = getProfileIndexFromId(p.getId()); if (checkDuplicateName(p, index)) { final VpnProfile profile = p; - Util.showErrorMessage(this, String.format( - getString(R.string.vpn_error_duplicate_name), + Util.showErrorMessage(activity, String.format( + activity.getString(R.string.vpn_error_duplicate_name), p.getName()), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int w) { @@ -407,30 +418,32 @@ public class VpnSettings extends PreferenceActivity implements try { if (index < 0) { addProfile(p); - Util.showShortToastMessage(this, String.format( - getString(R.string.vpn_profile_added), p.getName())); + Util.showShortToastMessage(activity, String.format( + activity.getString(R.string.vpn_profile_added), p.getName())); } else { replaceProfile(index, p); - Util.showShortToastMessage(this, String.format( - getString(R.string.vpn_profile_replaced), + Util.showShortToastMessage(activity, String.format( + activity.getString(R.string.vpn_profile_replaced), p.getName())); } } catch (IOException e) { final VpnProfile profile = p; - Util.showErrorMessage(this, e + ": " + e.getMessage(), + Util.showErrorMessage(activity, e + ": " + e.getMessage(), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int w) { startVpnEditor(profile); } }); } + + // Remove cached VpnEditor as it is needless anymore. } else { throw new RuntimeException("unknown request code: " + requestCode); } } // Called when the buttons on the connect dialog are clicked. - //@Override + @Override public synchronized void onClick(DialogInterface dialog, int which) { if (which == CONNECT_BUTTON) { Dialog d = (Dialog) dialog; @@ -440,12 +453,15 @@ public class VpnSettings extends PreferenceActivity implements removeDialog(DIALOG_CONNECT); return; } else { - dismissDialog(DIALOG_CONNECT); + // dismissDialog(DIALOG_CONNECT); + removeDialog(DIALOG_CONNECT); + + final Activity activity = getActivity(); // show error dialog - mShowingDialog = new AlertDialog.Builder(this) + mShowingDialog = new AlertDialog.Builder(activity) .setTitle(android.R.string.dialog_alert_title) .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(String.format(getString( + .setMessage(String.format(activity.getString( R.string.vpn_error_miss_entering), error)) .setPositiveButton(R.string.vpn_back_button, new DialogInterface.OnClickListener() { @@ -513,7 +529,7 @@ public class VpnSettings extends PreferenceActivity implements } } }; - mShowingDialog = new AlertDialog.Builder(this) + mShowingDialog = new AlertDialog.Builder(getActivity()) .setTitle(android.R.string.dialog_alert_title) .setIcon(android.R.drawable.ic_dialog_alert) .setMessage(R.string.vpn_confirm_profile_deletion) @@ -559,7 +575,7 @@ public class VpnSettings extends PreferenceActivity implements // Adds a preference in mVpnListContainer private VpnPreference addPreferenceFor( VpnProfile p, boolean addToContainer) { - VpnPreference pref = new VpnPreference(this, p); + VpnPreference pref = new VpnPreference(getActivity(), p); mVpnPreferenceMap.put(p.getName(), pref); if (addToContainer) mVpnListContainer.addPreference(pref); @@ -599,8 +615,8 @@ public class VpnSettings extends PreferenceActivity implements } private void startVpnTypeSelection() { - Intent intent = new Intent(this, VpnTypeSelection.class); - startActivityForResult(intent, REQUEST_SELECT_VPN_TYPE); + startFragment(this, VpnTypeSelection.class.getCanonicalName(), + REQUEST_SELECT_VPN_TYPE, null); } private boolean isKeyStoreUnlocked() { @@ -614,16 +630,14 @@ public class VpnSettings extends PreferenceActivity implements L2tpIpsecPskProfile pskProfile = (L2tpIpsecPskProfile) p; String presharedKey = pskProfile.getPresharedKey(); if (!TextUtils.isEmpty(presharedKey)) return true; - // pass through - + // $FALL-THROUGH$ case L2TP: L2tpProfile l2tpProfile = (L2tpProfile) p; if (l2tpProfile.isSecretEnabled() && !TextUtils.isEmpty(l2tpProfile.getSecretString())) { return true; } - // pass through - + // $FALL-THROUGH$ default: return false; } @@ -648,14 +662,15 @@ public class VpnSettings extends PreferenceActivity implements private boolean unlockKeyStore(VpnProfile p, Runnable action) { if (isKeyStoreUnlocked()) return true; mUnlockAction = action; - Credentials.getInstance().unlock(this); + Credentials.getInstance().unlock(getActivity()); return false; } private void startVpnEditor(final VpnProfile profile) { - Intent intent = new Intent(this, VpnEditor.class); - intent.putExtra(KEY_VPN_PROFILE, (Parcelable) profile); - startActivityForResult(intent, REQUEST_ADD_OR_EDIT_PROFILE); + Bundle args = new Bundle(); + args.putParcelable(KEY_VPN_PROFILE, profile); + startFragment(this, VpnEditor.class.getCanonicalName(), + REQUEST_ADD_OR_EDIT_PROFILE, args); } private synchronized void connect(final VpnProfile p) { @@ -714,7 +729,7 @@ public class VpnSettings extends PreferenceActivity implements case CONNECTING: mConnectingActor = getActor(p); - // pass through + // $FALL-THROUGH$ case DISCONNECTING: mActiveProfile = p; disableProfilePreferencesIfOneActive(); @@ -810,11 +825,6 @@ public class VpnSettings extends PreferenceActivity implements public int compare(VpnProfile p1, VpnProfile p2) { return p1.getName().compareTo(p2.getName()); } - - public boolean equals(VpnProfile p) { - // not used - return false; - } }); for (VpnProfile p : mVpnProfileList) { Preference pref = addPreferenceFor(p, false); @@ -855,20 +865,21 @@ public class VpnSettings extends PreferenceActivity implements } private String getProfileSummaryString(VpnProfile p) { + final Activity activity = getActivity(); switch (p.getState()) { case CONNECTING: - return getString(R.string.vpn_connecting); + return activity.getString(R.string.vpn_connecting); case DISCONNECTING: - return getString(R.string.vpn_disconnecting); + return activity.getString(R.string.vpn_disconnecting); case CONNECTED: - return getString(R.string.vpn_connected); + return activity.getString(R.string.vpn_connected); default: - return getString(R.string.vpn_connect_hint); + return activity.getString(R.string.vpn_connect_hint); } } private VpnProfileActor getActor(VpnProfile p) { - return new AuthenticationActor(this, p); + return new AuthenticationActor(getActivity(), p); } private VpnProfile createVpnProfile(String type) { @@ -938,8 +949,7 @@ public class VpnSettings extends PreferenceActivity implements Log.e(TAG, "keystore write failed: key=" + key); } pskProfile.setPresharedKey(key); - // pass through - + // $FALL-THROUGH$ case L2TP_IPSEC: case L2TP: L2tpProfile l2tpProfile = (L2tpProfile) p; @@ -1007,8 +1017,6 @@ public class VpnSettings extends PreferenceActivity implements // managing status check in a background thread private class StatusChecker { - private List<VpnProfile> mList; - synchronized void check(final List<VpnProfile> list) { final ConditionVariable cv = new ConditionVariable(); cv.close(); @@ -1027,7 +1035,7 @@ public class VpnSettings extends PreferenceActivity implements changeState(p, VpnState.IDLE); } } - VpnSettings.this.unbindService(this); + getActivity().unbindService(this); showPreferences(); } @@ -1035,7 +1043,7 @@ public class VpnSettings extends PreferenceActivity implements cv.open(); setDefaultState(list); - VpnSettings.this.unbindService(this); + getActivity().unbindService(this); showPreferences(); } }; diff --git a/src/com/android/settings/vpn/VpnTypeSelection.java b/src/com/android/settings/vpn/VpnTypeSelection.java index aa4bc5e..5990ac0 100644 --- a/src/com/android/settings/vpn/VpnTypeSelection.java +++ b/src/com/android/settings/vpn/VpnTypeSelection.java @@ -17,13 +17,14 @@ package com.android.settings.vpn; import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import android.app.Activity; import android.content.Intent; import android.net.vpn.VpnManager; import android.net.vpn.VpnType; import android.os.Bundle; import android.preference.Preference; -import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; import java.util.HashMap; @@ -32,7 +33,7 @@ import java.util.Map; /** * The activity to select a VPN type. */ -public class VpnTypeSelection extends PreferenceActivity { +public class VpnTypeSelection extends SettingsPreferenceFragment { private Map<String, VpnType> mTypeMap = new HashMap<String, VpnType>(); @Override @@ -46,19 +47,20 @@ public class VpnTypeSelection extends PreferenceActivity { @Override public boolean onPreferenceTreeClick(PreferenceScreen ps, Preference pref) { setResult(mTypeMap.get(pref.getTitle().toString())); - finish(); + finishFragment(); return true; } private void initTypeList() { PreferenceScreen root = getPreferenceScreen(); + final Activity activity = getActivity(); for (VpnType t : VpnManager.getSupportedVpnTypes()) { String displayName = t.getDisplayName(); String message = String.format( - getString(R.string.vpn_edit_title_add), displayName); + activity.getString(R.string.vpn_edit_title_add), displayName); mTypeMap.put(message, t); - Preference pref = new Preference(this); + Preference pref = new Preference(activity); pref.setTitle(message); pref.setSummary(t.getDescriptionId()); root.addPreference(pref); @@ -66,8 +68,8 @@ public class VpnTypeSelection extends PreferenceActivity { } private void setResult(VpnType type) { - Intent intent = new Intent(this, VpnSettings.class); + Intent intent = new Intent(getActivity(), VpnSettings.class); intent.putExtra(VpnSettings.KEY_VPN_TYPE, type.toString()); - setResult(RESULT_OK, intent); + setResult(Activity.RESULT_OK, intent); } } |