Merge "Updated Tethering and portable hotspot to use switches." into lmp-dev

This commit is contained in:
PauloftheWest
2014-08-25 16:44:25 +00:00
committed by Android (Google) Code Review
3 changed files with 39 additions and 39 deletions

View File

@@ -16,12 +16,12 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference <SwitchPreference
android:key="usb_tether_settings" android:key="usb_tether_settings"
android:title="@string/usb_tethering_button_text" android:title="@string/usb_tethering_button_text"
android:persistent="false" /> android:persistent="false" />
<CheckBoxPreference <SwitchPreference
android:key="enable_wifi_ap" android:key="enable_wifi_ap"
android:title="@string/wifi_tether_checkbox_text" android:title="@string/wifi_tether_checkbox_text"
android:persistent="false" /> android:persistent="false" />
@@ -31,7 +31,7 @@
android:title="@string/wifi_tether_configure_ap_text" android:title="@string/wifi_tether_configure_ap_text"
android:persistent="false" /> android:persistent="false" />
<CheckBoxPreference <SwitchPreference
android:key="enable_bluetooth_tethering" android:key="enable_bluetooth_tethering"
android:title="@string/bluetooth_tether_checkbox_text" android:title="@string/bluetooth_tether_checkbox_text"
android:persistent="false" /> android:persistent="false" />

View File

