Merge "Fragmentize wifi.AdvancedSettings."
diff --git a/res/layout-xlarge/date_time_settings_setupwizard.xml b/res/layout-xlarge/date_time_settings_setupwizard.xml
index 3985217..3c05089 100644
--- a/res/layout-xlarge/date_time_settings_setupwizard.xml
+++ b/res/layout-xlarge/date_time_settings_setupwizard.xml
@@ -19,7 +19,7 @@
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:paddingTop="70dip"
-              android:paddingBottom="40dip"
+              android:paddingBottom="100dip"
               android:paddingLeft="60dip"
               android:paddingRight="60dip">
 
@@ -29,7 +29,7 @@
               android:layout_height="wrap_content"
               android:layout_weight="0"
               android:gravity="center"
-              android:layout_marginBottom="10dip"
+              android:layout_marginBottom="30dip"
               android:layout_alignParentTop="true"
               android:textSize="64dip"
               android:textColor="#FF30FF30"
@@ -41,69 +41,98 @@
                   android:layout_height="fill_parent"
                   android:layout_weight="1">
         <!-- Left side: time zone setting -->
-        <LinearLayout android:orientation="vertical"
-                      android:layout_width="0px"
-                      android:layout_weight="1"
-                      android:layout_height="fill_parent">
-            <!-- TODO: replace with appropratie UI component -->
-            <CheckBox android:id="@+id/time_zone_auto"
-                      android:layout_width="wrap_content"
-                      android:layout_height="wrap_content"
-                      android:gravity="right|center_horizontal"
-                      android:layout_marginBottom="5dip"
-                      android:textSize="32dip"
-                      android:text="@string/time_zone_auto_stub"/>
-
-            <!-- text should manually be set. -->
-            <Button android:id="@+id/current_time_zone"
-                    android:layout_width="fill_parent"
-                    android:layout_height="wrap_content"
-                    android:textSize="24dip"
-                    android:layout_alignParentTop="true" />
-            <LinearLayout android:id="@+id/zone_picker"
+        <RelativeLayout android:layout_width="0px"
+                        android:layout_weight="1"
+                        android:layout_height="fill_parent"
+                        android:layout_marginRight="50dip">
+            <LinearLayout android:id="@+id/timezone"
                           android:orientation="vertical"
                           android:layout_width="fill_parent"
-                          android:layout_height="fill_parent"
-                          android:paddingLeft="10dip"
-                          android:paddingBottom="20dip"
-                          android:gravity="center"
-                          android:visibility="gone"
-                          android:clickable="true">
-                <fragment android:id="@+id/zone_picker_fragment"
-                          class="com.android.settings.ZonePicker"
-                          android:layout_width="fill_parent"
-                          android:layout_height="wrap_content" />
+                          android:layout_height="wrap_content"
+                          android:layout_weight="1"
+                          android:layout_alignParentTop="true">
+
+                <CheckBox android:id="@+id/time_zone_auto"
+                          android:layout_width="wrap_content"
+                          android:layout_height="wrap_content"
+                          android:gravity="right|center_horizontal"
+                          android:layout_marginBottom="5dip"
+                          android:textSize="32dip"
+                          android:text="@string/time_zone_auto_stub"/>
+
+                <!-- text should manually be set. -->
+                <Button android:id="@+id/current_time_zone"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:textSize="24dip"
+                        android:layout_alignParentTop="true" />
+                <LinearLayout android:id="@+id/zone_picker"
+                              android:orientation="vertical"
+                              android:layout_width="fill_parent"
+                              android:layout_height="350dip"
+                              android:paddingLeft="10dip"
+                              android:paddingBottom="20dip"
+                              android:gravity="center"
+                              android:visibility="gone"
+                              android:clickable="true">
+                    <fragment android:id="@+id/zone_picker_fragment"
+                              class="com.android.settings.ZonePicker"
+                              android:layout_width="fill_parent"
+                              android:layout_height="wrap_content" />
+                </LinearLayout>
             </LinearLayout>
