Move sleep policy to main settings page

Bug: 3404049
Change-Id: I091abd737894a4adb9ebfc08b8e63bc3224b971c
This commit is contained in:
Irfan Sheriff
2011-01-28 16:42:33 -08:00
parent 46f4b754e1
commit 7bdf0e73d0
4 changed files with 42 additions and 30 deletions

View File

@@ -17,15 +17,6 @@
<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">
<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

@@ -30,6 +30,15 @@
android:summary="@string/wifi_notify_open_networks_summary" android:summary="@string/wifi_notify_open_networks_summary"
android:persistent="false" /> 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 <com.android.settings.ProgressCategory
android:key="access_points" android:key="access_points"
android:dependency="enable_wifi" android:dependency="enable_wifi"

View File

@@ -27,7 +27,6 @@ import android.os.Bundle;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.Toast; import android.widget.Toast;
import android.util.Log; import android.util.Log;
@@ -38,7 +37,6 @@ public class AdvancedSettings extends SettingsPreferenceFragment
private static final String TAG = "AdvancedSettings"; private static final String TAG = "AdvancedSettings";
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_SLEEP_POLICY = "sleep_policy";
private static final String KEY_FREQUENCY_BAND = "frequency_band"; private static final String KEY_FREQUENCY_BAND = "frequency_band";
private WifiManager mWifiManager; private WifiManager mWifiManager;
@@ -63,18 +61,12 @@ public class AdvancedSettings extends SettingsPreferenceFragment
} }
private void initPreferences() { private void initPreferences() {
ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
pref.setOnPreferenceChangeListener(this);
int value = Settings.System.getInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED);
pref.setValue(String.valueOf(value));
pref = (ListPreference) findPreference(KEY_FREQUENCY_BAND); ListPreference pref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
if (mWifiManager.isDualBandSupported()) { if (mWifiManager.isDualBandSupported()) {
pref.setOnPreferenceChangeListener(this); pref.setOnPreferenceChangeListener(this);
value = mWifiManager.getFrequencyBand(); int value = mWifiManager.getFrequencyBand();
if (value != -1) { if (value != -1) {
pref.setValue(String.valueOf(value)); pref.setValue(String.valueOf(value));
} else { } else {
@@ -89,16 +81,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment
String key = preference.getKey(); String key = preference.getKey();
if (key == null) return true; if (key == null) return true;
if (key.equals(KEY_SLEEP_POLICY)) { if (key.equals(KEY_FREQUENCY_BAND)) {
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;
}
} else if (key.equals(KEY_FREQUENCY_BAND)) {
try { try {
mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true); mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@@ -45,9 +45,11 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.CheckBoxPreference; 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.Secure;
import android.provider.Settings;
import android.security.Credentials; import android.security.Credentials;
import android.security.KeyStore; import android.security.KeyStore;
import android.view.ContextMenu; import android.view.ContextMenu;
@@ -78,12 +80,13 @@ 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 { implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener {
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_ADVANCED = Menu.FIRST + 1;
private static final int MENU_ID_CONNECT = Menu.FIRST + 2; private static final int MENU_ID_CONNECT = Menu.FIRST + 2;
private static final int MENU_ID_FORGET = Menu.FIRST + 3; private static final int MENU_ID_FORGET = Menu.FIRST + 3;
private static final int MENU_ID_MODIFY = Menu.FIRST + 4; private static final int MENU_ID_MODIFY = Menu.FIRST + 4;
private static final String KEY_SLEEP_POLICY = "sleep_policy";
private final IntentFilter mFilter; private final IntentFilter mFilter;
private final BroadcastReceiver mReceiver; private final BroadcastReceiver mReceiver;
@@ -206,6 +209,13 @@ public class WifiSettings extends SettingsPreferenceFragment
mAccessPoints.setOrderingAsAdded(false); mAccessPoints.setOrderingAsAdded(false);
mAddNetwork = findPreference("add_network"); mAddNetwork = findPreference("add_network");
ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
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()); registerForContextMenu(getListView());
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@@ -353,6 +363,25 @@ public class WifiSettings extends SettingsPreferenceFragment
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.