Settings refactoring

Wifi and bluetooth pane refactored, main toggles moved to left pane.

Change-Id: I42ea4cf3bdf24158f3c67e0dea311258206cd78a
This commit is contained in:
Gilles Debunne
2011-06-20 15:00:07 -07:00
parent 222a619668
commit e78c187905
33 changed files with 1216 additions and 604 deletions

View File

@@ -149,8 +149,8 @@
android:windowSoftInputMode="adjustResize" android:windowSoftInputMode="adjustResize"
android:exported="true" /> android:exported="true" />
<activity-alias android:name=".wifi.AdvancedSettings" <activity-alias android:name=".wifi.AdvancedWifiSettings"
android:label="@string/wifi_ip_settings_titlebar" android:label="@string/wifi_advanced_settings_label"
android:targetActivity="Settings" android:targetActivity="Settings"
> >
<intent-filter> <intent-filter>
@@ -239,6 +239,18 @@
android:value="com.android.settings.Settings$WirelessSettingsActivity" /> android:value="com.android.settings.Settings$WirelessSettingsActivity" />
</activity> </activity>
<activity-alias android:name=".bluetooth.AdvancedBluetoothSettings"
android:label="@string/bluetooth_advanced_settings_label"
android:targetActivity="Settings"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.BLUETOOTH_ADVANCED_SETTINGS" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity-alias>
<activity android:name=".bluetooth.DevicePickerActivity" <activity android:name=".bluetooth.DevicePickerActivity"
android:theme="@android:style/Theme.Holo.DialogWhenLarge" android:theme="@android:style/Theme.Holo.DialogWhenLarge"
android:label="@string/device_picker" android:label="@string/device_picker"

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Layout of a header item in PreferenceActivity. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:background="?android:attr/activatedBackgroundIndicator"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dip"
android:layout_marginRight="6dip"
android:layout_gravity="center" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:ellipsize="end"
android:maxLines="2" />
</RelativeLayout>
<Switch android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dip"
android:focusable="false"
android:clickable="true" />
</LinearLayout>

View File

@@ -185,6 +185,7 @@
<CheckBox android:id="@+id/show_password" <CheckBox android:id="@+id/show_password"
style="@style/wifi_item_content" style="@style/wifi_item_content"
android:textSize="14sp"
android:text="@string/wifi_show_password" /> android:text="@string/wifi_show_password" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -21,4 +21,5 @@
<dimen name="device_memory_usage_button_width">16dip</dimen> <dimen name="device_memory_usage_button_width">16dip</dimen>
<dimen name="device_memory_usage_button_height">32dip</dimen> <dimen name="device_memory_usage_button_height">32dip</dimen>
<dimen name="data_usage_chart_height">220dip</dimen> <dimen name="data_usage_chart_height">220dip</dimen>
<dimen name="action_bar_switch_padding">16dip</dimen>
</resources> </resources>

View File

@@ -24,6 +24,16 @@
<!-- Device Info screen. Used for a status item's value when the proper value is not known --> <!-- Device Info screen. Used for a status item's value when the proper value is not known -->
<string name="device_info_default">Unknown</string> <string name="device_info_default">Unknown</string>
<!-- Category headings in left-pane header menu --> <skip />
<!-- Settings main menu category heading. Wireless and networks (Wi-Fi, Bluetooth, data usage...). [CHAR LIMIT=40] -->
<string name="header_category_wireless_networks">WIRELESS &amp; NETWORKS</string>
<!-- Settings main menu category heading. Device (Sound, display, battery, applications...). [CHAR LIMIT=40] -->
<string name="header_category_device">DEVICE</string>
<!-- Settings main menu category heading. Personal (Accounts, security, language, backup...). [CHAR LIMIT=40] -->
<string name="header_category_personal">PERSONAL</string>
<!-- Settings main menu category heading. System (Updates, data, accessibility, about phone). [CHAR LIMIT=40] -->
<string name="header_category_system">SYSTEM</string>
<!-- Phone info --> <!-- Phone info -->
<!-- Phone Info screen. Button label to turn on the radio . Only shown in diagnostic screen, so precise translation is not needed. --> <!-- Phone Info screen. Button label to turn on the radio . Only shown in diagnostic screen, so precise translation is not needed. -->
<string name="turn_on_radio">Turn on radio</string> <string name="turn_on_radio">Turn on radio</string>
@@ -505,8 +515,8 @@
<string name="airplane_mode_turning_on">Disabling wireless connections\u2026</string> <string name="airplane_mode_turning_on">Disabling wireless connections\u2026</string>
<!-- Wireless controls settings screen, setting option summary text as airplane mode is being disabled (so it is re-enabling all the wireless conenctions) --> <!-- Wireless controls settings screen, setting option summary text as airplane mode is being disabled (so it is re-enabling all the wireless conenctions) -->
<string name="airplane_mode_turning_off">Enabling wireless connections\u2026</string> <string name="airplane_mode_turning_off">Enabling wireless connections\u2026</string>
<!-- Main Settings screen settings title for things like Wi-Fi, bluetooth, airplane mode. This will take you to another screen with those settings. --> <!-- Main Settings screen settings title for things like airplane mode, tethering, NFC, VPN. This will take you to another screen with those settings. -->
<string name="radio_controls_title">Wireless &amp; networks</string> <string name="radio_controls_title">More\u2026</string>
<!-- Wireless Settings screen title for things like Wi-Fi, bluetooth, airplane mode. --> <!-- Wireless Settings screen title for things like Wi-Fi, bluetooth, airplane mode. -->
<string name="wireless_networks_settings_title">Wireless &amp; networks</string> <string name="wireless_networks_settings_title">Wireless &amp; networks</string>
<!-- Main Settings screen settings summary text for the "Wireless controls" setting --> <!-- Main Settings screen settings summary text for the "Wireless controls" setting -->
@@ -875,9 +885,9 @@
<!-- Bluetooth settings check box summary for turning on bluetooth --> <!-- Bluetooth settings check box summary for turning on bluetooth -->
<string name="bluetooth_quick_toggle_summary">Turn on Bluetooth</string> <string name="bluetooth_quick_toggle_summary">Turn on Bluetooth</string>
<!--Used as title on second screen after selecting Bluetooth settings --> <!--Used as title on second screen after selecting Bluetooth settings -->
<string name="bluetooth_settings">Bluetooth settings</string> <string name="bluetooth_settings">Bluetooth</string>
<!--Wireless controls screen, settings title for the item to take you to the bluetooth settings screen --> <!--Wireless controls screen, settings title for the item to take you to the bluetooth settings screen -->
<string name="bluetooth_settings_title">Bluetooth settings</string> <string name="bluetooth_settings_title">Bluetooth</string>
<!--Wireless controls screen, settings summary for the item tot ake you to the bluetooth settings screen --> <!--Wireless controls screen, settings summary for the item tot ake you to the bluetooth settings screen -->
<string name="bluetooth_settings_summary">Manage connections, set device name &amp; discoverability</string> <string name="bluetooth_settings_summary">Manage connections, set device name &amp; discoverability</string>
@@ -937,6 +947,15 @@
<string name="bluetooth_device_context_disconnect_unpair">Disconnect &amp; unpair</string> <string name="bluetooth_device_context_disconnect_unpair">Disconnect &amp; unpair</string>
<!-- Bluetooth settings. Context menu item for a device. Action will take the user to another screen where they can choose exactly which profiles to connect to. --> <!-- Bluetooth settings. Context menu item for a device. Action will take the user to another screen where they can choose exactly which profiles to connect to. -->
<string name="bluetooth_device_context_connect_advanced">Options\u2026</string> <string name="bluetooth_device_context_connect_advanced">Options\u2026</string>
<!-- Bluetooth settings. Menu option to Bluetooth advanced settings [CHAR LIMIT=20]-->
<string name="bluetooth_menu_advanced">Advanced</string>
<!-- Bluetooth settings. Title of the advanced bluetooth settings screen [CHAR LIMIT=30]-->
<string name="bluetooth_advanced_titlebar">Advanced Bluetooth</string>
<!-- Bluetooth Advanced settings. Used as a label under the shortcut icon that goes to Bluetooth advanced settings. [CHAR LIMIT=20]-->
<string name="bluetooth_advanced_settings_label">Advanced Bluetooth</string>
<!-- Bluetooth settings. Text displayed when Bluetooth is off and device list is empty [CHAR LIMIT=50]-->
<string name="bluetooth_empty_list_bluetooth_off">Turn on bluetooth to see available devices</string>
<!-- Bluetooth settings. The title of the screen to pick which profiles to connect to on the device. For example, headphones may have both A2DP and headset, this allows the user to choose which one he wants to connect to. --> <!-- Bluetooth settings. The title of the screen to pick which profiles to connect to on the device. For example, headphones may have both A2DP and headset, this allows the user to choose which one he wants to connect to. -->
<string name="bluetooth_connect_specific_profiles_title">Connect to\u2026</string> <string name="bluetooth_connect_specific_profiles_title">Connect to\u2026</string>
@@ -1032,16 +1051,18 @@
<string name="wifi_quick_toggle_title">Wi-Fi</string> <string name="wifi_quick_toggle_title">Wi-Fi</string>
<!-- Used in the 1st-level settings screen as the turn-on summary --> <!-- Used in the 1st-level settings screen as the turn-on summary -->
<string name="wifi_quick_toggle_summary">Turn on Wi-Fi</string> <string name="wifi_quick_toggle_summary">Turn on Wi-Fi</string>
<!-- Used in the 1st-level settings screen to go to the 2nd-level settings screen --> <!-- Used in the 1st-level settings screen to go to the 2nd-level settings screen [CHAR LIMIT=20]-->
<string name="wifi_settings">Wi-Fi settings</string> <string name="wifi_settings">Wi-Fi</string>
<!-- Title of the Wi-fi settings screen --> <!-- Title of the Wi-fi settings screen -->
<string name="wifi_settings_category">Wi-Fi settings</string> <string name="wifi_settings_category">Wi-Fi settings</string>
<!-- Title of the Wi-fi settings entry in the left top level menu -->
<string name="wifi_settings_title">Wi-Fi</string>
<!-- Summary text of the Wi-fi settings screen --> <!-- Summary text of the Wi-fi settings screen -->
<string name="wifi_settings_summary">Set up &amp; manage wireless access points</string> <string name="wifi_settings_summary">Set up &amp; manage wireless access points</string>
<!-- Summary text when turning Wi-Fi or bluetooth on --> <!-- Summary text when turning Wi-Fi or bluetooth on -->
<string name="wifi_starting">Turning on\u2026</string> <string name="wifi_starting">Turning on Wi-Fi\u2026</string>
<!-- Summary text when turning Wi-Fi or bluetooth off --> <!-- Summary text when turning Wi-Fi or bluetooth off -->
<string name="wifi_stopping">Turning off\u2026</string> <string name="wifi_stopping">Turning off Wi-Fi\u2026</string>
<!-- Summary text when Wi-Fi or bluetooth has error --> <!-- Summary text when Wi-Fi or bluetooth has error -->
<string name="wifi_error">Error</string> <string name="wifi_error">Error</string>
<!-- Toast message when Wi-Fi or bluetooth is disallowed in airplane mode --> <!-- Toast message when Wi-Fi or bluetooth is disallowed in airplane mode -->
@@ -1060,10 +1081,8 @@
<string name="wifi_setting_sleep_policy_summary_wifi_only">Specify when to disconnect from Wi-Fi</string> <string name="wifi_setting_sleep_policy_summary_wifi_only">Specify when to disconnect from Wi-Fi</string>
<!-- Generic error message when the sleep policy could not be set. --> <!-- Generic error message when the sleep policy could not be set. -->
<string name="wifi_setting_sleep_policy_error">There was a problem changing the setting</string> <string name="wifi_setting_sleep_policy_error">There was a problem changing the setting</string>
<!-- Action message to manually add a wifi network --> <!-- Action bar text message to manually add a wifi network [CHAR LIMIT=20]-->
<string name="wifi_add_network">Add Wi-Fi network</string> <string name="wifi_add_network">Add network</string>
<!-- Summary for add wifi network setting [CHAR LIMIT=50]-->
<string name="wifi_add_network_summary">Configure a non-broadcast network</string>
<!-- Header for the list of wifi networks--> <!-- Header for the list of wifi networks-->
<string name="wifi_access_points">Wi-Fi networks</string> <string name="wifi_access_points">Wi-Fi networks</string>
<!-- Menu option to scan Wi-Fi networks --> <!-- Menu option to scan Wi-Fi networks -->
@@ -1076,6 +1095,8 @@
<string name="wifi_menu_forget">Forget network</string> <string name="wifi_menu_forget">Forget network</string>
<!-- Menu option to modify a Wi-Fi network configuration --> <!-- Menu option to modify a Wi-Fi network configuration -->
<string name="wifi_menu_modify">Modify network</string> <string name="wifi_menu_modify">Modify network</string>
<!-- Wi-Fi settings. text displayed when WiFi is off and network list is empty [CHAR LIMIT=50]-->
<string name="wifi_empty_list_wifi_off">Turn on wifi to see available networks</string>
<!-- Dialog for Access Points --> <skip /> <!-- Dialog for Access Points --> <skip />
<!-- Label for network setup [CHAR LIMIT=50] --> <!-- Label for network setup [CHAR LIMIT=50] -->
@@ -1168,8 +1189,9 @@
<!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's current IP address. --> <!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's current IP address. -->
<string name="wifi_advanced_ip_address_title">IP address</string> <string name="wifi_advanced_ip_address_title">IP address</string>
<string name="wifi_ip_settings_titlebar">IP settings</string> <!-- Wifi Advanced settings. Used as a label under the shortcut icon that goes to Wifi advanced settings. [CHAR LIMIT=20]-->
<!-- Menu ietm to save the IP settings --> <string name="wifi_advanced_settings_label">IP settings</string>
<!-- Menu item to save the IP settings -->
<string name="wifi_ip_settings_menu_save">Save</string> <string name="wifi_ip_settings_menu_save">Save</string>
<!-- Menu ietm to cancel the IP settings --> <!-- Menu ietm to cancel the IP settings -->
<string name="wifi_ip_settings_menu_cancel">Cancel</string> <string name="wifi_ip_settings_menu_cancel">Cancel</string>
@@ -1918,6 +1940,10 @@
<!-- Tethering help button - calls up a web view with general tethering info --> <!-- Tethering help button - calls up a web view with general tethering info -->
<string name="tethering_help_button_text">Help</string> <string name="tethering_help_button_text">Help</string>
<!-- Wireless controls, header for the general category (airplane mode, VPN, NFC, tethering...) [CHAR LIMIT=40]-->
<string name="wireless_category_general">General</string>
<!-- Wireless controls, header for the mobile networks category (4G/ network operator...) [CHAR LIMIT=40]-->
<string name="wireless_category_mobile_networks">Mobile networks</string>
<!-- Wireless controls, item title to go into the network settings --> <!-- Wireless controls, item title to go into the network settings -->
<string name="network_settings_title">Mobile networks</string> <string name="network_settings_title">Mobile networks</string>
<!-- Wireless controls, the item summary for the user to go into the network settings --> <!-- Wireless controls, the item summary for the user to go into the network settings -->

