Merge "Fix NPE in WirelessSettings.onCreate() for SDK and non-BT devices." into honeycomb-mr1

This commit is contained in:
Jake Hamby
2011-03-29 13:28:48 -07:00
committed by Android (Google) Code Review
3 changed files with 9 additions and 9 deletions

View File

@@ -19,8 +19,6 @@ package com.android.settings;
import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties; import com.android.internal.telephony.TelephonyProperties;
import com.android.settings.bluetooth.BluetoothEnabler; import com.android.settings.bluetooth.BluetoothEnabler;
import com.android.settings.bluetooth.LocalBluetoothAdapter;
import com.android.settings.bluetooth.LocalBluetoothManager;
import com.android.settings.wifi.WifiEnabler; import com.android.settings.wifi.WifiEnabler;
import com.android.settings.nfc.NfcEnabler; import com.android.settings.nfc.NfcEnabler;
@@ -105,8 +103,7 @@ public class WirelessSettings extends SettingsPreferenceFragment {
mAirplaneModeEnabler = new AirplaneModeEnabler(activity, airplane); mAirplaneModeEnabler = new AirplaneModeEnabler(activity, airplane);
mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE); mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
mWifiEnabler = new WifiEnabler(activity, wifi); mWifiEnabler = new WifiEnabler(activity, wifi);
mBtEnabler = new BluetoothEnabler(activity, mBtEnabler = new BluetoothEnabler(activity, bt);
LocalBluetoothManager.getInstance(activity).getBluetoothAdapter(), 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(),
@@ -128,6 +125,7 @@ public class WirelessSettings extends SettingsPreferenceFragment {
// Remove Bluetooth Settings if Bluetooth service is not available. // Remove Bluetooth Settings if Bluetooth service is not available.
if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) { if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
getPreferenceScreen().removePreference(bt); getPreferenceScreen().removePreference(bt);
getPreferenceScreen().removePreference(findPreference(KEY_BT_SETTINGS));
} }
// Remove NFC if its not available // Remove NFC if its not available

View File

@@ -50,17 +50,19 @@ public final class BluetoothEnabler implements Preference.OnPreferenceChangeList
} }
}; };
public BluetoothEnabler(Context context, LocalBluetoothAdapter adapter, public BluetoothEnabler(Context context, CheckBoxPreference checkBox) {
CheckBoxPreference checkBox) {
mContext = context; mContext = context;
mCheckBox = checkBox; mCheckBox = checkBox;
mOriginalSummary = checkBox.getSummary(); mOriginalSummary = checkBox.getSummary();
checkBox.setPersistent(false); checkBox.setPersistent(false);
mLocalAdapter = adapter; LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context);
if (adapter == null) { if (manager == null) {
// Bluetooth is not supported // Bluetooth is not supported
mLocalAdapter = null;
checkBox.setEnabled(false); checkBox.setEnabled(false);
} else {
mLocalAdapter = manager.getBluetoothAdapter();
} }
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
} }

View File

@@ -58,7 +58,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
void addPreferencesForActivity() { void addPreferencesForActivity() {
addPreferencesFromResource(R.xml.bluetooth_settings); addPreferencesFromResource(R.xml.bluetooth_settings);
mEnabler = new BluetoothEnabler(getActivity(), mLocalAdapter, mEnabler = new BluetoothEnabler(getActivity(),
(CheckBoxPreference) findPreference(KEY_BT_CHECKBOX)); (CheckBoxPreference) findPreference(KEY_BT_CHECKBOX));
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(), mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),