Merge "Updated Tethering and portable hotspot to use switches." into lmp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
aa5c7565e4
@@ -16,12 +16,12 @@
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<CheckBoxPreference
|
||||
<SwitchPreference
|
||||
android:key="usb_tether_settings"
|
||||
android:title="@string/usb_tethering_button_text"
|
||||
android:persistent="false" />
|
||||
|
||||
<CheckBoxPreference
|
||||
<SwitchPreference
|
||||
android:key="enable_wifi_ap"
|
||||
android:title="@string/wifi_tether_checkbox_text"
|
||||
android:persistent="false" />
|
||||
@@ -31,7 +31,7 @@
|
||||
android:title="@string/wifi_tether_configure_ap_text"
|
||||
android:persistent="false" />
|
||||
|
||||
<CheckBoxPreference
|
||||
<SwitchPreference
|
||||
android:key="enable_bluetooth_tethering"
|
||||
android:title="@string/bluetooth_tether_checkbox_text"
|
||||
android:persistent="false" />
|
||||
|
@@ -40,9 +40,9 @@ import android.os.Environment;
|
||||
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 @@ public class TetherSettings extends SettingsPreferenceFragment
|
||||
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 @@ public class TetherSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
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 @@ public class TetherSettings extends SettingsPreferenceFragment
|
||||
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:
|
||||
|
@@ -33,7 +33,7 @@ import android.net.wifi.SupplicantState;
|
||||
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 @@ import android.widget.Toast;
|
||||
|
||||
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 @@ public class WifiApEnabler {
|
||||
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 class WifiApEnabler {
|
||||
|
||||
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 @@ public class WifiApEnabler {
|
||||
|
||||
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 class WifiApEnabler {
|
||||
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 @@ public class WifiApEnabler {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user