Fragmentize wifi.AdvancedSettings.

Change-Id: I3dde2eb604886a8d0719549eabac76fadc74c220
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 130674e..a767cb4 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -105,8 +105,9 @@
                   android:screenOrientation="landscape"
                   android:exported="true" />
 
-        <activity android:name=".wifi.AdvancedSettings"
+        <activity-alias android:name=".wifi.AdvancedSettings"
                 android:label="@string/wifi_ip_settings_titlebar"
+                android:targetActivity="Settings"
                 >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -114,7 +115,7 @@
                 <category android:name="android.intent.category.VOICE_LAUNCH" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-        </activity>
+        </activity-alias>
 
         <activity android:name=".wifi.WifiInfo">
             <intent-filter>
diff --git a/src/com/android/settings/wifi/AdvancedSettings.java b/src/com/android/settings/wifi/AdvancedSettings.java
index 4b33fdc..c88073d 100644
--- a/src/com/android/settings/wifi/AdvancedSettings.java
+++ b/src/com/android/settings/wifi/AdvancedSettings.java
@@ -17,35 +17,40 @@
 package com.android.settings.wifi;
 
 import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
 
+import android.app.Activity;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
+import android.os.SystemProperties;
 import android.preference.ListPreference;
 import android.preference.Preference;
-import android.preference.PreferenceActivity;
 import android.provider.Settings;
 import android.text.TextUtils;
 import android.widget.Toast;
-import android.os.SystemProperties;
 
-public class AdvancedSettings extends PreferenceActivity
+public class AdvancedSettings extends SettingsPreferenceFragment
         implements Preference.OnPreferenceChangeListener {
 
     private static final String KEY_MAC_ADDRESS = "mac_address";
     private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
     private static final String KEY_NUM_CHANNELS = "num_channels";
     private static final String KEY_SLEEP_POLICY = "sleep_policy";
-    
+
     //Tracks ro.debuggable (1 on userdebug builds)
     private static int DEBUGGABLE;
 
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
+    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        
         addPreferencesFromResource(R.xml.wifi_advanced_settings);
-        
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+
         DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0);
 
         /**
@@ -68,9 +73,9 @@
     }
     
     @Override
-    protected void onResume() {
+    public void onResume() {
         super.onResume();
-        
+
         /**
          * Remove user control of regulatory domain
          * channel count settings in non userdebug builds
@@ -86,7 +91,7 @@
         ListPreference pref = (ListPreference) findPreference(KEY_NUM_CHANNELS);
         pref.setOnPreferenceChangeListener(this);
 
-        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
+        WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE);
         /*
          * Generate the list of valid channel counts to show in the ListPreference.
          * The values are numerical, so the only text to be localized is the
@@ -94,7 +99,7 @@
          */
         int[] validChannelCounts = wifiManager.getValidChannelCounts();
         if (validChannelCounts == null) {
-            Toast.makeText(this, R.string.wifi_setting_num_channels_error,
+            Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
                            Toast.LENGTH_SHORT).show();
             pref.setEnabled(false);
             return;
@@ -104,8 +109,8 @@
 
         for (int i = 0; i < validChannelCounts.length; i++) {
             entryValues[i] = String.valueOf(validChannelCounts[i]);
-            entries[i] = getString(R.string.wifi_setting_num_channels_channel_phrase,
-                                   validChannelCounts[i]);
+            entries[i] = getActivity().getString(R.string.wifi_setting_num_channels_channel_phrase,
+                    validChannelCounts[i]);
         }
         pref.setEntries(entries);
         pref.setEntryValues(entryValues);
@@ -131,13 +136,13 @@
         if (key.equals(KEY_NUM_CHANNELS)) {
             try {
                 int numChannels = Integer.parseInt((String) newValue);
-                WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
+                WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE);
                 if (!wifiManager.setNumAllowedChannels(numChannels, true)) {
-                    Toast.makeText(this, R.string.wifi_setting_num_channels_error,
+                    Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
                             Toast.LENGTH_SHORT).show();
                 }
             } catch (NumberFormatException e) {
-                Toast.makeText(this, R.string.wifi_setting_num_channels_error,
+                Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error,
                         Toast.LENGTH_SHORT).show();
                 return false;
             }
@@ -147,24 +152,23 @@
                 Settings.System.putInt(getContentResolver(),
                         Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue)));
             } catch (NumberFormatException e) {
-                Toast.makeText(this, R.string.wifi_setting_sleep_policy_error,
+                Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error,
                         Toast.LENGTH_SHORT).show();
                 return false;
             }
-
         }
         
         return true;
     }
 
     private void refreshWifiInfo() {
-        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
+        WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE);
         WifiInfo wifiInfo = wifiManager.getConnectionInfo();
 
         Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
         String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
         wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress 
-                : getString(R.string.status_unavailable));
+                : getActivity().getString(R.string.status_unavailable));
 
         Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
         String ipAddress = null;
@@ -178,7 +182,7 @@
             }
         }
         wifiIpAddressPref.setSummary(ipAddress == null ?
-                getString(R.string.status_unavailable) : ipAddress);
+                getActivity().getString(R.string.status_unavailable) : ipAddress);
     }
 
 }
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 905f2a3..5f6294f 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -188,7 +188,6 @@
         mAddNetwork = findPreference("add_network");
 
         registerForContextMenu(getListView());
-
         setHasOptionsMenu(true);
     }
 
@@ -267,7 +266,7 @@
                 }
                 return true;
             case MENU_ID_ADVANCED:
-                startActivity(new Intent(getActivity(), AdvancedSettings.class));
+                startFragment(this, AdvancedSettings.class.getCanonicalName(), -1, null);
                 return true;
         }
         return super.onOptionsItemSelected(item);