-        </LinearLayout>
+            <Button android:id="@+id/skip_button"
+                    android:layout_width="300dip"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="0"
+                    android:layout_alignParentBottom="true"
+                    android:layout_centerHorizontal="true"
+                    android:textSize="32dip"
+                    android:text="@string/skip_label"/>
+        </RelativeLayout>
 
         <!-- Right side: date & time setting -->
-        <LinearLayout android:orientation="vertical"
-                      android:layout_width="0px"
-                      android:layout_weight="1"
-                      android:layout_height="fill_parent">
-
-            <!-- TODO: replace with appropratie UI component -->
-            <CheckBox android:id="@+id/date_time_auto"
-                      android:layout_width="wrap_content"
-                      android:layout_height="wrap_content"
-                      android:gravity="right|center_horizontal"
-                      android:textSize="32dip"
-                      android:text="@string/date_time_auto" />
-
-            <LinearLayout android:orientation="horizontal"
+        <RelativeLayout android:layout_width="0px"
+                        android:layout_weight="1"
+                        android:layout_height="fill_parent"
+                        android:layout_marginLeft="50dip">
+            <LinearLayout android:id="@+id/datetime"
+                          android:orientation="vertical"
                           android:layout_width="fill_parent"
-                          android:layout_height="wrap_content">
-                <TimePicker android:id="@+id/time_picker"
-                            android:layout_width="0px"
-                            android:layout_weight=".5"
-                            android:layout_height="wrap_content"
-                            android:visibility="visible"/>
-                <DatePicker android:id="@+id/date_picker"
-                            android:layout_width="0px"
-                            android:layout_weight=".5"
-                            android:layout_height="wrap_content"/>
+                          android:layout_height="wrap_content"
+                          android:layout_weight="1"
+                          android:layout_alignParentTop="true">
+
+                <CheckBox android:id="@+id/date_time_auto"
+                          android:layout_width="wrap_content"
+                          android:layout_height="wrap_content"
+                          android:gravity="right|center_horizontal"
+                          android:textSize="32dip"
+                          android:text="@string/date_time_auto" />
+
+                <LinearLayout android:orientation="horizontal"
+                              android:layout_width="fill_parent"
+                              android:layout_height="wrap_content">
+                    <TimePicker android:id="@+id/time_picker"
+                                android:layout_width="0px"
+                                android:layout_weight=".5"
+                                android:layout_height="wrap_content"
+                                android:visibility="visible"/>
+                    <DatePicker android:id="@+id/date_picker"
+                                android:layout_width="0px"
+                                android:layout_weight=".5"
+                                android:layout_height="wrap_content"/>
+                </LinearLayout>
             </LinearLayout>
-        </LinearLayout>
+            <Button android:id="@+id/next_button"
+                    android:layout_width="300dip"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="0"
+                    android:layout_alignParentBottom="true"
+                    android:layout_centerHorizontal="true"
+                    android:textSize="32dip"
+                    android:text="@string/next_label" />
+        </RelativeLayout>
     </LinearLayout>
 
     <LinearLayout android:id="@+id/bottom"
@@ -112,22 +141,6 @@
                   android:gravity="center"
                   android:layout_height="wrap_content"
                   android:layout_weight="0">
-        <Button android:id="@+id/skip_button"
-                android:layout_width="300dip"
-                android:layout_height="wrap_content"
-                android:layout_alignParentBottom="true"
-                android:layout_alignParentLeft="true"
-                android:layout_marginRight="50dip"
-                android:textSize="32dip"
-                android:text="@string/skip_label"/>
 
-        <Button android:id="@+id/next_button"
-                android:layout_width="300dip"
-                android:layout_height="wrap_content"
-                android:layout_alignParentBottom="true"
-                android:layout_alignParentRight="true"
-                android:layout_marginLeft="50dip"
-                android:textSize="32dip"
-                android:text="@string/next_label" />
     </LinearLayout>
 </LinearLayout>