@@ -40,9 +40,9 @@ import android.os.Environment;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent; import android.view.ViewParent;
@@ -68,12 +68,12 @@ public class TetherSettings extends SettingsPreferenceFragment
private static final int DIALOG_AP_SETTINGS = 1; private static final int DIALOG_AP_SETTINGS = 1;
private WebView mView; private WebView mView;
private CheckBoxPreference mUsbTether; private SwitchPreference mUsbTether;
private WifiApEnabler mWifiApEnabler; private WifiApEnabler mWifiApEnabler;
private CheckBoxPreference mEnableWifiAp; private SwitchPreference mEnableWifiAp;
private CheckBoxPreference mBluetoothTether; private SwitchPreference mBluetoothTether;
private BroadcastReceiver mTetherChangeReceiver; private BroadcastReceiver mTetherChangeReceiver;
@@ -135,10 +135,10 @@ public class TetherSettings extends SettingsPreferenceFragment
} }
mEnableWifiAp = mEnableWifiAp =
(CheckBoxPreference) findPreference(ENABLE_WIFI_AP); (SwitchPreference) findPreference(ENABLE_WIFI_AP);
Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY); Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY);
mUsbTether = (CheckBoxPreference) findPreference(USB_TETHER_SETTINGS); mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
mBluetoothTether = (CheckBoxPreference) findPreference(ENABLE_BLUETOOTH_TETHERING); mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
ConnectivityManager cm = ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -484,7 +484,7 @@ public class TetherSettings extends SettingsPreferenceFragment
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
startTethering(); startTethering();
} else { } 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 //Wifi tethering is never turned on until afterwards
switch (mTetherChoice) { switch (mTetherChoice) {
case BLUETOOTH_TETHERING: case BLUETOOTH_TETHERING:

View File

@@ -33,7 +33,7 @@ import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.preference.CheckBoxPreference; import android.preference.SwitchPreference;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -41,7 +41,7 @@ import android.widget.Toast;
public class WifiApEnabler { public class WifiApEnabler {
private final Context mContext; private final Context mContext;
private final CheckBoxPreference mCheckBox; private final SwitchPreference mSwitch;
private final CharSequence mOriginalSummary; private final CharSequence mOriginalSummary;
private WifiManager mWifiManager; private WifiManager mWifiManager;
@@ -66,17 +66,17 @@ public class WifiApEnabler {
ConnectivityManager.EXTRA_ERRORED_TETHER); ConnectivityManager.EXTRA_ERRORED_TETHER);
updateTetherState(available.toArray(), active.toArray(), errored.toArray()); updateTetherState(available.toArray(), active.toArray(), errored.toArray());
} else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { } 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; mContext = context;
mCheckBox = checkBox; mSwitch = switchPreference;
mOriginalSummary = checkBox.getSummary(); mOriginalSummary = switchPreference.getSummary();
checkBox.setPersistent(false); switchPreference.setPersistent(false);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -90,21 +90,21 @@ public class WifiApEnabler {
public void resume() { public void resume() {
mContext.registerReceiver(mReceiver, mIntentFilter); mContext.registerReceiver(mReceiver, mIntentFilter);
enableWifiCheckBox(); enableWifiSwitch();
} }
public void pause() { public void pause() {
mContext.unregisterReceiver(mReceiver); mContext.unregisterReceiver(mReceiver);
} }
private void enableWifiCheckBox() { private void enableWifiSwitch() {
boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(), boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0; Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
if(!isAirplaneMode) { if(!isAirplaneMode) {
mCheckBox.setEnabled(true); mSwitch.setEnabled(true);
} else { } else {
mCheckBox.setSummary(mOriginalSummary); mSwitch.setSummary(mOriginalSummary);
mCheckBox.setEnabled(false); mSwitch.setEnabled(false);
} }
} }
@@ -122,9 +122,9 @@ public class WifiApEnabler {
if (mWifiManager.setWifiApEnabled(null, enable)) { if (mWifiManager.setWifiApEnabled(null, enable)) {
/* Disable here, enabled on receiving success broadcast */ /* Disable here, enabled on receiving success broadcast */
mCheckBox.setEnabled(false); mSwitch.setEnabled(false);
} else { } else {
mCheckBox.setSummary(R.string.wifi_error); mSwitch.setSummary(R.string.wifi_error);
} }
/** /**
@@ -147,7 +147,7 @@ public class WifiApEnabler {
public void updateConfigSummary(WifiConfiguration wifiConfig) { public void updateConfigSummary(WifiConfiguration wifiConfig) {
String s = mContext.getString( String s = mContext.getString(
com.android.internal.R.string.wifi_tether_configure_ssid_default); 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), mContext.getString(R.string.wifi_tether_enabled_subtext),
(wifiConfig == null) ? s : wifiConfig.SSID)); (wifiConfig == null) ? s : wifiConfig.SSID));
} }
@@ -173,38 +173,38 @@ public class WifiApEnabler {
WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration(); WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration();
updateConfigSummary(wifiConfig); updateConfigSummary(wifiConfig);
} else if (wifiErrored) { } else if (wifiErrored) {
mCheckBox.setSummary(R.string.wifi_error); mSwitch.setSummary(R.string.wifi_error);
} }
} }
private void handleWifiApStateChanged(int state) { private void handleWifiApStateChanged(int state) {
switch (state) { switch (state) {
case WifiManager.WIFI_AP_STATE_ENABLING: case WifiManager.WIFI_AP_STATE_ENABLING:
mCheckBox.setSummary(R.string.wifi_tether_starting); mSwitch.setSummary(R.string.wifi_tether_starting);
mCheckBox.setEnabled(false); mSwitch.setEnabled(false);
break; break;
case WifiManager.WIFI_AP_STATE_ENABLED: case WifiManager.WIFI_AP_STATE_ENABLED:
/** /**
* Summary on enable is handled by tether * Summary on enable is handled by tether
* broadcast notice * broadcast notice
*/ */
mCheckBox.setChecked(true); mSwitch.setChecked(true);
/* Doesnt need the airplane check */ /* Doesnt need the airplane check */
mCheckBox.setEnabled(true); mSwitch.setEnabled(true);
break; break;
case WifiManager.WIFI_AP_STATE_DISABLING: case WifiManager.WIFI_AP_STATE_DISABLING:
mCheckBox.setSummary(R.string.wifi_tether_stopping); mSwitch.setSummary(R.string.wifi_tether_stopping);
mCheckBox.setEnabled(false); mSwitch.setEnabled(false);
break; break;
case WifiManager.WIFI_AP_STATE_DISABLED: case WifiManager.WIFI_AP_STATE_DISABLED:
mCheckBox.setChecked(false); mSwitch.setChecked(false);
mCheckBox.setSummary(mOriginalSummary); mSwitch.setSummary(mOriginalSummary);
enableWifiCheckBox(); enableWifiSwitch();
break; break;
default: default:
mCheckBox.setChecked(false); mSwitch.setChecked(false);
mCheckBox.setSummary(R.string.wifi_error); mSwitch.setSummary(R.string.wifi_error);
enableWifiCheckBox(); enableWifiSwitch();
} }
} }
} }