View File

@@ -83,7 +83,7 @@
</style> </style>
<style name="wifi_item"> <style name="wifi_item">
<item name="android:layout_width">match_parent</item> <item name="android:layout_width">200dip</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">8dip</item> <item name="android:layout_marginTop">8dip</item>
<item name="android:layout_marginLeft">16dip</item> <item name="android:layout_marginLeft">16dip</item>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/bluetooth_advanced_titlebar">
<com.android.settings.bluetooth.BluetoothNamePreference
android:key="bt_name"
android:title="@string/bluetooth_device_name"
android:summary="@string/bluetooth_name_not_set"
android:dialogTitle="@string/bluetooth_device_name"
android:persistent="false"
android:singleLine="true" />
<CheckBoxPreference
android:key="bt_discoverable"
android:title="@string/bluetooth_visibility"
android:summaryOn="@string/bluetooth_is_discoverable"
android:summaryOff="@string/bluetooth_not_discoverable"
android:persistent="false" />
<ListPreference
android:key="bt_discoverable_timeout"
android:title="@string/bluetooth_visibility_timeout"
android:summary="@string/bluetooth_visibility_timeout_summary"
android:entries="@array/bluetooth_visibility_timeout_entries"
android:entryValues="@array/bluetooth_visibility_timeout_values" />
<Preference
android:key="bt_show_received_files"
android:title="@string/bluetooth_show_received_files_title"
android:summary="@string/bluetooth_show_received_files_summary" />
</PreferenceScreen>

View File

@@ -18,54 +18,4 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/bluetooth_settings" > android:title="@string/bluetooth_settings" >
<PreferenceCategory
android:title="@string/bluetooth_preference_device_settings"/>
<CheckBoxPreference
android:key="bt_checkbox"
android:title="@string/bluetooth"
android:summary="@string/bluetooth_quick_toggle_summary" />
<com.android.settings.bluetooth.BluetoothNamePreference
android:key="bt_name"
android:title="@string/bluetooth_device_name"
android:summary="@string/bluetooth_name_not_set"
android:dialogTitle="@string/bluetooth_device_name"
android:dependency="bt_checkbox"
android:persistent="false"
android:singleLine="true" />
<CheckBoxPreference
android:key="bt_discoverable"
android:title="@string/bluetooth_visibility"
android:dependency="bt_checkbox"
android:summaryOn="@string/bluetooth_is_discoverable"
android:summaryOff="@string/bluetooth_not_discoverable"
android:persistent="false" />
<ListPreference
android:key="bt_discoverable_timeout"
android:title="@string/bluetooth_visibility_timeout"
android:dependency="bt_discoverable"
android:summary="@string/bluetooth_visibility_timeout_summary"
android:entries="@array/bluetooth_visibility_timeout_entries"
android:entryValues="@array/bluetooth_visibility_timeout_values" />
<Preference
android:key="bt_show_received_files"
android:dependency="bt_checkbox"
android:title="@string/bluetooth_show_received_files_title"
android:summary="@string/bluetooth_show_received_files_summary" />
<PreferenceCategory
android:key="bt_device_list"
android:title="@string/bluetooth_preference_paired_devices"
android:orderingFromXml="false" />
<Preference
android:key="bt_find_nearby"
android:dependency="bt_checkbox"
android:fragment="com.android.settings.bluetooth.BluetoothFindNearby"
android:title="@string/bluetooth_preference_find_nearby_title" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -17,32 +17,32 @@
<preference-headers <preference-headers
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Operator hook -->
<!-- WIRELESS and NETWORKS -->
<header android:title="@string/header_category_wireless_networks" />
<!-- Wifi -->
<header <header
android:fragment="com.android.settings.WirelessSettings" android:id="@+id/wifi_settings"
android:id="@+id/operator_settings"> android:fragment="com.android.settings.wifi.WifiSettings"
<intent android:action="com.android.settings.OPERATOR_APPLICATION_SETTING" /> android:title="@string/wifi_settings_title"
</header>
<!-- Manufacturer hook -->
<header
android:fragment="com.android.settings.WirelessSettings"
android:id="@+id/manufacturer_settings">
<intent android:action="com.android.settings.MANUFACTURER_APPLICATION_SETTING" />
</header>
<!-- Wireless controls -->
<header
android:id="@+id/wireless_settings"
android:title="@string/radio_controls_title"
android:fragment="com.android.settings.WirelessSettings"
android:icon="@drawable/ic_settings_wireless" /> android:icon="@drawable/ic_settings_wireless" />
<!-- Call settings - this is in the phone process --> <!-- Bluetooth -->
<header
android:id="@+id/bluetooth_settings"
android:fragment="com.android.settings.bluetooth.BluetoothSettings"
android:title="@string/bluetooth_settings_title"
android:icon="@drawable/ic_settings_bluetooth2" />
<!-- Data Usage -->
<header
android:id="@+id/data_usage_settings"
android:fragment="com.android.settings.DataUsageSummary"
android:title="@string/data_usage_summary_title"
android:icon="@drawable/ic_settings_data_usage" />
<!-- Call settings - this is in the phone process -->
<header <header
android:id="@+id/call_settings" android:id="@+id/call_settings"
android:icon="@drawable/ic_settings_call" android:icon="@drawable/ic_settings_call"
@@ -53,8 +53,25 @@
android:targetClass="com.android.phone.CallFeaturesSetting" /> android:targetClass="com.android.phone.CallFeaturesSetting" />
</header> </header>
<!-- Sound --> <!-- Operator hook -->
<header
android:fragment="com.android.settings.WirelessSettings"
android:id="@+id/operator_settings">
<intent android:action="com.android.settings.OPERATOR_APPLICATION_SETTING" />
</header>
<!-- Other wireless and network controls -->
<header
android:id="@+id/wireless_settings"
android:title="@string/radio_controls_title"
android:fragment="com.android.settings.WirelessSettings"
android:icon="@drawable/ic_settings_more_wireless" />
<!-- DEVICE -->
<header android:title="@string/header_category_device" />
<!-- Sound -->
<header <header
android:id="@+id/sound_settings" android:id="@+id/sound_settings"
android:icon="@drawable/ic_settings_sound" android:icon="@drawable/ic_settings_sound"
@@ -62,73 +79,72 @@
android:title="@string/sound_settings_title" /> android:title="@string/sound_settings_title" />
<!-- Display --> <!-- Display -->
<header <header
android:id="@+id/display_settings" android:id="@+id/display_settings"
android:icon="@drawable/ic_settings_display" android:icon="@drawable/ic_settings_display"
android:fragment="com.android.settings.DisplaySettings" android:fragment="com.android.settings.DisplaySettings"
android:title="@string/display_settings_title" /> android:title="@string/display_settings_title" />
<!-- Security & Location -->
<header
android:fragment="com.android.settings.SecuritySettings"
android:icon="@drawable/ic_settings_security"
android:title="@string/security_settings_title"
android:id="@+id/security_settings" />
<!-- Application Settings -->
<header
android:fragment="com.android.settings.ApplicationSettings"
android:icon="@drawable/ic_settings_applications"
android:title="@string/applications_settings"
android:id="@+id/application_settings" />
<!-- Data Sync. The settings activity will ensure this is resolved to an
activity on the system image, otherwise it will remove this
preference. -->
<header
android:fragment="com.android.settings.accounts.ManageAccountsSettings"
android:icon="@drawable/ic_settings_sync"
android:title="@string/sync_settings"
android:id="@+id/sync_settings" />
<!-- Privacy -->
<header
android:fragment="com.android.settings.PrivacySettings"
android:icon="@drawable/ic_settings_privacy"
android:title="@string/privacy_settings"
android:id="@+id/privacy_settings" />
<!-- Storage --> <!-- Storage -->
<header <header
android:id="@+id/storage_settings" android:id="@+id/storage_settings"
android:fragment="com.android.settings.deviceinfo.Memory" android:fragment="com.android.settings.deviceinfo.Memory"
android:icon="@drawable/ic_settings_storage" android:icon="@drawable/ic_settings_storage"
android:title="@string/storage_settings" /> android:title="@string/storage_settings" />
<!-- Language --> <!-- Application Settings -->
<header
android:fragment="com.android.settings.ApplicationSettings"
android:icon="@drawable/ic_settings_applications"
android:title="@string/applications_settings"
android:id="@+id/application_settings" />
<!-- Manufacturer hook -->
<header
android:fragment="com.android.settings.WirelessSettings"
android:id="@+id/manufacturer_settings">
<intent android:action="com.android.settings.MANUFACTURER_APPLICATION_SETTING" />
</header>
<!-- PERSONAL -->
<header android:title="@string/header_category_personal" />
<!-- Data Sync. The settings activity will ensure this is resolved to an
activity on the system image, otherwise it will remove this
preference. -->
<header
android:fragment="com.android.settings.accounts.ManageAccountsSettings"
android:icon="@drawable/ic_settings_sync"
android:title="@string/sync_settings"
android:id="@+id/sync_settings" />
<!-- Security & Location -->
<header
android:fragment="com.android.settings.SecuritySettings"
android:icon="@drawable/ic_settings_security"
android:title="@string/security_settings_title"
android:id="@+id/security_settings" />
<!-- Privacy -->
<header
android:fragment="com.android.settings.PrivacySettings"
android:icon="@drawable/ic_settings_privacy"
android:title="@string/privacy_settings"
android:id="@+id/privacy_settings" />
<!-- Language -->
<header <header
android:id="@+id/language_settings" android:id="@+id/language_settings"
android:fragment="com.android.settings.inputmethod.InputMethodAndLanguageSettings" android:fragment="com.android.settings.inputmethod.InputMethodAndLanguageSettings"
android:icon="@drawable/ic_settings_language" android:icon="@drawable/ic_settings_language"
android:title="@string/language_settings" /> android:title="@string/language_settings" />
<!-- Accessibility feedback -->
<header <!-- SYSTEM -->
android:id="@+id/accessibility_settings" <header android:title="@string/header_category_system" />
android:fragment="com.android.settings.AccessibilitySettings"
android:icon="@drawable/ic_settings_accessibility"
android:title="@string/accessibility_settings" />
<!-- Dock --> <!-- Dock -->
<header <header
android:id="@+id/dock_settings" android:id="@+id/dock_settings"
android:fragment="com.android.settings.DockSettings" android:fragment="com.android.settings.DockSettings"
@@ -136,15 +152,20 @@
android:title="@string/dock_settings" /> android:title="@string/dock_settings" />
<!-- Date & Time --> <!-- Date & Time -->
<header <header
android:id="@+id/date_time_settings" android:id="@+id/date_time_settings"
android:fragment="com.android.settings.DateTimeSettings" android:fragment="com.android.settings.DateTimeSettings"
android:icon="@drawable/ic_settings_date_time" android:icon="@drawable/ic_settings_date_time"
android:title="@string/date_and_time_settings_title" /> android:title="@string/date_and_time_settings_title" />
<!-- About Device --> <!-- Accessibility feedback -->
<header
android:id="@+id/accessibility_settings"
android:fragment="com.android.settings.AccessibilitySettings"
android:icon="@drawable/ic_settings_accessibility"
android:title="@string/accessibility_settings" />
<!-- About Device -->
<header <header
android:id="@+id/about_settings" android:id="@+id/about_settings"
android:fragment="com.android.settings.DeviceInfoSettings" android:fragment="com.android.settings.DeviceInfoSettings"