diff --git a/res/layout/wifi_config_preference.xml b/res/layout/wifi_config_preference.xml
index c510abf..b7f183f 100644
--- a/res/layout/wifi_config_preference.xml
+++ b/res/layout/wifi_config_preference.xml
@@ -142,4 +142,84 @@
                   android:layout_height="wrap_content"
                   android:text="@string/wifi_show_password" />
     </LinearLayout>  <!-- android:id="@+id/fields" -->
+
+    <LinearLayout android:id="@+id/ipfields"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:orientation="vertical"
+                  android:visibility="gone">
+
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/wifi_ip_settings" />
+
+        <Spinner android:id="@+id/ipsettings"
+                 android:layout_width="fill_parent"
+                 android:layout_height="wrap_content"
+                 android:prompt="@string/wifi_ip_settings"
+                 android:entries="@array/wifi_ip_settings" />
+    </LinearLayout>
+
+    <LinearLayout android:id="@+id/staticip"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:orientation="vertical"
+                  android:visibility="gone">
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/wifi_ip_address" />
+
+        <EditText android:id="@+id/ipaddress"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:inputType="textNoSuggestions" />
+
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/wifi_gateway" />
+
+        <EditText android:id="@+id/gateway"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:inputType="textNoSuggestions" />
+
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/wifi_netmask" />
+
+        <EditText android:id="@+id/netmask"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:inputType="textNoSuggestions" />
+
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/wifi_dns1" />
+
+        <EditText android:id="@+id/dns1"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:inputType="textNoSuggestions" />
+
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/wifi_dns2" />
+
+        <EditText android:id="@+id/dns2"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:inputType="textNoSuggestions" />
+    </LinearLayout>
+
 </LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 84bc6cc..7581275 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2122,10 +2122,21 @@
         </string>
     <!-- Message for the prompt that lets users know that they have no accessibility related apps
          installed and that they can install TalkBack from Market. -->
-    <string name="accessibility_service_no_apps_message">You do not have any accessibility related
+    <string name="accessibility_service_no_apps_message">You do not have any accessibility-related
         applications installed.\n\nYou can download a screen reader for your device from Android
         Market.\n\nClick "OK" to install the screen reader.</string>
 
+    <!-- Accessibility settings: Webpage accessibility scripts category [CHAR LIMIT=25] -->
+    <string name="accessibility_script_injection_category">Accessibility scripts</string>
+    <!-- Accessibility settings: Checkbox title for enabling download of accessibility scripts [CHAR LIMIT=40] -->
+    <string name="accessibility_script_injection_enabled">Download accessibility scripts</string>
+    <!-- Accessibility settings: Checkbox summary for enabling download of accessibility scripts [CHAR LIMIT=65] -->
+    <string name="accessibility_script_injection_enabled_summary">Allow applications to download accessibility scripts from Google</string>
+    <!-- Warning message about security implications of downloading accessibility scripts,
+         displayed as a dialog message when the user selects to enable script downloading. [CHAR LIMIT="NONE"] -->
+    <string name="accessibility_script_injection_security_warning">Some applications can ask Google
+        to download scripts to your phone that make their content more accessible. Are you sure you
+        want to allow Google to install accessibility scripts on your phone?</string>
     <!-- Accessibility settings: Power button category -->
     <string name="accessibility_power_button_category">Power button</string>
     <!-- Accessibility settings: checkbox title for power button behavior -->
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index f82af85..f2efb27 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -26,6 +26,15 @@
     <PreferenceCategory android:key="accessibility_services_category"
             android:title="@string/accessibility_services_category" />
 
