Updated Tethering and portable hotspot to use switches.

Bug: 17020102
Change-Id: I5da1745d4ea9545f8960c015ca6858fb0a34de0d
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index d960ce6..8069d52 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -40,9 +40,9 @@
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
 import android.text.TextUtils;
 import android.view.ViewGroup;
 import android.view.ViewParent;
@@ -68,12 +68,12 @@
     private static final int DIALOG_AP_SETTINGS = 1;
 
     private WebView mView;
-    private CheckBoxPreference mUsbTether;
+    private SwitchPreference mUsbTether;
 
     private WifiApEnabler mWifiApEnabler;
-    private CheckBoxPreference mEnableWifiAp;
+    private SwitchPreference mEnableWifiAp;
 
-    private CheckBoxPreference mBluetoothTether;
+    private SwitchPreference mBluetoothTether;
 
     private BroadcastReceiver mTetherChangeReceiver;
 
@@ -135,10 +135,10 @@
         }
 
         mEnableWifiAp =
-                (CheckBoxPreference) findPreference(ENABLE_WIFI_AP);
+                (SwitchPreference) findPreference(ENABLE_WIFI_AP);
         Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY);
-        mUsbTether = (CheckBoxPreference) findPreference(USB_TETHER_SETTINGS);
-        mBluetoothTether = (CheckBoxPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
+        mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
+        mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
 
         ConnectivityManager cm =
                 (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -484,7 +484,7 @@
             if (resultCode == Activity.RESULT_OK) {
                 startTethering();
             } else {
-                //BT and USB need checkbox turned off on failure
+                //BT and USB need switch turned off on failure
                 //Wifi tethering is never turned on until afterwards
                 switch (mTetherChoice) {
                     case BLUETOOTH_TETHERING:
diff --git a/src/com/android/settings/wifi/WifiApEnabler.java b/src/com/android/settings/wifi/WifiApEnabler.java
index 9a3b49d..fc34f3b 100644
--- a/src/com/android/settings/wifi/WifiApEnabler.java
+++ b/src/com/android/settings/wifi/WifiApEnabler.java
@@ -33,7 +33,7 @@
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
-import android.preference.CheckBoxPreference;
+import android.preference.SwitchPreference;
 import android.provider.Settings;
 import android.text.TextUtils;
 import android.util.Log;
@@ -41,7 +41,7 @@
 
 public class WifiApEnabler {
     private final Context mContext;
-    private final CheckBoxPreference mCheckBox;
+    private final SwitchPreference mSwitch;
     private final CharSequence mOriginalSummary;
 
     private WifiManager mWifiManager;
@@ -66,17 +66,17 @@
                         ConnectivityManager.EXTRA_ERRORED_TETHER);
                 updateTetherState(available.toArray(), active.toArray(), errored.toArray());
             } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
-                enableWifiCheckBox();
+                enableWifiSwitch();
             }
 
         }
     };
 
-    public WifiApEnabler(Context context, CheckBoxPreference checkBox) {
+    public WifiApEnabler(Context context, SwitchPreference switchPreference) {
         mContext = context;
-        mCheckBox = checkBox;
-        mOriginalSummary = checkBox.getSummary();
-        checkBox.setPersistent(false);
+        mSwitch = switchPreference;
+        mOriginalSummary = switchPreference.getSummary();
+        switchPreference.setPersistent(false);
 
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
         mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -90,21 +90,21 @@
 
     public void resume() {
         mContext.registerReceiver(mReceiver, mIntentFilter);
-        enableWifiCheckBox();
+        enableWifiSwitch();
     }
 
     public void pause() {
         mContext.unregisterReceiver(mReceiver);
     }
 
-    private void enableWifiCheckBox() {
+    private void enableWifiSwitch() {
         boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
                 Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
         if(!isAirplaneMode) {
-            mCheckBox.setEnabled(true);
+            mSwitch.setEnabled(true);
         } else {
-            mCheckBox.setSummary(mOriginalSummary);
-            mCheckBox.setEnabled(false);
+            mSwitch.setSummary(mOriginalSummary);
+            mSwitch.setEnabled(false);
         }
     }
 
@@ -122,9 +122,9 @@
 
         if (mWifiManager.setWifiApEnabled(null, enable)) {
             /* Disable here, enabled on receiving success broadcast */
-            mCheckBox.setEnabled(false);
+            mSwitch.setEnabled(false);
         } else {
-            mCheckBox.setSummary(R.string.wifi_error);
+            mSwitch.setSummary(R.string.wifi_error);
         }
 
         /**
@@ -147,7 +147,7 @@
     public void updateConfigSummary(WifiConfiguration wifiConfig) {
         String s = mContext.getString(
                 com.android.internal.R.string.wifi_tether_configure_ssid_default);
-        mCheckBox.setSummary(String.format(
+        mSwitch.setSummary(String.format(
                     mContext.getString(R.string.wifi_tether_enabled_subtext),
                     (wifiConfig == null) ? s : wifiConfig.SSID));
     }
@@ -173,38 +173,38 @@
             WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration();
             updateConfigSummary(wifiConfig);
         } else if (wifiErrored) {
-            mCheckBox.setSummary(R.string.wifi_error);
+            mSwitch.setSummary(R.string.wifi_error);
         }
     }
 
     private void handleWifiApStateChanged(int state) {
         switch (state) {
             case WifiManager.WIFI_AP_STATE_ENABLING:
-                mCheckBox.setSummary(R.string.wifi_tether_starting);
-                mCheckBox.setEnabled(false);
+                mSwitch.setSummary(R.string.wifi_tether_starting);
+                mSwitch.setEnabled(false);
                 break;
             case WifiManager.WIFI_AP_STATE_ENABLED:
                 /**
                  * Summary on enable is handled by tether
                  * broadcast notice
                  */
-                mCheckBox.setChecked(true);
+                mSwitch.setChecked(true);
                 /* Doesnt need the airplane check */
-                mCheckBox.setEnabled(true);
+                mSwitch.setEnabled(true);
                 break;
             case WifiManager.WIFI_AP_STATE_DISABLING:
-                mCheckBox.setSummary(R.string.wifi_tether_stopping);
-                mCheckBox.setEnabled(false);
+                mSwitch.setSummary(R.string.wifi_tether_stopping);
+                mSwitch.setEnabled(false);
                 break;
             case WifiManager.WIFI_AP_STATE_DISABLED:
-                mCheckBox.setChecked(false);
-                mCheckBox.setSummary(mOriginalSummary);
-                enableWifiCheckBox();
+                mSwitch.setChecked(false);
+                mSwitch.setSummary(mOriginalSummary);
+                enableWifiSwitch();
                 break;
             default:
-                mCheckBox.setChecked(false);
-                mCheckBox.setSummary(R.string.wifi_error);
-                enableWifiCheckBox();
+                mSwitch.setChecked(false);
+                mSwitch.setSummary(R.string.wifi_error);
+                enableWifiSwitch();
         }
     }
 }