View File

@@ -15,7 +15,4 @@
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.settings.wifi.AccessPointCategoryForSetupWizardXL
android:key="access_points"
android:persistent="false" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -17,6 +17,22 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/wifi_advanced_titlebar"> android:title="@string/wifi_advanced_titlebar">
<!-- android:dependency="enable_wifi" -->
<CheckBoxPreference
android:key="notify_open_networks"
android:title="@string/wifi_notify_open_networks"
android:summary="@string/wifi_notify_open_networks_summary"
android:persistent="false" />
<ListPreference
android:key="sleep_policy"
android:title="@string/wifi_setting_sleep_policy_title"
android:summary="@string/wifi_setting_sleep_policy_summary"
android:persistent="false"
android:entries="@array/wifi_sleep_policy_entries"
android:entryValues="@array/wifi_sleep_policy_values"
/>
<ListPreference <ListPreference
android:key="frequency_band" android:key="frequency_band"
android:title="@string/wifi_setting_frequency_band_title" android:title="@string/wifi_setting_frequency_band_title"

View File

@@ -17,39 +17,4 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/wifi_settings_category"> android:title="@string/wifi_settings_category">
<CheckBoxPreference
android:key="enable_wifi"
android:title="@string/wifi_quick_toggle_title"
android:summary="@string/wifi_quick_toggle_summary"
android:persistent="false" />
<CheckBoxPreference
android:key="notify_open_networks"
android:dependency="enable_wifi"
android:title="@string/wifi_notify_open_networks"
android:summary="@string/wifi_notify_open_networks_summary"
android:persistent="false" />
<ListPreference
android:key="sleep_policy"
android:title="@string/wifi_setting_sleep_policy_title"
android:summary="@string/wifi_setting_sleep_policy_summary"
android:persistent="false"
android:entries="@array/wifi_sleep_policy_entries"
android:entryValues="@array/wifi_sleep_policy_values"
/>
<com.android.settings.ProgressCategory
android:key="access_points"
android:dependency="enable_wifi"
android:title="@string/wifi_access_points"
android:persistent="false" />
<Preference
android:key="add_network"
android:dependency="enable_wifi"
android:title="@string/wifi_add_network"
android:summary="@string/wifi_add_network_summary"
android:persistent="false" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -17,6 +17,9 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/wireless_networks_settings_title"> android:title="@string/wireless_networks_settings_title">
<PreferenceCategory
android:title="@string/wireless_category_general" />
<CheckBoxPreference <CheckBoxPreference
android:key="toggle_airplane" android:key="toggle_airplane"
android:title="@string/airplane_mode" android:title="@string/airplane_mode"
@@ -24,31 +27,17 @@
android:persistent="false" android:persistent="false"
android:disableDependentsState="true" /> android:disableDependentsState="true" />
<!-- Programmatically will have dynamic summary, but we provide the fallback summary. -->
<CheckBoxPreference <CheckBoxPreference
android:key="toggle_wifi" android:key="toggle_nfc"
android:title="@string/wifi_quick_toggle_title" android:title="@string/nfc_quick_toggle_title"
android:summary="@string/wifi_quick_toggle_summary" android:summary="@string/nfc_quick_toggle_summary"
android:persistent="false" /> android:persistent="false" />
<PreferenceScreen <PreferenceScreen
android:fragment="com.android.settings.wifi.WifiSettings" android:fragment="com.android.settings.vpn.VpnSettings"
android:key="wifi_settings" android:key="vpn_settings"
android:title="@string/wifi_settings" android:title="@string/vpn_settings_title"
android:summary="@string/wifi_settings_summary" > android:summary="@string/vpn_settings_summary" >
</PreferenceScreen>
<CheckBoxPreference
android:key="toggle_bluetooth"
android:title="@string/bluetooth_quick_toggle_title"
android:summary="@string/bluetooth_quick_toggle_summary"
android:persistent="false" />
<PreferenceScreen
android:fragment="com.android.settings.bluetooth.BluetoothSettings"
android:key="bt_settings"
android:title="@string/bluetooth_settings_title"
android:summary="@string/bluetooth_settings_summary">
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen
@@ -58,18 +47,8 @@
android:summary="@string/tether_settings_summary_all"> android:summary="@string/tether_settings_summary_all">
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceCategory
android:fragment="com.android.settings.vpn.VpnSettings" android:title="@string/wireless_category_mobile_networks" />
android:key="vpn_settings"
android:title="@string/vpn_settings_title"
android:summary="@string/vpn_settings_summary" >
</PreferenceScreen>
<CheckBoxPreference
android:key="toggle_nfc"
android:title="@string/nfc_quick_toggle_title"
android:summary="@string/nfc_quick_toggle_summary"
android:persistent="false" />
<PreferenceScreen <PreferenceScreen
android:key="mobile_network_settings" android:key="mobile_network_settings"
@@ -89,9 +68,4 @@
android:summary="@string/proxy_settings_summary" > android:summary="@string/proxy_settings_summary" >
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen
android:fragment="com.android.settings.DataUsageSummary"
android:key="data_usage_summary"
android:title="@string/data_usage_summary_title" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -16,18 +16,33 @@
package com.android.settings; package com.android.settings;
import android.bluetooth.BluetoothAdapter;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.os.ServiceManager;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.Switch;
import android.widget.TextView;
import com.android.settings.bluetooth.BluetoothEnabler;
import com.android.settings.wifi.WifiEnabler;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -36,10 +51,11 @@ import java.util.List;
*/ */
public class Settings extends PreferenceActivity implements ButtonBarHandler { public class Settings extends PreferenceActivity implements ButtonBarHandler {
private static final String LOG_TAG = "Settings";
private static final String META_DATA_KEY_HEADER_ID = private static final String META_DATA_KEY_HEADER_ID =
"com.android.settings.TOP_LEVEL_HEADER_ID"; "com.android.settings.TOP_LEVEL_HEADER_ID";
private static final String META_DATA_KEY_FRAGMENT_CLASS = private static final String META_DATA_KEY_FRAGMENT_CLASS =
"com.android.settings.FRAGMENT_CLASS"; "com.android.settings.FRAGMENT_CLASS";
private static final String META_DATA_KEY_PARENT_TITLE = private static final String META_DATA_KEY_PARENT_TITLE =
"com.android.settings.PARENT_FRAGMENT_TITLE"; "com.android.settings.PARENT_FRAGMENT_TITLE";
private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS = private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS =
@@ -58,6 +74,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
// TODO: Update Call Settings based on airplane mode state. // TODO: Update Call Settings based on airplane mode state.
protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>(); protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
private List<Header> mHeaders;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -107,6 +124,26 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
} }
} }
@Override
public void onResume() {
super.onResume();
ListAdapter listAdapter = getListAdapter();
if (listAdapter instanceof HeaderAdapter) {
((HeaderAdapter) listAdapter).resume();
}
}
@Override
public void onPause() {
super.onPause();
ListAdapter listAdapter = getListAdapter();
if (listAdapter instanceof HeaderAdapter) {
((HeaderAdapter) listAdapter).pause();
}
}
private void switchToHeaderLocal(Header header) { private void switchToHeaderLocal(Header header) {
mInLocalHeaderSwitch = true; mInLocalHeaderSwitch = true;
switchToHeader(header); switchToHeader(header);
@@ -148,7 +185,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE); mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE);
} }
} catch (NameNotFoundException nnfe) { } catch (NameNotFoundException nnfe) {
Log.w("Settings", "Could not find parent activity : " + className); Log.w(LOG_TAG, "Could not find parent activity : " + className);
} }
} }
@@ -174,21 +211,22 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
@Override @Override
public Intent getIntent() { public Intent getIntent() {
String startingFragment = getStartingFragmentClass(super.getIntent()); Intent superIntent = super.getIntent();
String startingFragment = getStartingFragmentClass(superIntent);
if (startingFragment != null && !onIsMultiPane()) { if (startingFragment != null && !onIsMultiPane()) {
Intent modIntent = new Intent(super.getIntent()); Intent modIntent = new Intent(superIntent);
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
Bundle args = super.getIntent().getExtras(); Bundle args = superIntent.getExtras();
if (args != null) { if (args != null) {
args = new Bundle(args); args = new Bundle(args);
} else { } else {
args = new Bundle(); args = new Bundle();
} }
args.putParcelable("intent", super.getIntent()); args.putParcelable("intent", superIntent);
modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, super.getIntent().getExtras()); modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras());
return modIntent; return modIntent;
} }
return super.getIntent(); return superIntent;
} }
/** /**
@@ -204,7 +242,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
if ("com.android.settings.ManageApplications".equals(intentClass) if ("com.android.settings.ManageApplications".equals(intentClass)
|| "com.android.settings.RunningServices".equals(intentClass) || "com.android.settings.RunningServices".equals(intentClass)
|| "com.android.settings.applications.StorageUse".equals(intentClass)) { || "com.android.settings.applications.StorageUse".equals(intentClass)) {
// Old name of manage apps. // Old names of manage apps.
intentClass = com.android.settings.applications.ManageApplications.class.getName(); intentClass = com.android.settings.applications.ManageApplications.class.getName();
} }
@@ -226,7 +264,18 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
mCurrentHeader = header; mCurrentHeader = header;
return header; return header;
} }
return super.onGetInitialHeader();
// Find first non-category header
int position = 0;
while (position < mHeaders.size()) {
Header header = mHeaders.get(position);
if (HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY)
return header;
position++;
}
Log.e(LOG_TAG, "Unable to find a non-category header");
return null;
} }
@Override @Override
@@ -242,10 +291,12 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
* Populate the activity with the top-level headers. * Populate the activity with the top-level headers.
*/ */
@Override @Override
public void onBuildHeaders(List<Header> target) { public void onBuildHeaders(List<Header> headers) {
loadHeadersFromResource(R.xml.settings_headers, target); loadHeadersFromResource(R.xml.settings_headers, headers);
updateHeaderList(target); updateHeaderList(headers);
mHeaders = headers;
} }
private void updateHeaderList(List<Header> target) { private void updateHeaderList(List<Header> target) {
@@ -262,7 +313,13 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
} else if (id == R.id.call_settings) { } else if (id == R.id.call_settings) {
if (!Utils.isVoiceCapable(this)) if (!Utils.isVoiceCapable(this))
target.remove(header); target.remove(header);
} else if (id == R.id.bluetooth_settings) {
// Remove Bluetooth Settings if Bluetooth service is not available.
if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
target.remove(header);
}
} }
// Increment if the current one wasn't removed by the Utils code. // Increment if the current one wasn't removed by the Utils code.
if (target.get(i) == header) { if (target.get(i) == header) {
// Hold on to the first header, when we need to reset to the top-level // Hold on to the first header, when we need to reset to the top-level
@@ -296,6 +353,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
} }
} }
} catch (NameNotFoundException nnfe) { } catch (NameNotFoundException nnfe) {
// No recovery
} }
} }
@@ -309,39 +367,197 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
return super.getNextButton(); return super.getNextButton();
} }
private static class HeaderAdapter extends ArrayAdapter<Header> {
static final int HEADER_TYPE_CATEGORY = 0;
static final int HEADER_TYPE_NORMAL = 1;
static final int HEADER_TYPE_SWITCH = 2;
private static final int HEADER_TYPE_COUNT = HEADER_TYPE_SWITCH + 1;
private final WifiEnabler mWifiEnabler;
private final BluetoothEnabler mBluetoothEnabler;
private static class HeaderViewHolder {
ImageView icon;
TextView title;
TextView summary;
Switch switch_;
}
private LayoutInflater mInflater;
static int getHeaderType(Header header) {
if (header.fragment == null && header.intent == null) {
return HEADER_TYPE_CATEGORY;
} else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) {
return HEADER_TYPE_SWITCH;
} else {
return HEADER_TYPE_NORMAL;
}
}
@Override
public int getItemViewType(int position) {
Header header = getItem(position);
return getHeaderType(header);
}
@Override
public boolean areAllItemsEnabled() {
return false; // because of categories
}
@Override
public boolean isEnabled(int position) {
return getItemViewType(position) != HEADER_TYPE_CATEGORY;
}
@Override
public int getViewTypeCount() {
return HEADER_TYPE_COUNT;
}
@Override
public boolean hasStableIds() {
return true;
}
public HeaderAdapter(Context context, List<Header> objects) {
super(context, 0, objects);
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// These Switches are provided as placeholder until the adapter replaces these with actual
// Switches inflated from their layouts. Must be done before adapter is set in super
mWifiEnabler = new WifiEnabler(context, new Switch(context));
mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder;
Header header = getItem(position);
int headerType = getHeaderType(header);
View view = null;
if (convertView == null) {
holder = new HeaderViewHolder();
switch (headerType) {
case HEADER_TYPE_CATEGORY:
view = new TextView(getContext(), null, android.R.attr.listSeparatorTextViewStyle);
holder.title = (TextView) view;
break;
case HEADER_TYPE_SWITCH:
view = mInflater.inflate(R.layout.preference_header_switch_item, parent, false);
holder.icon = (ImageView) view.findViewById(R.id.icon);
holder.title = (TextView) view.findViewById(com.android.internal.R.id.title);
holder.summary = (TextView) view.findViewById(com.android.internal.R.id.summary);
holder.switch_ = (Switch) view.findViewById(R.id.switchWidget);
break;
case HEADER_TYPE_NORMAL:
view = mInflater.inflate(com.android.internal.R.layout.preference_header_item, parent, false);
holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon);
holder.title = (TextView) view.findViewById(com.android.internal.R.id.title);
holder.summary = (TextView) view.findViewById(com.android.internal.R.id.summary);
break;
}
view.setTag(holder);
} else {
view = convertView;
holder = (HeaderViewHolder) view.getTag();
}
// All view fields must be updated every time, because the view may be recycled
switch (headerType) {
case HEADER_TYPE_CATEGORY:
holder.title.setText(header.getTitle(getContext().getResources()));
break;
case HEADER_TYPE_SWITCH:
// Would need a different treatment if the main menu had more switches
if (header.id == R.id.wifi_settings) {
mWifiEnabler.setSwitch(holder.switch_);
} else {
mBluetoothEnabler.setSwitch(holder.switch_);
}
// No break, fall through on purpose to update common fields
//$FALL-THROUGH$
case HEADER_TYPE_NORMAL:
holder.icon.setImageResource(header.iconRes);
holder.title.setText(header.getTitle(getContext().getResources()));
CharSequence summary = header.getSummary(getContext().getResources());
if (!TextUtils.isEmpty(summary)) {
holder.summary.setVisibility(View.VISIBLE);
holder.summary.setText(summary);
} else {
holder.summary.setVisibility(View.GONE);
}
break;
}
return view;
}
public void resume() {
mWifiEnabler.resume();
mBluetoothEnabler.resume();
}
public void pause() {
mWifiEnabler.pause();
mBluetoothEnabler.pause();
}
}
@Override
public void setListAdapter(ListAdapter adapter) {
if (mHeaders == null) {
mHeaders = new ArrayList<Header>();
// When the saved state provides the list of headers, onBuildHeaders is not called
// Copy the list of Headers from the adapter, preserving their order
for (int i = 0; i < adapter.getCount(); i++) {
mHeaders.add((Header) adapter.getItem(i));
}
}
// Ignore the adapter provided by PreferenceActivity and substitute ours instead
super.setListAdapter(new HeaderAdapter(this, mHeaders));
}
/* /*
* Settings subclasses for launching independently. * Settings subclasses for launching independently.
*/ */
public static class BluetoothSettingsActivity extends Settings { } public static class BluetoothSettingsActivity extends Settings { /* empty */ }
public static class WirelessSettingsActivity extends Settings { } public static class WirelessSettingsActivity extends Settings { /* empty */ }
public static class TetherSettingsActivity extends Settings { } public static class TetherSettingsActivity extends Settings { /* empty */ }
public static class VpnSettingsActivity extends Settings { } public static class VpnSettingsActivity extends Settings { /* empty */ }
public static class DateTimeSettingsActivity extends Settings { } public static class DateTimeSettingsActivity extends Settings { /* empty */ }
public static class StorageSettingsActivity extends Settings { } public static class StorageSettingsActivity extends Settings { /* empty */ }
public static class WifiSettingsActivity extends Settings { } public static class WifiSettingsActivity extends Settings { /* empty */ }
public static class InputMethodAndLanguageSettingsActivity extends Settings { } public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ }
public static class InputMethodConfigActivity extends Settings { } public static class InputMethodConfigActivity extends Settings { /* empty */ }
public static class InputMethodAndSubtypeEnablerActivity extends Settings { } public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ }
public static class LocalePickerActivity extends Settings { } public static class LocalePickerActivity extends Settings { /* empty */ }
public static class UserDictionarySettingsActivity extends Settings { } public static class UserDictionarySettingsActivity extends Settings { /* empty */ }
public static class SoundSettingsActivity extends Settings { } public static class SoundSettingsActivity extends Settings { /* empty */ }
public static class DisplaySettingsActivity extends Settings { } public static class DisplaySettingsActivity extends Settings { /* empty */ }
public static class DeviceInfoSettingsActivity extends Settings { } public static class DeviceInfoSettingsActivity extends Settings { /* empty */ }
public static class ApplicationSettingsActivity extends Settings { } public static class ApplicationSettingsActivity extends Settings { /* empty */ }
public static class ManageApplicationsActivity extends Settings { } public static class ManageApplicationsActivity extends Settings { /* empty */ }
public static class StorageUseActivity extends Settings { } public static class StorageUseActivity extends Settings { /* empty */ }
public static class DevelopmentSettingsActivity extends Settings { } public static class DevelopmentSettingsActivity extends Settings { /* empty */ }
public static class AccessibilitySettingsActivity extends Settings { } public static class AccessibilitySettingsActivity extends Settings { /* empty */ }
public static class SecuritySettingsActivity extends Settings { } public static class SecuritySettingsActivity extends Settings { /* empty */ }
public static class PrivacySettingsActivity extends Settings { } public static class PrivacySettingsActivity extends Settings { /* empty */ }
public static class DockSettingsActivity extends Settings { } public static class DockSettingsActivity extends Settings { /* empty */ }
public static class RunningServicesActivity extends Settings { } public static class RunningServicesActivity extends Settings { /* empty */ }
public static class ManageAccountsSettingsActivity extends Settings { } public static class ManageAccountsSettingsActivity extends Settings { /* empty */ }
public static class PowerUsageSummaryActivity extends Settings { } public static class PowerUsageSummaryActivity extends Settings { /* empty */ }
public static class AccountSyncSettingsActivity extends Settings { } public static class AccountSyncSettingsActivity extends Settings { /* empty */ }
public static class AccountSyncSettingsInAddAccountActivity extends Settings { } public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ }
public static class CryptKeeperSettingsActivity extends Settings { } public static class CryptKeeperSettingsActivity extends Settings { /* empty */ }
public static class DeviceAdminSettingsActivity extends Settings { } public static class DeviceAdminSettingsActivity extends Settings { /* empty */ }
public static class DataUsageSummaryActivity extends Settings { } public static class DataUsageSummaryActivity extends Settings { /* empty */ }
} }

