am 7bdf0e73: Move sleep policy to main settings page

* commit '7bdf0e73d051f176fbc20451761eb50177d69f91':
  Move sleep policy to main settings page
This commit is contained in:
Irfan Sheriff
2011-01-28 17:30:59 -08:00
committed by Android Git Automerger
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"
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"

View File

@@ -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"

View File

@@ -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) {

View File

@@ -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.