OSDN Git Service

Fix window leak on orientation change
authorIrfan Sheriff <isheriff@google.com>
Tue, 6 Apr 2010 22:16:44 +0000 (15:16 -0700)
committerIrfan Sheriff <isheriff@google.com>
Wed, 7 Apr 2010 21:38:42 +0000 (14:38 -0700)
Use Activity managed dialogs

Bug: 2571764
Bug: 2571820
Change-Id: Id506988abd4200155774e92b31dd132519e29172

src/com/android/settings/TetherSettings.java
src/com/android/settings/wifi/WifiApSettings.java

index 2ab7a50..79b081f 100644 (file)
@@ -19,6 +19,7 @@ package com.android.settings;
 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 @@ public class TetherSettings extends PreferenceActivity {
     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 @@ public class TetherSettings extends PreferenceActivity {
             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 @@ public class TetherSettings extends PreferenceActivity {
                 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;
     }
index bca4835..0815238 100644 (file)
@@ -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 @@ public class WifiApSettings extends PreferenceActivity
     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 @@ public class WifiApSettings extends PreferenceActivity
     }
 
     @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 @@ public class WifiApSettings extends PreferenceActivity
     @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) {