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

@@ -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);
}
}