OSDN Git Service

Fix window leak on orientation change
[android-x86/packages-apps-Settings.git] / src / com / android / settings / TetherSettings.java
index 5770482..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;
@@ -26,8 +27,6 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.net.ConnectivityManager;
-import android.net.wifi.WifiManager;
-import android.net.wifi.WifiConfiguration;
 import android.os.Environment;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
@@ -48,15 +47,19 @@ public class TetherSettings extends PreferenceActivity {
     private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
     private static final String WIFI_AP_SETTINGS = "wifi_ap_settings";
     private static final String TETHERING_HELP = "tethering_help";
-    private static final String HELP_URL = "file:///android_asset/html/%y_%z/tethering_help.html";
+    private static final String USB_HELP_MODIFIER = "usb_";
+    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;
     private PreferenceScreen mWifiApSettings;
     private WifiApEnabler mWifiApEnabler;
     private PreferenceScreen mTetherHelp;
-    private WifiManager mWifiManager;
 
     private BroadcastReceiver mTetherChangeReceiver;
 
@@ -64,7 +67,6 @@ public class TetherSettings extends PreferenceActivity {
     private ArrayList mUsbIfaces;
 
     private String[] mWifiRegexs;
-    private ArrayList mWifiIfaces;
 
     @Override
     protected void onCreate(Bundle icicle) {
@@ -79,7 +81,6 @@ public class TetherSettings extends PreferenceActivity {
 
         ConnectivityManager cm =
                 (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
-        mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
 
         mUsbRegexs = cm.getTetherableUsbRegexs();
         if (mUsbRegexs.length == 0) {
@@ -92,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) {
@@ -157,12 +185,8 @@ public class TetherSettings extends PreferenceActivity {
         boolean usbAvailable = false;
         int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
         boolean usbErrored = false;
-        boolean wifiTethered = false;
-        boolean wifiAvailable = false;
-        int wifiError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
         boolean massStorageActive =
                 Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
-        boolean wifiErrored = false;
         for (Object o : available) {
             String s = (String)o;
             for (String regex : mUsbRegexs) {
@@ -173,32 +197,18 @@ public class TetherSettings extends PreferenceActivity {
                     }
                 }
             }
-            for (String regex : mWifiRegexs) {
-                if (s.matches(regex)) {
-                    wifiAvailable = true;
-                    if (wifiError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
-                        wifiError = cm.getLastTetherError(s);
-                    }
-                }
-            }
         }
         for (Object o : tethered) {
             String s = (String)o;
             for (String regex : mUsbRegexs) {
                 if (s.matches(regex)) usbTethered = true;
             }
-            for (String regex : mWifiRegexs) {
-                if (s.matches(regex)) wifiTethered = true;
-            }
         }
         for (Object o: errored) {
             String s = (String)o;
             for (String regex : mUsbRegexs) {
                 if (s.matches(regex)) usbErrored = true;
             }
-            for (String regex : mWifiRegexs) {
-                if (s.matches(regex)) wifiErrored = true;
-            }
         }
 
         if (usbTethered) {
@@ -226,17 +236,6 @@ public class TetherSettings extends PreferenceActivity {
             mUsbTether.setEnabled(false);
             mUsbTether.setChecked(false);
         }
-
-        if (wifiTethered) {
-            WifiConfiguration mWifiConfig = mWifiManager.getWifiApConfiguration();
-            String s = getString(com.android.internal.R.string.wifi_tether_configure_ssid_default);
-            mEnableWifiAp.setSummary(String.format(getString(R.string.wifi_tether_enabled_subtext),
-                                                   (mWifiConfig == null) ? s : mWifiConfig.SSID));
-        }
-
-        if (wifiErrored) {
-            mEnableWifiAp.setSummary(R.string.wifi_error);
-        }
     }
 
     @Override
@@ -276,16 +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());
-            WebView view = new WebView(this);
-            view.loadUrl(url);
 
-            AlertDialog.Builder builder = new AlertDialog.Builder(this);
-            builder.setCancelable(true);
-            builder.setView(view);
-            builder.show();
+            showDialog(DIALOG_TETHER_HELP);
         }
         return false;
     }