+    <PreferenceCategory android:key="accessibility_script_injection_category"
+            android:title="@string/accessibility_script_injection_category">
+        <CheckBoxPreference
+                android:key="toggle_accessibility_script_injection_checkbox"
+                android:title="@string/accessibility_script_injection_enabled"
+                android:summary="@string/accessibility_script_injection_enabled_summary"
+                android:persistent="false" />
+    </PreferenceCategory>
+
     <PreferenceCategory android:key="power_button_category"
             android:title="@string/accessibility_power_button_category">
         <CheckBoxPreference
diff --git a/res/xml/voice_input_output_settings.xml b/res/xml/voice_input_output_settings.xml
index 5781a5c..1645d88 100644
--- a/res/xml/voice_input_output_settings.xml
+++ b/res/xml/voice_input_output_settings.xml
@@ -35,10 +35,7 @@
             android:title="@string/voice_output_category" />
 
     <PreferenceScreen android:key="tts_settings"
-            android:title="@string/tts_settings_title">
-        <intent android:action="android.intent.action.MAIN"
-                android:targetPackage="com.android.settings"
-                android:targetClass="com.android.settings.TextToSpeechSettings" />
-    </PreferenceScreen>
+            android:fragment="com.android.settings.TextToSpeechSettings"
+            android:title="@string/tts_settings_title" />
 
-</PreferenceScreen>
\ No newline at end of file
+</PreferenceScreen>
diff --git a/src/com/android/settings/AccessibilitySettings.java b/src/com/android/settings/AccessibilitySettings.java
index 321e956..104ee9e 100644
--- a/src/com/android/settings/AccessibilitySettings.java
+++ b/src/com/android/settings/AccessibilitySettings.java
@@ -56,6 +56,9 @@
     private static final String ACCESSIBILITY_SERVICES_CATEGORY =
         "accessibility_services_category";
 
+    private static final String TOGGLE_ACCESSIBILITY_SCRIPT_INJECTION_CHECKBOX =
+        "toggle_accessibility_script_injection_checkbox";
+
     private static final String POWER_BUTTON_CATEGORY =
         "power_button_category";
 
@@ -64,6 +67,8 @@
 
     private CheckBoxPreference mToggleCheckBox;
 
+    private CheckBoxPreference mToggleScriptInjectionCheckBox;
+
     private PreferenceCategory mPowerButtonCategory;
     private CheckBoxPreference mPowerButtonEndsCallCheckBox;
 
@@ -81,18 +86,16 @@
         addPreferencesFromResource(R.xml.accessibility_settings);
 
         mToggleCheckBox = (CheckBoxPreference) findPreference(
-            TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX);
+                TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX);
+
+        mToggleScriptInjectionCheckBox = (CheckBoxPreference) findPreference(
+                TOGGLE_ACCESSIBILITY_SCRIPT_INJECTION_CHECKBOX);
 
         mPowerButtonCategory = (PreferenceCategory) findPreference(POWER_BUTTON_CATEGORY);
         mPowerButtonEndsCallCheckBox = (CheckBoxPreference) findPreference(
-            POWER_BUTTON_ENDS_CALL_CHECKBOX);
+                POWER_BUTTON_ENDS_CALL_CHECKBOX);
 
         addAccessibilitServicePreferences();