View File

@@ -16,35 +16,27 @@
package com.android.settings; package com.android.settings;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.settings.bluetooth.BluetoothEnabler;
import com.android.settings.wifi.WifiEnabler;
import com.android.settings.nfc.NfcEnabler;
import android.app.Activity; import android.app.Activity;
import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.nfc.NfcAdapter; import android.nfc.NfcAdapter;
import android.os.Bundle; import android.os.Bundle;
import android.os.ServiceManager;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.provider.Settings; import android.provider.Settings;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.settings.nfc.NfcEnabler;
public class WirelessSettings extends SettingsPreferenceFragment { public class WirelessSettings extends SettingsPreferenceFragment {
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
private static final String KEY_TOGGLE_WIFI = "toggle_wifi";
private static final String KEY_TOGGLE_NFC = "toggle_nfc"; private static final String KEY_TOGGLE_NFC = "toggle_nfc";
private static final String KEY_WIFI_SETTINGS = "wifi_settings";
private static final String KEY_BT_SETTINGS = "bt_settings";
private static final String KEY_VPN_SETTINGS = "vpn_settings"; private static final String KEY_VPN_SETTINGS = "vpn_settings";
private static final String KEY_TETHER_SETTINGS = "tether_settings"; private static final String KEY_TETHER_SETTINGS = "tether_settings";
private static final String KEY_PROXY_SETTINGS = "proxy_settings"; private static final String KEY_PROXY_SETTINGS = "proxy_settings";
@@ -55,9 +47,7 @@ public class WirelessSettings extends SettingsPreferenceFragment {
private AirplaneModeEnabler mAirplaneModeEnabler; private AirplaneModeEnabler mAirplaneModeEnabler;
private CheckBoxPreference mAirplaneModePreference; private CheckBoxPreference mAirplaneModePreference;
private WifiEnabler mWifiEnabler;
private NfcEnabler mNfcEnabler; private NfcEnabler mNfcEnabler;
private BluetoothEnabler mBtEnabler;
/** /**
* Invoked on each preference click in this hierarchy, overrides * Invoked on each preference click in this hierarchy, overrides
@@ -95,15 +85,10 @@ public class WirelessSettings extends SettingsPreferenceFragment {
addPreferencesFromResource(R.xml.wireless_settings); addPreferencesFromResource(R.xml.wireless_settings);
final Activity activity = getActivity(); final Activity activity = getActivity();
CheckBoxPreference airplane = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE); mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
CheckBoxPreference wifi = (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI);
CheckBoxPreference bt = (CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH);
CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC); CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
mAirplaneModeEnabler = new AirplaneModeEnabler(activity, airplane); mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
mWifiEnabler = new WifiEnabler(activity, wifi);
mBtEnabler = new BluetoothEnabler(activity, bt);
mNfcEnabler = new NfcEnabler(activity, nfc); mNfcEnabler = new NfcEnabler(activity, nfc);
String toggleable = Settings.System.getString(activity.getContentResolver(), String toggleable = Settings.System.getString(activity.getContentResolver(),
@@ -111,21 +96,12 @@ public class WirelessSettings extends SettingsPreferenceFragment {
// Manually set dependencies for Wifi when not toggleable. // Manually set dependencies for Wifi when not toggleable.
if (toggleable == null || !toggleable.contains(Settings.System.RADIO_WIFI)) { if (toggleable == null || !toggleable.contains(Settings.System.RADIO_WIFI)) {
wifi.setDependency(KEY_TOGGLE_AIRPLANE);
findPreference(KEY_WIFI_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
} }
// Manually set dependencies for Bluetooth when not toggleable. // Manually set dependencies for Bluetooth when not toggleable.
if (toggleable == null || !toggleable.contains(Settings.System.RADIO_BLUETOOTH)) { if (toggleable == null || !toggleable.contains(Settings.System.RADIO_BLUETOOTH)) {
bt.setDependency(KEY_TOGGLE_AIRPLANE); // No bluetooth-dependent items in the list. Code kept in case one is added later.
findPreference(KEY_BT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
}
// Remove Bluetooth Settings if Bluetooth service is not available.
if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
getPreferenceScreen().removePreference(bt);
getPreferenceScreen().removePreference(findPreference(KEY_BT_SETTINGS));
} }
// Remove NFC if its not available // Remove NFC if its not available
@@ -191,8 +167,6 @@ public class WirelessSettings extends SettingsPreferenceFragment {
super.onResume(); super.onResume();
mAirplaneModeEnabler.resume(); mAirplaneModeEnabler.resume();
mWifiEnabler.resume();
mBtEnabler.resume();
mNfcEnabler.resume(); mNfcEnabler.resume();
} }
@@ -201,8 +175,6 @@ public class WirelessSettings extends SettingsPreferenceFragment {
super.onPause(); super.onPause();
mAirplaneModeEnabler.pause(); mAirplaneModeEnabler.pause();
mWifiEnabler.pause();
mBtEnabler.pause();
mNfcEnabler.pause(); mNfcEnabler.pause();
} }

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.bluetooth;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
public class AdvancedBluetoothSettings extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {
private static final String KEY_BT_DISCOVERABLE = "bt_discoverable";
private static final String KEY_BT_DISCOVERABLE_TIMEOUT = "bt_discoverable_timeout";
private static final String KEY_BT_NAME = "bt_name";
private static final String KEY_BT_SHOW_RECEIVED = "bt_show_received_files";
/* Private intent to show the list of received files */
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
"android.btopp.intent.action.OPEN_RECEIVED_FILES";
private BluetoothDiscoverableEnabler mDiscoverableEnabler;
private BluetoothNamePreference mNamePreference;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.bluetooth_advanced_settings);
LocalBluetoothManager localManager = LocalBluetoothManager.getInstance(getActivity());
if (localManager != null) {
LocalBluetoothAdapter localAdapter = localManager.getBluetoothAdapter();
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),
localAdapter,
(CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE),
(ListPreference) findPreference(KEY_BT_DISCOVERABLE_TIMEOUT));
}
mNamePreference = (BluetoothNamePreference) findPreference(KEY_BT_NAME);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
mDiscoverableEnabler.resume();
mNamePreference.resume();
}
@Override
public void onPause() {
super.onPause();
mNamePreference.pause();
mDiscoverableEnabler.pause();
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (KEY_BT_SHOW_RECEIVED.equals(preference.getKey())) {
Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
getActivity().sendBroadcast(intent);
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
}

View File

@@ -16,28 +16,27 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import com.android.settings.R;
import com.android.settings.WirelessSettings;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.preference.Preference;
import android.preference.CheckBoxPreference;
import android.provider.Settings; import android.provider.Settings;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast; import android.widget.Toast;
import com.android.settings.R;
import com.android.settings.WirelessSettings;
/** /**
* BluetoothEnabler is a helper to manage the Bluetooth on/off checkbox * BluetoothEnabler is a helper to manage the Bluetooth on/off checkbox
* preference. It turns on/off Bluetooth and ensures the summary of the * preference. It turns on/off Bluetooth and ensures the summary of the
* preference reflects the current state. * preference reflects the current state.
*/ */
public final class BluetoothEnabler implements Preference.OnPreferenceChangeListener { public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeListener {
private final Context mContext; private final Context mContext;
private final CheckBoxPreference mCheckBox; private Switch mSwitch;
private final CharSequence mOriginalSummary;
private final LocalBluetoothAdapter mLocalAdapter; private final LocalBluetoothAdapter mLocalAdapter;
private final IntentFilter mIntentFilter; private final IntentFilter mIntentFilter;
@@ -50,17 +49,15 @@ public final class BluetoothEnabler implements Preference.OnPreferenceChangeList
} }
}; };
public BluetoothEnabler(Context context, CheckBoxPreference checkBox) { public BluetoothEnabler(Context context, Switch switch_) {
mContext = context; mContext = context;
mCheckBox = checkBox; mSwitch = switch_;
mOriginalSummary = checkBox.getSummary();
checkBox.setPersistent(false);
LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context); LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context);
if (manager == null) { if (manager == null) {
// Bluetooth is not supported // Bluetooth is not supported
mLocalAdapter = null; mLocalAdapter = null;
checkBox.setEnabled(false); mSwitch.setEnabled(false);
} else { } else {
mLocalAdapter = manager.getBluetoothAdapter(); mLocalAdapter = manager.getBluetoothAdapter();
} }
@@ -76,7 +73,7 @@ public final class BluetoothEnabler implements Preference.OnPreferenceChangeList
handleStateChanged(mLocalAdapter.getBluetoothState()); handleStateChanged(mLocalAdapter.getBluetoothState());
mContext.registerReceiver(mReceiver, mIntentFilter); mContext.registerReceiver(mReceiver, mIntentFilter);
mCheckBox.setOnPreferenceChangeListener(this); mSwitch.setOnCheckedChangeListener(this);
} }
public void pause() { public void pause() {
@@ -85,51 +82,54 @@ public final class BluetoothEnabler implements Preference.OnPreferenceChangeList
} }
mContext.unregisterReceiver(mReceiver); mContext.unregisterReceiver(mReceiver);
mCheckBox.setOnPreferenceChangeListener(null); mSwitch.setOnCheckedChangeListener(null);
} }
public boolean onPreferenceChange(Preference preference, Object value) { public void setSwitch(Switch switch_) {
boolean enable = (Boolean) value; if (mSwitch == switch_) return;
mSwitch.setOnCheckedChangeListener(null);
mSwitch = switch_;
mSwitch.setOnCheckedChangeListener(this);
final int bluetoothState = mLocalAdapter.getBluetoothState();
boolean isEnabled = bluetoothState == BluetoothAdapter.STATE_ON;
boolean isDisabled = bluetoothState == BluetoothAdapter.STATE_OFF;
mSwitch.setChecked(isEnabled);
mSwitch.setEnabled(isEnabled || isDisabled);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Show toast message if Bluetooth is not allowed in airplane mode // Show toast message if Bluetooth is not allowed in airplane mode
if (enable && !WirelessSettings if (isChecked &&
.isRadioAllowed(mContext, Settings.System.RADIO_BLUETOOTH)) { !WirelessSettings.isRadioAllowed(mContext, Settings.System.RADIO_BLUETOOTH)) {
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
Toast.LENGTH_SHORT).show(); // Reset switch to off
return false; buttonView.setChecked(false);
} }
mLocalAdapter.setBluetoothEnabled(enable); mLocalAdapter.setBluetoothEnabled(isChecked);
mCheckBox.setEnabled(false); mSwitch.setEnabled(false);
// Don't update UI to opposite state until we're sure
return false;
} }
void handleStateChanged(int state) { void handleStateChanged(int state) {
switch (state) { switch (state) {
case BluetoothAdapter.STATE_TURNING_ON: case BluetoothAdapter.STATE_TURNING_ON:
mCheckBox.setSummary(R.string.wifi_starting); mSwitch.setEnabled(false);
mCheckBox.setEnabled(false);
break; break;
case BluetoothAdapter.STATE_ON: case BluetoothAdapter.STATE_ON:
mCheckBox.setChecked(true); mSwitch.setChecked(true);
mCheckBox.setSummary(null); mSwitch.setEnabled(true);
mCheckBox.setEnabled(true);
break; break;
case BluetoothAdapter.STATE_TURNING_OFF: case BluetoothAdapter.STATE_TURNING_OFF:
mCheckBox.setSummary(R.string.wifi_stopping); mSwitch.setEnabled(false);
mCheckBox.setEnabled(false);
break; break;
case BluetoothAdapter.STATE_OFF: case BluetoothAdapter.STATE_OFF:
mCheckBox.setChecked(false); mSwitch.setChecked(false);
mCheckBox.setSummary(mOriginalSummary); mSwitch.setEnabled(true);
mCheckBox.setEnabled(true);
break; break;
default: default:
mCheckBox.setChecked(false); mSwitch.setChecked(false);
mCheckBox.setSummary(R.string.wifi_error); mSwitch.setEnabled(true);
mCheckBox.setEnabled(true);
} }
} }
} }

