Merge "b/2174155 Remove debug logging in bluetooth" into froyo
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 2ab7a50..79b081f 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -19,6 +19,7 @@
 import com.android.settings.wifi.WifiApEnabler;
 
 import android.app.AlertDialog;
+import android.app.Dialog;
 import android.os.Bundle;
 import android.os.SystemProperties;
 import android.content.BroadcastReceiver;
@@ -50,6 +51,9 @@
     private static final String WIFI_HELP_MODIFIER = "wifi_";
     private static final String HELP_URL = "file:///android_asset/html/%y_%z/tethering_%xhelp.html";
 
+    private static final int DIALOG_TETHER_HELP = 1;
+
+    private WebView mView;
     private CheckBoxPreference mUsbTether;
 
     private CheckBoxPreference mEnableWifiAp;
@@ -89,8 +93,35 @@
             getPreferenceScreen().removePreference(mWifiApSettings);
         }
         mWifiApEnabler = new WifiApEnabler(this, mEnableWifiAp);
+        mView = new WebView(this);
     }
 
+    @Override
+    protected Dialog onCreateDialog(int id) {
+        if (id == DIALOG_TETHER_HELP) {
+            Locale locale = Locale.getDefault();
+            String url = HELP_URL.replace("%y", locale.getLanguage().toLowerCase());
+            url = url.replace("%z", locale.getCountry().toLowerCase());
+
+            if ((mUsbRegexs.length != 0) && (mWifiRegexs.length == 0)) {
+                url = url.replace("%x", USB_HELP_MODIFIER);
+            } else if ((mWifiRegexs.length != 0) && (mUsbRegexs.length == 0)) {
+                url = url.replace("%x", WIFI_HELP_MODIFIER);
+            } else {
+                // could assert that both wifi and usb have regexs, but the default
+                // is to use this anyway so no check is needed
+                url = url.replace("%x", "");
+            }
+            mView.loadUrl(url);
+
+            return new AlertDialog.Builder(this)
+                .setCancelable(true)
+                .setTitle(R.string.tethering_help_button_text)
+                .setView(mView)
+                .create();
+        }
+        return null;
+    }
 
     private class TetherChangeReceiver extends BroadcastReceiver {
         public void onReceive(Context content, Intent intent) {
@@ -244,27 +275,8 @@
                 mUsbTether.setSummary("");
             }
         } else if (preference == mTetherHelp) {
-            Locale locale = Locale.getDefault();
-            String url = HELP_URL.replace("%y", locale.getLanguage().toLowerCase());
-            url = url.replace("%z", locale.getCountry().toLowerCase());
 
-            if ((mUsbRegexs.length != 0) && (mWifiRegexs.length == 0)) {
-                url = url.replace("%x", USB_HELP_MODIFIER);
-            } else if ((mWifiRegexs.length != 0) && (mUsbRegexs.length == 0)) {
-                url = url.replace("%x", WIFI_HELP_MODIFIER);
-            } else {
-                // could assert that both wifi and usb have regexs, but the default
-                // is to use this anyway so no check is needed
-                url = url.replace("%x", "");
-            }
-            WebView view = new WebView(this);
-            view.loadUrl(url);
-
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setCancelable(true);
-            builder.setTitle(R.string.tethering_help_button_text);
-            builder.setView(view);
-            builder.show();
+            showDialog(DIALOG_TETHER_HELP);
         }
         return false;
     }
diff --git a/src/com/android/settings/TextToSpeechSettings.java b/src/com/android/settings/TextToSpeechSettings.java
index fa9ea58..5366bd0 100644
--- a/src/com/android/settings/TextToSpeechSettings.java
+++ b/src/com/android/settings/TextToSpeechSettings.java
@@ -99,6 +99,7 @@
     private boolean mVoicesMissing = false;
 
     private TextToSpeech mTts = null;
+    private boolean mTtsStarted = false;
 
     /**
      * Request code (arbitrary value) for voice data check through
@@ -120,8 +121,7 @@
         setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
 
         mEnableDemo = false;
-        initClickers();
-        initDefaultSettings();
+        mTtsStarted = false;
 
         mTts = new TextToSpeech(this, this);
     }
@@ -130,12 +130,14 @@
     @Override
     protected void onStart() {
         super.onStart();
-        // whenever we return to this screen, we don't know the state of the
-        // system, so we have to recheck that we can play the demo, or it must be disabled.
-        // TODO make the TTS service listen to "changes in the system", i.e. sd card un/mount
-        initClickers();
-        updateWidgetState();
-        checkVoiceData();
+        if (mTtsStarted){
+            // whenever we return to this screen, we don't know the state of the
+            // system, so we have to recheck that we can play the demo, or it must be disabled.
+            // TODO make the TTS service listen to "changes in the system", i.e. sd card un/mount
+            initClickers();
+            updateWidgetState();
+            checkVoiceData();
+        }
     }
 
 
@@ -327,7 +329,6 @@
      */
     public void onInit(int status) {
         if (status == TextToSpeech.SUCCESS) {
-            Log.v(TAG, "TTS engine for settings screen initialized.");
             mEnableDemo = true;
             if (mDefaultLanguage == null) {
                 mDefaultLanguage = Locale.getDefault().getISO3Language();
@@ -340,6 +341,12 @@
             }
             mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
             mTts.setSpeechRate((float)(mDefaultRate/100.0f));
+            initDefaultSettings();
+            initClickers();
+            updateWidgetState();
+            checkVoiceData();
+            mTtsStarted = true;
+            Log.v(TAG, "TTS engine for settings screen initialized.");
         } else {
             Log.v(TAG, "TTS engine for settings screen failed to initialize successfully.");
             mEnableDemo = false;
diff --git a/src/com/android/settings/wifi/WifiApSettings.java b/src/com/android/settings/wifi/WifiApSettings.java
index bca4835..0815238 100644
--- a/src/com/android/settings/wifi/WifiApSettings.java
+++ b/src/com/android/settings/wifi/WifiApSettings.java
@@ -17,6 +17,7 @@
 package com.android.settings.wifi;
 
 import com.android.settings.R;
+import android.app.Dialog;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -48,6 +49,8 @@
     private static final int OPEN_INDEX = 0;
     private static final int WPA_INDEX = 1;
 
+    private static final int DIALOG_AP_SETTINGS = 1;
+
     private String[] mSecurityType;
     private Preference mCreateNetwork;
     private CheckBoxPreference mEnableWifiAp;
@@ -85,6 +88,15 @@
     }
 
     @Override
+    protected Dialog onCreateDialog(int id) {
+        if (id == DIALOG_AP_SETTINGS) {
+            mDialog = new WifiApDialog(this, this, mWifiConfig);
+            return mDialog;
+        }
+        return null;
+    }
+
+    @Override
     protected void onResume() {
         super.onResume();
         mWifiApEnabler.resume();
@@ -99,19 +111,11 @@
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
         if (preference == mCreateNetwork) {
-            showDialog();
+            showDialog(DIALOG_AP_SETTINGS);
         }
         return true;
     }
 
-    private void showDialog() {
-        if (mDialog != null) {
-            mDialog.dismiss();
-        }
-        mDialog = new WifiApDialog(this, this, mWifiConfig);
-        mDialog.show();
-    }
-
     public void onClick(DialogInterface dialogInterface, int button) {
 
         if (button == DialogInterface.BUTTON_POSITIVE) {