-    }
-
-    @Override
-    public void onResume() {
-        super.onResume();
 
         final HashSet<String> enabled = new HashSet<String>();
         String settingValue = Settings.Secure.getString(getContentResolver(),
@@ -136,6 +139,12 @@
             displayNoAppsAlert();
         }
 
+        // set the accessibility script injection category
+        boolean scriptInjectionEnabled = (Settings.Secure.getInt(getContentResolver(),
+                Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 0) == 1);
+        mToggleScriptInjectionCheckBox.setChecked(scriptInjectionEnabled);
+        mToggleScriptInjectionCheckBox.setEnabled(true);
+
         if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER)
                 && Utils.isVoiceCapable(getActivity())) {
             int incallPowerBehavior = Settings.Secure.getInt(getContentResolver(),
@@ -185,7 +194,6 @@
         final String key = preference.getKey();
 
         if (TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX.equals(key)) {
-            boolean isChecked = ((CheckBoxPreference) preference).isChecked();
             handleEnableAccessibilityStateChange((CheckBoxPreference) preference);
         } else if (POWER_BUTTON_ENDS_CALL_CHECKBOX.equals(key)) {
             boolean isChecked = ((CheckBoxPreference) preference).isChecked();
@@ -196,6 +204,8 @@
                     Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                     (isChecked ? Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP
                             : Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_SCREEN_OFF));
+        } else if (TOGGLE_ACCESSIBILITY_SCRIPT_INJECTION_CHECKBOX.equals(key)) {
+            handleToggleAccessibilityScriptInjection((CheckBoxPreference) preference);
         } else if (preference instanceof CheckBoxPreference) {
             handleEnableAccessibilityServiceStateChange((CheckBoxPreference) preference);
         }
@@ -242,6 +252,42 @@
     }
 
     /**
+     * Handles the change of the accessibility script injection setting state.
+     *
+     * @param preference The preference for enabling/disabling accessibility script injection.
+     */
+    private void handleToggleAccessibilityScriptInjection(CheckBoxPreference preference) {
+        if (preference.isChecked()) {
+            final CheckBoxPreference checkBoxPreference = preference;
+            // TODO: DialogFragment?
+            AlertDialog dialog = (new AlertDialog.Builder(getActivity()))
+                .setTitle(android.R.string.dialog_alert_title)
+                .setIcon(android.R.drawable.ic_dialog_alert)
+                .setMessage(getActivity().getString(
+                        R.string.accessibility_script_injection_security_warning))
+                .setCancelable(true)
+                .setPositiveButton(android.R.string.ok,
+                    new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            Settings.Secure.putInt(getContentResolver(),
+                            Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 1);
+                        }
+                })
+                .setNegativeButton(android.R.string.cancel,
+                    new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            checkBoxPreference.setChecked(false);
+                        }
+                    })
+                .create();
+                dialog.show();
+        } else {
+            Settings.Secure.putInt(getContentResolver(),
+                Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 0);
+        }
+    }
+
+    /**
      * Handles the change of the preference for enabling/disabling an AccessibilityService.
      *
      * @param preference The preference.
diff --git a/src/com/android/settings/TextToSpeechSettings.java b/src/com/android/settings/TextToSpeechSettings.java
index 89a4641..488e117 100644
--- a/src/com/android/settings/TextToSpeechSettings.java
+++ b/src/com/android/settings/TextToSpeechSettings.java
@@ -16,29 +16,30 @@
 
 package com.android.settings;
 
-import static android.provider.Settings.Secure.TTS_USE_DEFAULTS;
-import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
-import static android.provider.Settings.Secure.TTS_DEFAULT_LANG;
 import static android.provider.Settings.Secure.TTS_DEFAULT_COUNTRY;
-import static android.provider.Settings.Secure.TTS_DEFAULT_VARIANT;
+import static android.provider.Settings.Secure.TTS_DEFAULT_LANG;
+import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
 import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
+import static android.provider.Settings.Secure.TTS_DEFAULT_VARIANT;
 import static android.provider.Settings.Secure.TTS_ENABLED_PLUGINS;
+import static android.provider.Settings.Secure.TTS_USE_DEFAULTS;
 
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.ContentResolver;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.os.Bundle;
+import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceClickListener;
-import android.preference.PreferenceActivity;
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceScreen;
-import android.preference.CheckBoxPreference;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.speech.tts.TextToSpeech;
@@ -49,7 +50,7 @@
 import java.util.Locale;
 import java.util.StringTokenizer;
 
-public class TextToSpeechSettings extends PreferenceActivity implements
+public class TextToSpeechSettings extends SettingsPreferenceFragment implements
         Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
         TextToSpeech.OnInitListener {
 
@@ -90,8 +91,6 @@
     private String             mDefaultEng = "";
     private int                mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
 
-    // Array of strings used to demonstrate TTS in the different languages.
-    private String[] mDemoStrings;
     // Index of the current string to use for the demo.
     private int      mDemoStringIndex = 0;
 
@@ -109,16 +108,14 @@
     private static final int GET_SAMPLE_TEXT = 1983;
 
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
+    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-
         addPreferencesFromResource(R.xml.tts_settings);
 
-        addEngineSpecificSettings();
+        final Activity activity = getActivity();
+        addEngineSpecificSettings(activity);
 
-        mDemoStrings = getResources().getStringArray(R.array.tts_demo_strings);
-
-        setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
+        activity.setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
 
         mEnableDemo = false;
         mTtsStarted = false;
@@ -128,12 +125,12 @@
         mDefaultCountry = currentLocale.getISO3Country();
         mDefaultLocVariant = currentLocale.getVariant();
 
-        mTts = new TextToSpeech(this, this);
+        mTts = new TextToSpeech(activity, this);
     }
 
 
     @Override
-    protected void onStart() {
+    public void onStart() {
         super.onStart();
         if (mTtsStarted){
             // whenever we return to this screen, we don't know the state of the
@@ -147,7 +144,7 @@
 
 
     @Override
-    protected void onDestroy() {
+    public void onDestroy() {
         super.onDestroy();
         if (mTts != null) {
             mTts.shutdown();
@@ -155,7 +152,7 @@
     }
 
     @Override
-    protected void onPause() {
+    public void onPause() {
         super.onPause();
         if ((mDefaultRatePref != null) && (mDefaultRatePref.getDialog() != null)) {
             mDefaultRatePref.getDialog().dismiss();
@@ -168,9 +165,7 @@
         }
     }
 
-
-
-    private void addEngineSpecificSettings() {
+    private void addEngineSpecificSettings(Context context) {
         PreferenceGroup enginesCategory = (PreferenceGroup) findPreference("tts_engines_section");
         Intent intent = new Intent("android.intent.action.START_TTS_ENGINE");
         ResolveInfo[] enginesArray = new ResolveInfo[0];
@@ -180,14 +175,14 @@
             String prefKey = "";
             final String pluginPackageName = enginesArray[i].activityInfo.packageName;
             if (!enginesArray[i].activityInfo.packageName.equals(SYSTEM_TTS)) {
-                CheckBoxPreference chkbxPref = new CheckBoxPreference(this);
+                CheckBoxPreference chkbxPref = new CheckBoxPreference(context);
                 prefKey = KEY_PLUGIN_ENABLED_PREFIX + pluginPackageName;
                 chkbxPref.setKey(prefKey);
                 chkbxPref.setTitle(enginesArray[i].loadLabel(pm));
                 enginesCategory.addPreference(chkbxPref);
             }
             if (pluginHasSettings(pluginPackageName)) {
-                Preference pref = new Preference(this);
+                Preference pref = new Preference(context);
                 prefKey = KEY_PLUGIN_SETTINGS_PREFIX + pluginPackageName;
                 pref.setKey(prefKey);
                 pref.setTitle(enginesArray[i].loadLabel(pm));
@@ -360,7 +355,7 @@
                 mDefaultLocVariant = new String();
             }
             mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
-            mTts.setSpeechRate((float)(mDefaultRate/100.0f));
+            mTts.setSpeechRate(mDefaultRate/100.0f);
             initDefaultSettings();
             initClickers();
             updateWidgetState();
@@ -378,7 +373,8 @@
     /**
      * Called when voice data integrity check returns
      */
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
         if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
             if (data == null){
                 // The CHECK_TTS_DATA activity for the plugin did not run properly;
@@ -402,7 +398,7 @@
             }
             if (available.size() > 0){
                 if (mTts == null) {
-                    mTts = new TextToSpeech(this, this);
+                    mTts = new TextToSpeech(getActivity(), this);
                 }
                 ListPreference ttsLanguagePref =
                         (ListPreference) findPreference("tts_default_lang");
@@ -478,7 +474,7 @@
             updateWidgetState();
         } else if (requestCode == GET_SAMPLE_TEXT) {
             if (resultCode == TextToSpeech.LANG_AVAILABLE) {
-                String sample = getString(R.string.tts_demo);
+                String sample = getActivity().getString(R.string.tts_demo);
                 if ((data != null) && (data.getStringExtra("sampleText") != null)) {
                     sample = data.getStringExtra("sampleText");
                 }
@@ -492,7 +488,6 @@
         }
     }
 