View File

@@ -16,15 +16,20 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import android.app.ActionBar;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Switch;
import com.android.settings.R; import com.android.settings.R;
@@ -35,77 +40,120 @@ import com.android.settings.R;
public final class BluetoothSettings extends DeviceListPreferenceFragment { public final class BluetoothSettings extends DeviceListPreferenceFragment {
private static final String TAG = "BluetoothSettings"; private static final String TAG = "BluetoothSettings";
private static final String KEY_BT_CHECKBOX = "bt_checkbox"; private static final int MENU_ID_MAKE_DISCOVERABLE = Menu.FIRST;
private static final String KEY_BT_DISCOVERABLE = "bt_discoverable"; private static final int MENU_ID_SCAN = Menu.FIRST + 1;
private static final String KEY_BT_DISCOVERABLE_TIMEOUT = "bt_discoverable_timeout"; private static final int MENU_ID_ADVANCED = Menu.FIRST + 2;
private static final String KEY_BT_NAME = "bt_name";
private static final String KEY_BT_SHOW_RECEIVED = "bt_show_received_files";
private BluetoothEnabler mEnabler; private BluetoothEnabler mBluetoothEnabler;
private BluetoothDiscoverableEnabler mDiscoverableEnabler;
private BluetoothNamePreference mNamePreference;
/* Private intent to show the list of received files */
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
"android.btopp.intent.action.OPEN_RECEIVED_FILES";
/** Initialize the filter to show bonded devices only. */ /** Initialize the filter to show bonded devices only. */
public BluetoothSettings() { //public BluetoothSettings() {
super(BluetoothDeviceFilter.BONDED_DEVICE_FILTER); // super(BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
} //}
@Override @Override
void addPreferencesForActivity() { void addPreferencesForActivity() {
addPreferencesFromResource(R.xml.bluetooth_settings); addPreferencesFromResource(R.xml.bluetooth_settings);
mEnabler = new BluetoothEnabler(getActivity(), Activity activity = getActivity();
(CheckBoxPreference) findPreference(KEY_BT_CHECKBOX));
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(), Switch actionBarSwitch = new Switch(activity);
mLocalAdapter,
(CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE),
(ListPreference) findPreference(KEY_BT_DISCOVERABLE_TIMEOUT));
mNamePreference = (BluetoothNamePreference) findPreference(KEY_BT_NAME); if (activity instanceof PreferenceActivity) {
PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
final int padding = activity.getResources().getDimensionPixelSize(
R.dimen.action_bar_switch_padding);
actionBarSwitch.setPadding(0, 0, padding, 0);
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM);
activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.RIGHT));
}
}
mBluetoothEnabler = new BluetoothEnabler(activity, actionBarSwitch);
if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {
activity.getActionBar().setSubtitle(mLocalAdapter.getName());
}
// TODO activity.setTheme(android.R.style.Theme_Holo_SplitActionBarWhenNarrow);
setHasOptionsMenu(true);
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
// Repopulate (which isn't too bad since it's cached in the settings mBluetoothEnabler.resume();
// bluetooth manager)
addDevices();
mEnabler.resume(); updateContent(mLocalAdapter.getBluetoothState());
mDiscoverableEnabler.resume();
mNamePreference.resume();
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
mNamePreference.pause(); mBluetoothEnabler.pause();
mDiscoverableEnabler.pause(); }
mEnabler.pause();
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
menu.add(Menu.NONE, MENU_ID_MAKE_DISCOVERABLE, 0, R.string.bluetooth_visibility)
.setEnabled(bluetoothIsEnabled);
menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.bluetooth_preference_find_nearby_title)
.setIcon(R.drawable.ic_menu_scan_network).setEnabled(bluetoothIsEnabled);
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.bluetooth_menu_advanced)
.setIcon(android.R.drawable.ic_menu_manage);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ID_MAKE_DISCOVERABLE:
// TODO
// if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON) {
// onAddNetworkPressed();
// }
return true;
case MENU_ID_SCAN:
if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON) {
mLocalAdapter.startScanning(true);
}
return true;
case MENU_ID_ADVANCED:
if (getActivity() instanceof PreferenceActivity) {
((PreferenceActivity) getActivity()).startPreferencePanel(
AdvancedBluetoothSettings.class.getCanonicalName(),
null,
R.string.bluetooth_advanced_titlebar, null,
this, 0);
} else {
startFragment(this, AdvancedBluetoothSettings.class.getCanonicalName(), -1, null);
}
return true;
}
return super.onOptionsItemSelected(item);
} }
private final View.OnClickListener mListener = new View.OnClickListener() { private final View.OnClickListener mListener = new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
// User clicked on advanced options icon for a device in the list // User clicked on advanced options icon for a device in the list
if (v.getTag() instanceof CachedBluetoothDevice) { if (v.getTag() instanceof CachedBluetoothDevice) {
CachedBluetoothDevice CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
device = (CachedBluetoothDevice) v.getTag();
Preference pref = new Preference(getActivity()); Preference pref = new Preference(getActivity());
pref.setTitle(device.getName()); pref.setTitle(device.getName());
pref.setFragment(DeviceProfilesSettings.class.getName()); pref.setFragment(DeviceProfilesSettings.class.getName());
pref.getExtras().putParcelable(DeviceProfilesSettings.EXTRA_DEVICE, pref.getExtras().putParcelable(DeviceProfilesSettings.EXTRA_DEVICE,
device.getDevice()); device.getDevice());
((PreferenceActivity) getActivity()) ((PreferenceActivity) getActivity()).onPreferenceStartFragment(
.onPreferenceStartFragment(BluetoothSettings.this, BluetoothSettings.this, pref);
pref);
} else { } else {
Log.w(TAG, "onClick() called for other View: " + v); Log.w(TAG, "onClick() called for other View: " + v);
} }
@@ -113,19 +161,54 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
}; };
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, void onDevicePreferenceClick(BluetoothDevicePreference btPreference) {
Preference preference) { mLocalAdapter.stopScanning();
if (KEY_BT_SHOW_RECEIVED.equals(preference.getKey())) { super.onDevicePreferenceClick(btPreference);
Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
getActivity().sendBroadcast(intent);
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
} }
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, @Override
int bondState) { public void onBluetoothStateChanged(int bluetoothState) {
super.onBluetoothStateChanged(bluetoothState);
updateContent(bluetoothState);
}
private void updateContent(int bluetoothState) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
getActivity().invalidateOptionsMenu();
int messageId = 0;
switch (bluetoothState) {
case BluetoothAdapter.STATE_ON:
preferenceScreen.removeAll();
// Repopulate (which isn't too bad since it's cached in the settings bluetooth manager)
addDevices();
mLocalAdapter.startScanning(false);
return;
case BluetoothAdapter.STATE_TURNING_OFF:
int preferenceCount = preferenceScreen.getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
preferenceScreen.getPreference(i).setEnabled(false);
}
return;
case BluetoothAdapter.STATE_OFF:
messageId = R.string.bluetooth_empty_list_bluetooth_off;
break;
case BluetoothAdapter.STATE_TURNING_ON:
messageId = R.string.bluetooth_turning_on;
break;
}
removeAllDevices();
// TODO: from xml, add top padding. Same as in wifi
Preference emptyListPreference = new Preference(getActivity());
emptyListPreference.setTitle(messageId);
preferenceScreen.addPreference(emptyListPreference);
}
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
if (bondState == BluetoothDevice.BOND_BONDED) { if (bondState == BluetoothDevice.BOND_BONDED) {
// add to "Paired devices" list after remote-initiated pairing // add to "Paired devices" list after remote-initiated pairing
if (mDevicePreferenceMap.get(cachedDevice) == null) { if (mDevicePreferenceMap.get(cachedDevice) == null) {

View File

@@ -21,6 +21,7 @@ import android.bluetooth.BluetoothDevice;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.util.Log; import android.util.Log;
@@ -36,7 +37,6 @@ import java.util.WeakHashMap;
* *
* @see BluetoothSettings * @see BluetoothSettings
* @see DevicePickerFragment * @see DevicePickerFragment
* @see BluetoothFindNearby
*/ */
public abstract class DeviceListPreferenceFragment extends public abstract class DeviceListPreferenceFragment extends
SettingsPreferenceFragment implements BluetoothCallback { SettingsPreferenceFragment implements BluetoothCallback {
@@ -53,7 +53,7 @@ public abstract class DeviceListPreferenceFragment extends
LocalBluetoothAdapter mLocalAdapter; LocalBluetoothAdapter mLocalAdapter;
LocalBluetoothManager mLocalManager; LocalBluetoothManager mLocalManager;
private PreferenceCategory mDeviceList; private PreferenceGroup mDeviceListGroup;
final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap = final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap =
new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>(); new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>();
@@ -83,8 +83,13 @@ public abstract class DeviceListPreferenceFragment extends
addPreferencesForActivity(); addPreferencesForActivity();
mDeviceList = (PreferenceCategory) findPreference(KEY_BT_DEVICE_LIST); mDeviceListGroup = (PreferenceCategory) findPreference(KEY_BT_DEVICE_LIST);
if (mDeviceList == null) { if (mDeviceListGroup == null) {
// If null, device preferences are added directly to the root of the preference screen
mDeviceListGroup = getPreferenceScreen();
mDeviceListGroup.setOrderingAsAdded(false);
}
if (mDeviceListGroup == null) {
Log.e(TAG, "Could not find device list preference object!"); Log.e(TAG, "Could not find device list preference object!");
} }
} }
@@ -105,13 +110,15 @@ public abstract class DeviceListPreferenceFragment extends
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
removeAllDevices();
mLocalAdapter.stopScanning();
mLocalManager.setForegroundActivity(null); mLocalManager.setForegroundActivity(null);
mLocalManager.getEventManager().unregisterCallback(this); mLocalManager.getEventManager().unregisterCallback(this);
}
void removeAllDevices() {
mLocalAdapter.stopScanning();
mDevicePreferenceMap.clear(); mDevicePreferenceMap.clear();
mDeviceList.removeAll(); mDeviceListGroup.removeAll();
} }
void addDevices() { void addDevices() {
@@ -132,7 +139,7 @@ public abstract class DeviceListPreferenceFragment extends
} }
if (preference instanceof BluetoothDevicePreference) { if (preference instanceof BluetoothDevicePreference) {
BluetoothDevicePreference btPreference = (BluetoothDevicePreference)preference; BluetoothDevicePreference btPreference = (BluetoothDevicePreference) preference;
CachedBluetoothDevice device = btPreference.getCachedDevice(); CachedBluetoothDevice device = btPreference.getCachedDevice();
mSelectedDevice = device.getDevice(); mSelectedDevice = device.getDevice();
onDevicePreferenceClick(btPreference); onDevicePreferenceClick(btPreference);
@@ -152,6 +159,9 @@ public abstract class DeviceListPreferenceFragment extends
return; return;
} }
// No update while list shows state message
if (mLocalAdapter.getBluetoothState() != BluetoothAdapter.STATE_ON) return;
if (mFilter.matches(cachedDevice.getDevice())) { if (mFilter.matches(cachedDevice.getDevice())) {
createDevicePreference(cachedDevice); createDevicePreference(cachedDevice);
} }
@@ -162,7 +172,7 @@ public abstract class DeviceListPreferenceFragment extends
getActivity(), cachedDevice); getActivity(), cachedDevice);
initDevicePreference(preference); initDevicePreference(preference);
mDeviceList.addPreference(preference); mDeviceListGroup.addPreference(preference);
mDevicePreferenceMap.put(cachedDevice, preference); mDevicePreferenceMap.put(cachedDevice, preference);
} }
@@ -170,13 +180,14 @@ public abstract class DeviceListPreferenceFragment extends
* Overridden in {@link BluetoothSettings} to add a listener. * Overridden in {@link BluetoothSettings} to add a listener.
* @param preference the newly added preference * @param preference the newly added preference
*/ */
void initDevicePreference(BluetoothDevicePreference preference) { } void initDevicePreference(BluetoothDevicePreference preference) {
// Does nothing by default
}
public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
BluetoothDevicePreference preference = mDevicePreferenceMap.remove( BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice);
cachedDevice);
if (preference != null) { if (preference != null) {
mDeviceList.removePreference(preference); mDeviceListGroup.removePreference(preference);
} }
} }
@@ -185,9 +196,10 @@ public abstract class DeviceListPreferenceFragment extends
} }
private void updateProgressUi(boolean start) { private void updateProgressUi(boolean start) {
if (mDeviceList instanceof ProgressCategory) { if (mDeviceListGroup instanceof ProgressCategory) {
((ProgressCategory) mDeviceList).setProgress(start); ((ProgressCategory) mDeviceListGroup).setProgress(start);
} }
// else TODO Add a spinner at the end of the list to show in progress state
} }
public void onBluetoothStateChanged(int bluetoothState) { public void onBluetoothStateChanged(int bluetoothState) {

View File

@@ -89,7 +89,7 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
super.onBluetoothStateChanged(bluetoothState); super.onBluetoothStateChanged(bluetoothState);
if (bluetoothState == BluetoothAdapter.STATE_ON) { if (bluetoothState == BluetoothAdapter.STATE_ON) {
mLocalAdapter.startScanning(false); mLocalAdapter.startScanning(false);
} }
} }

