Move sleep policy to main settings page
Bug: 3404049 Change-Id: I091abd737894a4adb9ebfc08b8e63bc3224b971c
This commit is contained in:
@@ -17,15 +17,6 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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
|
||||
android:key="frequency_band"
|
||||
android:title="@string/wifi_setting_frequency_band_title"
|
||||
|
@@ -30,6 +30,15 @@
|
||||
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"
|
||||
|
@@ -27,7 +27,6 @@ import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
import android.util.Log;
|
||||
@@ -38,7 +37,6 @@ public class AdvancedSettings extends SettingsPreferenceFragment
|
||||
private static final String TAG = "AdvancedSettings";
|
||||
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_SLEEP_POLICY = "sleep_policy";
|
||||
private static final String KEY_FREQUENCY_BAND = "frequency_band";
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
@@ -63,18 +61,12 @@ public class AdvancedSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
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()) {
|
||||
pref.setOnPreferenceChangeListener(this);
|
||||
value = mWifiManager.getFrequencyBand();
|
||||
int value = mWifiManager.getFrequencyBand();
|
||||
if (value != -1) {
|
||||
pref.setValue(String.valueOf(value));
|
||||
} else {
|
||||
@@ -89,16 +81,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment
|
||||
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;
|
||||
}
|
||||
} else if (key.equals(KEY_FREQUENCY_BAND)) {
|
||||
if (key.equals(KEY_FREQUENCY_BAND)) {
|
||||
try {
|
||||
mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true);
|
||||
} catch (NumberFormatException e) {
|
||||
|
@@ -45,9 +45,11 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.provider.Settings;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
import android.view.ContextMenu;
|
||||
@@ -78,12 +80,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
* other decorations specific to that screen.
|
||||
*/
|
||||
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_ADVANCED = Menu.FIRST + 1;
|
||||
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_MODIFY = Menu.FIRST + 4;
|
||||
private static final String KEY_SLEEP_POLICY = "sleep_policy";
|
||||
|
||||
private final IntentFilter mFilter;
|
||||
private final BroadcastReceiver mReceiver;
|
||||
@@ -206,6 +209,13 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
mAccessPoints.setOrderingAsAdded(false);
|
||||
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());
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
@@ -353,6 +363,25 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
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.
|
||||
* Called when a user clicks "Add network" preference or one of available networks is selected.
|
||||
|
Reference in New Issue
Block a user