blob: f160bac8b4dbaed1da833fd0d53bd07c910135f0 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
19import com.android.settings.bluetooth.BluetoothEnabler;
20import com.android.settings.wifi.WifiEnabler;
21
22import android.net.wifi.WifiManager;
23import android.os.Bundle;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080024import android.preference.CheckBoxPreference;
Mike Lockwood83bcc982009-07-29 23:25:10 -070025import android.preference.Preference;
26import android.preference.PreferenceActivity;
27import android.provider.Settings;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080028
29public class WirelessSettings extends PreferenceActivity {
30
31 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
32 private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
33 private static final String KEY_TOGGLE_WIFI = "toggle_wifi";
Mike Lockwood83bcc982009-07-29 23:25:10 -070034 private static final String KEY_WIFI_SETTINGS = "wifi_settings";
35 private static final String KEY_VPN_SETTINGS = "vpn_settings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080036
37 private WifiEnabler mWifiEnabler;
38 private AirplaneModeEnabler mAirplaneModeEnabler;
39 private BluetoothEnabler mBtEnabler;
40
41 @Override
42 protected void onCreate(Bundle savedInstanceState) {
43 super.onCreate(savedInstanceState);
44
45 addPreferencesFromResource(R.xml.wireless_settings);
46
47 initToggles();
48 }
49
50 @Override
51 protected void onResume() {
52 super.onResume();
53
54 mWifiEnabler.resume();
55 mAirplaneModeEnabler.resume();
56 mBtEnabler.resume();
57 }
58
59 @Override
60 protected void onPause() {
61 super.onPause();
62
63 mWifiEnabler.pause();
64 mAirplaneModeEnabler.pause();
65 mBtEnabler.pause();
66 }
67
68 private void initToggles() {
69
Mike Lockwood83bcc982009-07-29 23:25:10 -070070 Preference airplanePreference = findPreference(KEY_TOGGLE_AIRPLANE);
71 Preference wifiPreference = findPreference(KEY_TOGGLE_WIFI);
72 Preference btPreference = findPreference(KEY_TOGGLE_BLUETOOTH);
73 Preference wifiSettings = findPreference(KEY_WIFI_SETTINGS);
74 Preference vpnSettings = findPreference(KEY_VPN_SETTINGS);
75
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080076 mWifiEnabler = new WifiEnabler(
Mike Lockwood83bcc982009-07-29 23:25:10 -070077 this, (WifiManager) getSystemService(WIFI_SERVICE),
78 (CheckBoxPreference) wifiPreference);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080079 mAirplaneModeEnabler = new AirplaneModeEnabler(
Mike Lockwood83bcc982009-07-29 23:25:10 -070080 this, (CheckBoxPreference) airplanePreference);
81 mBtEnabler = new BluetoothEnabler(this, (CheckBoxPreference) btPreference);
82
83 // manually set up dependencies for Wifi if its radio is not toggleable in airplane mode
84 String toggleableRadios = Settings.System.getString(getContentResolver(),
85 Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
86 if (toggleableRadios == null || !toggleableRadios.contains(Settings.System.RADIO_WIFI)) {
87 wifiPreference.setDependency(airplanePreference.getKey());
88 wifiSettings.setDependency(airplanePreference.getKey());
89 vpnSettings.setDependency(airplanePreference.getKey());
90 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080091 }
Mike Lockwood83bcc982009-07-29 23:25:10 -070092
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080093}