View File

@@ -50,7 +50,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
private static final String KEY_RENAME_DEVICE = "rename_device"; private static final String KEY_RENAME_DEVICE = "rename_device";
private static final String KEY_PROFILE_CONTAINER = "profile_container"; private static final String KEY_PROFILE_CONTAINER = "profile_container";
private static final String KEY_UNPAIR = "unpair"; private static final String KEY_UNPAIR = "unpair";
private static final String KEY_ALLOW_INCOMING = "allow_incoming"; //private static final String KEY_ALLOW_INCOMING = "allow_incoming";
public static final String EXTRA_DEVICE = "device"; public static final String EXTRA_DEVICE = "device";
@@ -355,6 +355,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mCachedDevice.unpair(); mCachedDevice.unpair();
} }
/*
private void setIncomingFileTransfersAllowed(boolean allow) { private void setIncomingFileTransfersAllowed(boolean allow) {
// TODO: make an IPC call into BluetoothOpp to update // TODO: make an IPC call into BluetoothOpp to update
Log.d(TAG, "Set allow incoming = " + allow); Log.d(TAG, "Set allow incoming = " + allow);
@@ -364,6 +365,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
// TODO: get this value from BluetoothOpp ??? // TODO: get this value from BluetoothOpp ???
return true; return true;
} }
*/
private boolean getAutoConnect(LocalBluetoothProfile prof) { private boolean getAutoConnect(LocalBluetoothProfile prof) {
return prof.isPreferred(mCachedDevice.getDevice()); return prof.isPreferred(mCachedDevice.getDevice());

View File

@@ -16,21 +16,23 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemProperties; import android.preference.CheckBoxPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.Toast;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
public class AdvancedSettings extends SettingsPreferenceFragment public class AdvancedSettings extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener { implements Preference.OnPreferenceChangeListener {
@@ -39,6 +41,8 @@ public class AdvancedSettings extends SettingsPreferenceFragment
private static final String KEY_MAC_ADDRESS = "mac_address"; private static final String KEY_MAC_ADDRESS = "mac_address";
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address"; private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
private static final String KEY_FREQUENCY_BAND = "frequency_band"; private static final String KEY_FREQUENCY_BAND = "frequency_band";
private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
private static final String KEY_SLEEP_POLICY = "sleep_policy";
private WifiManager mWifiManager; private WifiManager mWifiManager;
@@ -62,27 +66,61 @@ public class AdvancedSettings extends SettingsPreferenceFragment
} }
private void initPreferences() { private void initPreferences() {
CheckBoxPreference notifyOpenNetworks =
(CheckBoxPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
notifyOpenNetworks.setChecked(Secure.getInt(getContentResolver(),
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
ListPreference pref = (ListPreference) findPreference(KEY_FREQUENCY_BAND); ListPreference frequencyPref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
if (mWifiManager.isDualBandSupported()) { if (mWifiManager.isDualBandSupported()) {
pref.setOnPreferenceChangeListener(this); frequencyPref.setOnPreferenceChangeListener(this);
int value = mWifiManager.getFrequencyBand(); int value = mWifiManager.getFrequencyBand();
if (value != -1) { if (value != -1) {
pref.setValue(String.valueOf(value)); frequencyPref.setValue(String.valueOf(value));
} else { } else {
Log.e(TAG, "Failed to fetch frequency band"); Log.e(TAG, "Failed to fetch frequency band");
} }
} else { } else {
getPreferenceScreen().removePreference(pref); if (frequencyPref != null) {
// null if it has already been removed before resume
getPreferenceScreen().removePreference(frequencyPref);
}
} }
ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
if (sleepPolicyPref != null) {
if (Utils.isWifiOnly()) {
sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
sleepPolicyPref.setSummary(R.string.wifi_setting_sleep_policy_summary_wifi_only);
}
sleepPolicyPref.setOnPreferenceChangeListener(this);
int value = Settings.System.getInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_NEVER);
sleepPolicyPref.setValue(String.valueOf(value));
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
String key = preference.getKey();
if (KEY_NOTIFY_OPEN_NETWORKS.equals(key)) {
Secure.putInt(getContentResolver(),
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
((CheckBoxPreference) preference).isChecked() ? 1 : 0);
} else {
return super.onPreferenceTreeClick(screen, preference);
}
return true;
} }
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey(); String key = preference.getKey();
if (key == null) return true;
if (key.equals(KEY_FREQUENCY_BAND)) { if (KEY_FREQUENCY_BAND.equals(key)) {
try { try {
mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true); mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@@ -92,6 +130,17 @@ public class AdvancedSettings extends SettingsPreferenceFragment
} }
} }
if (KEY_SLEEP_POLICY.equals(key)) {
try {
Settings.System.putInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue)));
} catch (NumberFormatException e) {
Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error,
Toast.LENGTH_SHORT).show();
return false;
}
}
return true; return true;
} }

View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.wifi;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
public class AdvancedWifiSettings extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {
private static final String TAG = "AdvancedWifiSettings";
private static final String KEY_MAC_ADDRESS = "mac_address";
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
private static final String KEY_FREQUENCY_BAND = "frequency_band";
private WifiManager mWifiManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.wifi_advanced_settings);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}
@Override
public void onResume() {
super.onResume();
initPreferences();
refreshWifiInfo();
}
private void initPreferences() {
ListPreference pref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
if (mWifiManager.isDualBandSupported()) {
pref.setOnPreferenceChangeListener(this);
int value = mWifiManager.getFrequencyBand();
if (value != -1) {
pref.setValue(String.valueOf(value));
} else {
Log.e(TAG, "Failed to fetch frequency band");
}
} else {
getPreferenceScreen().removePreference(pref);
}
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (key == null) return true;
if (key.equals(KEY_FREQUENCY_BAND)) {
try {
mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true);
} catch (NumberFormatException e) {
Toast.makeText(getActivity(), R.string.wifi_setting_frequency_band_error,
Toast.LENGTH_SHORT).show();
return false;
}
}
return true;
}
private void refreshWifiInfo() {
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
: getActivity().getString(R.string.status_unavailable));
Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
String ipAddress = Utils.getWifiIpAddresses(getActivity());
wifiIpAddressPref.setSummary(ipAddress == null ?
getActivity().getString(R.string.status_unavailable) : ipAddress);
}
}

View File