-
     public boolean onPreferenceChange(Preference preference, Object objValue) {
         if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) {
             // "Use Defaults"
@@ -507,7 +502,7 @@
                 Settings.Secure.putInt(getContentResolver(),
                         TTS_DEFAULT_RATE, mDefaultRate);
                 if (mTts != null) {
-                    mTts.setSpeechRate((float)(mDefaultRate/100.0f));
+                    mTts.setSpeechRate(mDefaultRate/100.0f);
                 }
                 Log.i(TAG, "TTS default rate is " + mDefaultRate);
             } catch (NumberFormatException e) {
@@ -575,10 +570,11 @@
             if (!chkPref.getKey().equals(KEY_TTS_USE_DEFAULT)){
                 if (chkPref.isChecked()) {
                     chkPref.setChecked(false);
-                    AlertDialog d = (new AlertDialog.Builder(this))
+                    AlertDialog d = (new AlertDialog.Builder(getActivity()))
                             .setTitle(android.R.string.dialog_alert_title)
                             .setIcon(android.R.drawable.ic_dialog_alert)
-                            .setMessage(getString(R.string.tts_engine_security_warning,
+                            .setMessage(
+                                    getActivity().getString(R.string.tts_engine_security_warning,
                                     chkPref.getTitle()))
                             .setCancelable(true)
                             .setPositiveButton(android.R.string.ok,
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 5f374a5..d655f90 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -91,10 +91,10 @@
     // See mConnectAttempted
     private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
 
-    
+
     /**
      * Describes the current device and profile for logging.
-     * 
+     *
      * @param profile Profile to describe
      * @return Description of the device and profile
      */
@@ -107,7 +107,7 @@
 
         return sb.toString();
     }
-    
+
     private String describe(Profile profile) {
         return describe(this, profile);
     }
@@ -264,7 +264,7 @@
                         .getProfileManager(mLocalManager, profile);
                 if (profileManager.isPreferred(mDevice)) {
                     ++preferredProfiles;
-                    disconnectConnected(profile);
+                    disconnectConnected(this, profile);
                     connectInt(this, profile);
                 }
             }
@@ -287,7 +287,7 @@
                 LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
                         .getProfileManager(mLocalManager, profile);
                 profileManager.setPreferred(mDevice, false);
-                disconnectConnected(profile);
+                disconnectConnected(this, profile);
                 connectInt(this, profile);
             }
         }
@@ -297,19 +297,20 @@
         mConnectAttempted = SystemClock.elapsedRealtime();
         // Reset the only-show-one-error-dialog tracking variable
         mIsConnectingErrorPossible = true;
-        disconnectConnected(profile);
+        disconnectConnected(this, profile);
         connectInt(this, profile);
     }
 
-    private void disconnectConnected(Profile profile) {
+    private void disconnectConnected(CachedBluetoothDevice device, Profile profile) {
         LocalBluetoothProfileManager profileManager =
             LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
         CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager();
         Set<BluetoothDevice> devices = profileManager.getConnectedDevices();
         if (devices == null) return;
-        for (BluetoothDevice device : devices) {
-            CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(device);
-            if (cachedDevice != null) {
+        for (BluetoothDevice btDevice : devices) {
+            CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(btDevice);
+
+            if (cachedDevice != null && !cachedDevice.equals(device)) {
                 disconnectInt(cachedDevice, profile);
             }
         }