@@ -16,33 +16,29 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.DhcpInfo;
import android.net.LinkAddress; import android.net.LinkAddress;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.DetailedState;
import android.net.NetworkUtils; import android.net.NetworkUtils;
import android.net.Proxy;
import android.net.ProxyProperties; import android.net.ProxyProperties;
import android.net.RouteInfo; import android.net.RouteInfo;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.IpAssignment;
import android.net.wifi.WifiConfiguration.AuthAlgorithm; import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.IpAssignment;
import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WpsConfiguration;
import android.net.wifi.WpsConfiguration.Setup;
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import android.net.wifi.WifiConfiguration.ProxySettings; import android.net.wifi.WifiConfiguration.ProxySettings;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WpsConfiguration;
import android.net.wifi.WpsConfiguration.Setup;
import android.security.Credentials; import android.security.Credentials;
import android.security.KeyStore; import android.security.KeyStore;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.format.Formatter;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -57,12 +53,10 @@ import com.android.settings.ProxySelector;
import com.android.settings.R; import com.android.settings.R;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Iterator; import java.util.Iterator;
/** /**
* The class for allowing UIs like {@link WifiDialog} and {@link WifiConfigPreference} to * The class for allowing UIs like {@link WifiDialog} and {@link WifiConfigUiBase} to
* share the logic for controlling buttons, text fields, etc. * share the logic for controlling buttons, text fields, etc.
*/ */
public class WifiConfigController implements TextWatcher, public class WifiConfigController implements TextWatcher,
@@ -429,7 +423,9 @@ public class WifiConfigController implements TextWatcher,
int networkPrefixLength = -1; int networkPrefixLength = -1;
try { try {
networkPrefixLength = Integer.parseInt(mNetworkPrefixLengthView.getText().toString()); networkPrefixLength = Integer.parseInt(mNetworkPrefixLengthView.getText().toString());
} catch (NumberFormatException e) { } } catch (NumberFormatException e) {
// Use -1
}
if (networkPrefixLength < 0 || networkPrefixLength > 32) { if (networkPrefixLength < 0 || networkPrefixLength > 32) {
return R.string.wifi_ip_settings_invalid_network_prefix_length; return R.string.wifi_ip_settings_invalid_network_prefix_length;
} }
@@ -698,6 +694,7 @@ public class WifiConfigController implements TextWatcher,
private void setSelection(Spinner spinner, String value) { private void setSelection(Spinner spinner, String value) {
if (value != null) { if (value != null) {
@SuppressWarnings("unchecked")
ArrayAdapter<String> adapter = (ArrayAdapter<String>) spinner.getAdapter(); ArrayAdapter<String> adapter = (ArrayAdapter<String>) spinner.getAdapter();
for (int i = adapter.getCount() - 1; i >= 0; --i) { for (int i = adapter.getCount() - 1; i >= 0; --i) {
if (value.equals(adapter.getItem(i))) { if (value.equals(adapter.getItem(i))) {
@@ -719,10 +716,12 @@ public class WifiConfigController implements TextWatcher,
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// work done in afterTextChanged
} }
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
// work done in afterTextChanged
} }
@Override @Override
@@ -750,5 +749,6 @@ public class WifiConfigController implements TextWatcher,
@Override @Override
public void onNothingSelected(AdapterView<?> parent) { public void onNothingSelected(AdapterView<?> parent) {
//
} }
} }

View File

@@ -16,9 +16,6 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import com.android.settings.R;
import com.android.settings.WirelessSettings;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -27,19 +24,19 @@ import android.net.NetworkInfo;
import android.net.wifi.SupplicantState; import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.preference.Preference;
import android.preference.CheckBoxPreference;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast; import android.widget.Toast;
import com.android.settings.R;
import com.android.settings.WirelessSettings;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
public class WifiEnabler implements Preference.OnPreferenceChangeListener { public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
private final Context mContext; private final Context mContext;
private final CheckBoxPreference mCheckBox; private Switch mSwitch;
private final CharSequence mOriginalSummary;
private AtomicBoolean mConnected = new AtomicBoolean(false); private AtomicBoolean mConnected = new AtomicBoolean(false);
private final WifiManager mWifiManager; private final WifiManager mWifiManager;
@@ -65,11 +62,9 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener {
} }
}; };
public WifiEnabler(Context context, CheckBoxPreference checkBox) { public WifiEnabler(Context context, Switch switch_) {
mContext = context; mContext = context;
mCheckBox = checkBox; mSwitch = switch_;
mOriginalSummary = checkBox.getSummary();
checkBox.setPersistent(false);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
@@ -81,78 +76,86 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener {
public void resume() { public void resume() {
// Wi-Fi state is sticky, so just let the receiver update UI // Wi-Fi state is sticky, so just let the receiver update UI
mContext.registerReceiver(mReceiver, mIntentFilter); mContext.registerReceiver(mReceiver, mIntentFilter);
mCheckBox.setOnPreferenceChangeListener(this); mSwitch.setOnCheckedChangeListener(this);
} }
public void pause() { public void pause() {
mContext.unregisterReceiver(mReceiver); mContext.unregisterReceiver(mReceiver);
mCheckBox.setOnPreferenceChangeListener(null); mSwitch.setOnCheckedChangeListener(null);
} }
public boolean onPreferenceChange(Preference preference, Object value) { public void setSwitch(Switch switch_) {
boolean enable = (Boolean) value; if (mSwitch == switch_) return;
mSwitch.setOnCheckedChangeListener(null);
mSwitch = switch_;
mSwitch.setOnCheckedChangeListener(this);
final int wifiState = mWifiManager.getWifiState();
boolean isEnabled = wifiState == WifiManager.WIFI_STATE_ENABLED;
boolean isDisabled = wifiState == WifiManager.WIFI_STATE_DISABLED;
mSwitch.setChecked(isEnabled);
mSwitch.setEnabled(isEnabled || isDisabled);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Show toast message if Wi-Fi is not allowed in airplane mode // Show toast message if Wi-Fi is not allowed in airplane mode
if (enable && !WirelessSettings if (isChecked && !WirelessSettings.isRadioAllowed(mContext, Settings.System.RADIO_WIFI)) {
.isRadioAllowed(mContext, Settings.System.RADIO_WIFI)) { Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, // Reset switch to off. No infinite check/listenenr loop.
Toast.LENGTH_SHORT).show(); buttonView.setChecked(false);
return false;
} }
/** // Disable tethering if enabling Wifi
* Disable tethering if enabling Wifi
*/
int wifiApState = mWifiManager.getWifiApState(); int wifiApState = mWifiManager.getWifiApState();
if (enable && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || if (isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
(wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) { (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
mWifiManager.setWifiApEnabled(null, false); mWifiManager.setWifiApEnabled(null, false);
} }
if (mWifiManager.setWifiEnabled(enable)) {
mCheckBox.setEnabled(false);
} else {
mCheckBox.setSummary(R.string.wifi_error);
}
// Don't update UI to opposite state until we're sure if (mWifiManager.setWifiEnabled(isChecked)) {
return false; // Intent has been taken into account, disable until new state is active
mSwitch.setEnabled(false);
} else {
// Error
Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show();
}
} }
private void handleWifiStateChanged(int state) { private void handleWifiStateChanged(int state) {
switch (state) { switch (state) {
case WifiManager.WIFI_STATE_ENABLING: case WifiManager.WIFI_STATE_ENABLING:
mCheckBox.setSummary(R.string.wifi_starting); mSwitch.setEnabled(false);
mCheckBox.setEnabled(false);
break; break;
case WifiManager.WIFI_STATE_ENABLED: case WifiManager.WIFI_STATE_ENABLED:
mCheckBox.setChecked(true); mSwitch.setChecked(true);
mCheckBox.setSummary(null); mSwitch.setEnabled(true);
mCheckBox.setEnabled(true);
break; break;
case WifiManager.WIFI_STATE_DISABLING: case WifiManager.WIFI_STATE_DISABLING:
mCheckBox.setSummary(R.string.wifi_stopping); mSwitch.setEnabled(false);
mCheckBox.setEnabled(false);
break; break;
case WifiManager.WIFI_STATE_DISABLED: case WifiManager.WIFI_STATE_DISABLED:
mCheckBox.setChecked(false); mSwitch.setChecked(false);
mCheckBox.setSummary(mOriginalSummary); mSwitch.setEnabled(true);
mCheckBox.setEnabled(true);
break; break;
default: default:
mCheckBox.setChecked(false); mSwitch.setChecked(false);
mCheckBox.setSummary(R.string.wifi_error); mSwitch.setEnabled(true);
mCheckBox.setEnabled(true);
} }
} }
private void handleStateChanged(NetworkInfo.DetailedState state) { private void handleStateChanged(@SuppressWarnings("unused") NetworkInfo.DetailedState state) {
// After the refactoring from a CheckBoxPreference to a Switch, this method is useless since
// there is nowhere to display a summary.
// This code is kept in case a future change re-introduces an associated text.
/*
// WifiInfo is valid if and only if Wi-Fi is enabled. // WifiInfo is valid if and only if Wi-Fi is enabled.
// Here we use the state of the check box as an optimization. // Here we use the state of the switch as an optimization.
if (state != null && mCheckBox.isChecked()) { if (state != null && mSwitch.isChecked()) {
WifiInfo info = mWifiManager.getConnectionInfo(); WifiInfo info = mWifiManager.getConnectionInfo();
if (info != null) { if (info != null) {
mCheckBox.setSummary(Summary.get(mContext, info.getSSID(), state)); //setSummary(Summary.get(mContext, info.getSSID(), state));
} }
} }
*/
} }
} }

View File

@@ -18,6 +18,7 @@ package com.android.settings.wifi;
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID; import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -31,40 +32,35 @@ import android.net.NetworkInfo.DetailedState;
import android.net.wifi.ScanResult; import android.net.wifi.ScanResult;
import android.net.wifi.SupplicantState; import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.net.wifi.WpsResult; import android.net.wifi.WpsResult;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WpsConfiguration;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.ListPreference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.provider.Settings.Secure;
import android.provider.Settings;
import android.security.Credentials; import android.security.Credentials;
import android.security.KeyStore; import android.security.KeyStore;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.Switch;
import android.widget.Toast;
import com.android.internal.util.AsyncChannel; import com.android.internal.util.AsyncChannel;
import com.android.settings.ProgressCategoryBase;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -83,14 +79,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
* other decorations specific to that screen. * other decorations specific to that screen.
*/ */
public class WifiSettings extends SettingsPreferenceFragment public class WifiSettings extends SettingsPreferenceFragment
implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener { implements DialogInterface.OnClickListener {
private static final String TAG = "WifiSettings"; private static final String TAG = "WifiSettings";
private static final int MENU_ID_SCAN = Menu.FIRST; private static final int MENU_ID_SCAN = Menu.FIRST;
private static final int MENU_ID_ADVANCED = Menu.FIRST + 1; private static final int MENU_ID_ADD_NETWORK = Menu.FIRST + 1;
private static final int MENU_ID_CONNECT = Menu.FIRST + 2; private static final int MENU_ID_ADVANCED = Menu.FIRST + 2;
private static final int MENU_ID_FORGET = Menu.FIRST + 3; private static final int MENU_ID_CONNECT = Menu.FIRST + 3;
private static final int MENU_ID_MODIFY = Menu.FIRST + 4; private static final int MENU_ID_FORGET = Menu.FIRST + 4;
private static final String KEY_SLEEP_POLICY = "sleep_policy"; private static final int MENU_ID_MODIFY = Menu.FIRST + 5;
private final IntentFilter mFilter; private final IntentFilter mFilter;
private final BroadcastReceiver mReceiver; private final BroadcastReceiver mReceiver;
@@ -98,12 +94,8 @@ public class WifiSettings extends SettingsPreferenceFragment
private WifiManager mWifiManager; private WifiManager mWifiManager;
private WifiEnabler mWifiEnabler; private WifiEnabler mWifiEnabler;
private CheckBoxPreference mNotifyOpenNetworks;
private ProgressCategoryBase mAccessPoints;
private Preference mAddNetwork;
// An access point being editted is stored here. // An access point being editted is stored here.
private AccessPoint mSelectedAccessPoint; private AccessPoint mSelectedAccessPoint;
private boolean mEdit;
private DetailedState mLastState; private DetailedState mLastState;
private WifiInfo mLastInfo; private WifiInfo mLastInfo;
@@ -180,60 +172,48 @@ public class WifiSettings extends SettingsPreferenceFragment
// state, start it off in the right state // state, start it off in the right state
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false); mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
// Avoid re-adding on returning from an overlapping activity/fragment. if (mEnableNextOnConnection) {
if (getPreferenceScreen() == null || getPreferenceScreen().getPreferenceCount() < 2) { if (hasNextButton()) {
if (mEnableNextOnConnection) { final ConnectivityManager connectivity = (ConnectivityManager)
if (hasNextButton()) { getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
final ConnectivityManager connectivity = (ConnectivityManager) if (connectivity != null) {
getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivity.getNetworkInfo(
if (connectivity != null) { ConnectivityManager.TYPE_WIFI);
NetworkInfo info = connectivity.getNetworkInfo( changeNextButtonState(info.isConnected());
ConnectivityManager.TYPE_WIFI);
changeNextButtonState(info.isConnected());
}
} }
} }
if (mInXlSetupWizard) {
addPreferencesFromResource(R.xml.wifi_access_points_for_wifi_setup_xl);
} else if (intent.getBooleanExtra("only_access_points", false)) {
addPreferencesFromResource(R.xml.wifi_access_points);
} else {
addPreferencesFromResource(R.xml.wifi_settings);
mWifiEnabler = new WifiEnabler(activity,
(CheckBoxPreference) findPreference("enable_wifi"));
mNotifyOpenNetworks =
(CheckBoxPreference) findPreference("notify_open_networks");
mNotifyOpenNetworks.setChecked(Secure.getInt(getContentResolver(),
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
}
// This may be either ProgressCategory or AccessPointCategoryForXL.
final ProgressCategoryBase preference =
(ProgressCategoryBase) findPreference("access_points");
mAccessPoints = preference;
mAccessPoints.setOrderingAsAdded(false);
mAddNetwork = findPreference("add_network");
ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
if (pref != null) {
if (Utils.isWifiOnly()) {
pref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
pref.setSummary(R.string.wifi_setting_sleep_policy_summary_wifi_only);
}
pref.setOnPreferenceChangeListener(this);
int value = Settings.System.getInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_NEVER);
pref.setValue(String.valueOf(value));
}
registerForContextMenu(getListView());
setHasOptionsMenu(true);
} }
if (mInXlSetupWizard) {
addPreferencesFromResource(R.xml.wifi_access_points_for_wifi_setup_xl);
} else {
addPreferencesFromResource(R.xml.wifi_settings);
Switch actionBarSwitch = new Switch(activity);
if (activity instanceof PreferenceActivity) {
PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
final int padding = activity.getResources().getDimensionPixelSize(
R.dimen.action_bar_switch_padding);
actionBarSwitch.setPadding(0, 0, padding, 0);
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM);
activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.RIGHT));
}
}
mWifiEnabler = new WifiEnabler(activity, actionBarSwitch);
}
registerForContextMenu(getListView());
setHasOptionsMenu(true);
// After confirming PreferenceScreen is available, we call super. // After confirming PreferenceScreen is available, we call super.
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
} }
@Override @Override
@@ -249,6 +229,7 @@ public class WifiSettings extends SettingsPreferenceFragment
mWifiManager.connectNetwork(mKeyStoreNetworkId); mWifiManager.connectNetwork(mKeyStoreNetworkId);
} }
mKeyStoreNetworkId = INVALID_NETWORK_ID; mKeyStoreNetworkId = INVALID_NETWORK_ID;
updateAccessPoints(); updateAccessPoints();
} }
@@ -270,8 +251,11 @@ public class WifiSettings extends SettingsPreferenceFragment
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// We don't want menus in Setup Wizard XL. // We don't want menus in Setup Wizard XL.
if (!mInXlSetupWizard) { if (!mInXlSetupWizard) {
final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan) menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan)
.setIcon(R.drawable.ic_menu_scan_network); .setIcon(R.drawable.ic_menu_scan_network).setEnabled(wifiIsEnabled);
menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
.setIcon(android.R.drawable.ic_menu_add).setEnabled(wifiIsEnabled);
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced) menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
.setIcon(android.R.drawable.ic_menu_manage); .setIcon(android.R.drawable.ic_menu_manage);
} }
@@ -286,6 +270,11 @@ public class WifiSettings extends SettingsPreferenceFragment
mScanner.forceScan(); mScanner.forceScan();
} }
return true; return true;
case MENU_ID_ADD_NETWORK:
if (mWifiManager.isWifiEnabled()) {
onAddNetworkPressed();
}
return true;
case MENU_ID_ADVANCED: case MENU_ID_ADVANCED:
if (getActivity() instanceof PreferenceActivity) { if (getActivity() instanceof PreferenceActivity) {
((PreferenceActivity) getActivity()).startPreferencePanel( ((PreferenceActivity) getActivity()).startPreferencePanel(
@@ -363,43 +352,17 @@ public class WifiSettings extends SettingsPreferenceFragment
if (preference instanceof AccessPoint) { if (preference instanceof AccessPoint) {
mSelectedAccessPoint = (AccessPoint) preference; mSelectedAccessPoint = (AccessPoint) preference;
showConfigUi(mSelectedAccessPoint, false); showConfigUi(mSelectedAccessPoint, false);
} else if (preference == mAddNetwork) {
onAddNetworkPressed();
} else if (preference == mNotifyOpenNetworks) {
Secure.putInt(getContentResolver(),
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
mNotifyOpenNetworks.isChecked() ? 1 : 0);
} else { } else {
return super.onPreferenceTreeClick(screen, preference); return super.onPreferenceTreeClick(screen, preference);
} }
return true; return true;
} }
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (key == null) return true;
if (key.equals(KEY_SLEEP_POLICY)) {
try {
Settings.System.putInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue)));
} catch (NumberFormatException e) {
Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error,
Toast.LENGTH_SHORT).show();
return false;
}
}
return true;
}
/** /**
* Shows an appropriate Wifi configuration component. * Shows an appropriate Wifi configuration component.
* Called when a user clicks "Add network" preference or one of available networks is selected. * Called when a user clicks "Add network" preference or one of available networks is selected.
*/ */
private void showConfigUi(AccessPoint accessPoint, boolean edit) { private void showConfigUi(AccessPoint accessPoint, boolean edit) {
mEdit = edit;
if (mInXlSetupWizard) { if (mInXlSetupWizard) {
((WifiSettingsForSetupWizardXL)getActivity()).showConfigUi(accessPoint, edit); ((WifiSettingsForSetupWizardXL)getActivity()).showConfigUi(accessPoint, edit);
} else { } else {
@@ -430,20 +393,40 @@ public class WifiSettings extends SettingsPreferenceFragment
* the strength of network and the security for it. * the strength of network and the security for it.
*/ */
private void updateAccessPoints() { private void updateAccessPoints() {
mAccessPoints.removeAll(); final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
final int wifiState = mWifiManager.getWifiState();
// AccessPoints are automatically sorted with TreeSet. switch (wifiState) {
final Collection<AccessPoint> accessPoints = constructAccessPoints(); case WifiManager.WIFI_STATE_ENABLED:
if (mInXlSetupWizard) { // AccessPoints are automatically sorted with TreeSet.
((WifiSettingsForSetupWizardXL)getActivity()).onAccessPointsUpdated( final Collection<AccessPoint> accessPoints = constructAccessPoints();
mAccessPoints, accessPoints); if (mInXlSetupWizard) {
} else { ((WifiSettingsForSetupWizardXL)getActivity()).onAccessPointsUpdated(
for (AccessPoint accessPoint : accessPoints) { getPreferenceScreen(), accessPoints);
mAccessPoints.addPreference(accessPoint); } else {
} for (AccessPoint accessPoint : accessPoints) {
getPreferenceScreen().addPreference(accessPoint);
}
}
break;
case WifiManager.WIFI_STATE_DISABLING:
addMessagePreference(R.string.wifi_stopping);
break;
case WifiManager.WIFI_STATE_DISABLED:
addMessagePreference(R.string.wifi_empty_list_wifi_off);
break;
} }
} }
private void addMessagePreference(int messageId) {
Preference emptyListPreference = new Preference(getActivity());
emptyListPreference.setTitle(messageId);
getPreferenceScreen().addPreference(emptyListPreference);
}
private Collection<AccessPoint> constructAccessPoints() { private Collection<AccessPoint> constructAccessPoints() {
Collection<AccessPoint> accessPoints = new ArrayList<AccessPoint>(); Collection<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
@@ -542,9 +525,9 @@ public class WifiSettings extends SettingsPreferenceFragment
mLastState = state; mLastState = state;
} }
for (int i = mAccessPoints.getPreferenceCount() - 1; i >= 0; --i) { for (int i = getPreferenceScreen().getPreferenceCount() - 1; i >= 0; --i) {
// Maybe there's a WifiConfigPreference // Maybe there's a WifiConfigPreference
Preference preference = mAccessPoints.getPreference(i); Preference preference = getPreferenceScreen().getPreference(i);
if (preference instanceof AccessPoint) { if (preference instanceof AccessPoint) {
final AccessPoint accessPoint = (AccessPoint) preference; final AccessPoint accessPoint = (AccessPoint) preference;
accessPoint.update(mLastInfo, mLastState); accessPoint.update(mLastInfo, mLastState);
@@ -557,12 +540,25 @@ public class WifiSettings extends SettingsPreferenceFragment
} }
private void updateWifiState(int state) { private void updateWifiState(int state) {
if (state == WifiManager.WIFI_STATE_ENABLED) { getActivity().invalidateOptionsMenu();
mScanner.resume();
} else { switch (state) {
mScanner.pause(); case WifiManager.WIFI_STATE_ENABLED:
mAccessPoints.removeAll(); mScanner.resume();
return; // not break, to avoid pause
case WifiManager.WIFI_STATE_ENABLING:
getPreferenceScreen().removeAll();
addMessagePreference(R.string.wifi_starting);
break;
case WifiManager.WIFI_STATE_DISABLED:
getPreferenceScreen().removeAll();
addMessagePreference(R.string.wifi_empty_list_wifi_off);
break;
} }
mScanner.pause();
} }
private class Scanner extends Handler { private class Scanner extends Handler {
@@ -580,7 +576,6 @@ public class WifiSettings extends SettingsPreferenceFragment
void pause() { void pause() {
mRetry = 0; mRetry = 0;
mAccessPoints.setProgress(false);
removeMessages(0); removeMessages(0);
} }
@@ -594,7 +589,6 @@ public class WifiSettings extends SettingsPreferenceFragment
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
return; return;
} }
mAccessPoints.setProgress(mRetry != 0);
// Combo scans can take 5-6s to complete. Increase interval to 10s. // Combo scans can take 5-6s to complete. Increase interval to 10s.
sendEmptyMessageDelayed(0, 10000); sendEmptyMessageDelayed(0, 10000);
} }
@@ -636,6 +630,7 @@ public class WifiSettings extends SettingsPreferenceFragment
} }
break; break;
} }
break;
//TODO: more connectivity feedback //TODO: more connectivity feedback
default: default:
//Ignore //Ignore
@@ -740,7 +735,7 @@ public class WifiSettings extends SettingsPreferenceFragment
mScanner.resume(); mScanner.resume();
} }
mAccessPoints.removeAll(); getPreferenceScreen().removeAll();
} }
/** /**
@@ -753,8 +748,9 @@ public class WifiSettings extends SettingsPreferenceFragment
} }
/* package */ int getAccessPointsCount() { /* package */ int getAccessPointsCount() {
if (mAccessPoints != null) { final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
return mAccessPoints.getPreferenceCount(); if (wifiIsEnabled) {
return getPreferenceScreen().getPreferenceCount();
} else { } else {
return 0; return 0;
} }

View File

@@ -16,8 +16,6 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import com.android.settings.R;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -28,11 +26,9 @@ import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceCategory; import android.preference.PreferenceScreen;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -43,6 +39,7 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.android.internal.util.AsyncChannel; import com.android.internal.util.AsyncChannel;
import com.android.settings.R;
import java.util.Collection; import java.util.Collection;
import java.util.EnumMap; import java.util.EnumMap;
@@ -666,9 +663,10 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
/** /**
* Called when the list of AccessPoints are modified and this Activity needs to refresh * Called when the list of AccessPoints are modified and this Activity needs to refresh
* the list. * the list.
* @param preferenceScreen
*/ */
/* package */ void onAccessPointsUpdated( /* package */ void onAccessPointsUpdated(
PreferenceCategory holder, Collection<AccessPoint> accessPoints) { PreferenceScreen preferenceScreen, Collection<AccessPoint> accessPoints) {
// If we already show some of access points but the bar still shows "scanning" state, it // If we already show some of access points but the bar still shows "scanning" state, it
// should be stopped. // should be stopped.
if (mProgressBar.isIndeterminate() && accessPoints.size() > 0) { if (mProgressBar.isIndeterminate() && accessPoints.size() > 0) {
@@ -683,7 +681,7 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
for (AccessPoint accessPoint : accessPoints) { for (AccessPoint accessPoint : accessPoints) {
accessPoint.setLayoutResource(R.layout.custom_preference); accessPoint.setLayoutResource(R.layout.custom_preference);
holder.addPreference(accessPoint); preferenceScreen.addPreference(accessPoint);
} }
} }
@@ -788,11 +786,6 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
mWifiManager.connectNetwork(config); mWifiManager.connectNetwork(config);
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
}
/** /**
* Replace the current background with a new background whose id is resId if needed. * Replace the current background with a new background whose id is resId if needed.
*/ */