Fixed multiple Bluetooth Settings crashes.
+ Fixed a crash when selecting On/Off multiple times on an input device. + Fixed a crash when visiting different Bluetooth Settings after disabling an input device. Bug: 17402421 Change-Id: I23efa3a36ba8cf0df02cf41397586a10dae9e08c
This commit is contained in:
@@ -392,7 +392,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
|
|
||||||
final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
DeviceProfilesSettings profileFrag = (DeviceProfilesSettings)activity.
|
DeviceProfilesSettings profileFragment = (DeviceProfilesSettings)activity.
|
||||||
getFragmentManager().findFragmentById(R.id.bluetooth_fragment_settings);
|
getFragmentManager().findFragmentById(R.id.bluetooth_fragment_settings);
|
||||||
|
|
||||||
if (mSettingsDialogView != null){
|
if (mSettingsDialogView != null){
|
||||||
@@ -402,23 +402,26 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileFrag == null) {
|
if (profileFragment == null) {
|
||||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_settings, null);
|
mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_settings, null);
|
||||||
profileFrag = (DeviceProfilesSettings)activity.getFragmentManager()
|
profileFragment = (DeviceProfilesSettings)activity.getFragmentManager()
|
||||||
.findFragmentById(R.id.bluetooth_fragment_settings);
|
.findFragmentById(R.id.bluetooth_fragment_settings);
|
||||||
|
|
||||||
// To enable scrolling we store the name field in a seperate header and add to
|
// To enable scrolling we store the name field in a seperate header and add to
|
||||||
// the ListView of the profileFrag.
|
// the ListView of the profileFragment.
|
||||||
View header = inflater.inflate(R.layout.bluetooth_device_settings_header, null);
|
View header = inflater.inflate(R.layout.bluetooth_device_settings_header, null);
|
||||||
profileFrag.getListView().addHeaderView(header);
|
profileFragment.getListView().addHeaderView(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
final View dialogLayout = mSettingsDialogView;
|
final View dialogLayout = mSettingsDialogView;
|
||||||
AlertDialog.Builder settingsDialog = new AlertDialog.Builder(activity);
|
AlertDialog.Builder settingsDialog = new AlertDialog.Builder(activity);
|
||||||
profileFrag.setDevice(device);
|
profileFragment.setDevice(device);
|
||||||
final EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name);
|
final EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name);
|
||||||
deviceName.setText(device.getName(), TextView.BufferType.EDITABLE);
|
deviceName.setText(device.getName(), TextView.BufferType.EDITABLE);
|
||||||
|
|
||||||
|
final DeviceProfilesSettings dpsFragment = profileFragment;
|
||||||
|
final Context context = v.getContext();
|
||||||
settingsDialog.setView(dialogLayout);
|
settingsDialog.setView(dialogLayout);
|
||||||
settingsDialog.setTitle(R.string.bluetooth_preference_paired_devices);
|
settingsDialog.setTitle(R.string.bluetooth_preference_paired_devices);
|
||||||
settingsDialog.setPositiveButton(R.string.okay,
|
settingsDialog.setPositiveButton(R.string.okay,
|
||||||
@@ -429,7 +432,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
device.setName(deviceName.getText().toString());
|
device.setName(deviceName.getText().toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final Context context = v.getContext();
|
|
||||||
settingsDialog.setNegativeButton(R.string.forget,
|
settingsDialog.setNegativeButton(R.string.forget,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -442,6 +445,16 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// We must ensure that the fragment gets destroyed to avoid duplicate fragments.
|
||||||
|
settingsDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||||
|
public void onDismiss(final DialogInterface dialog) {
|
||||||
|
if (!activity.isDestroyed()) {
|
||||||
|
activity.getFragmentManager().beginTransaction().remove(dpsFragment)
|
||||||
|
.commitAllowingStateLoss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
AlertDialog dialog = settingsDialog.create();
|
AlertDialog dialog = settingsDialog.create();
|
||||||
dialog.create();
|
dialog.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
@@ -232,7 +232,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
|||||||
status == BluetoothProfile.STATE_CONNECTED;
|
status == BluetoothProfile.STATE_CONNECTED;
|
||||||
|
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
askDisconnect(getActivity(), profile);
|
askDisconnect(mManager.getForegroundActivity(), profile);
|
||||||
} else {
|
} else {
|
||||||
if (profile.isPreferred(device)) {
|
if (profile.isPreferred(device)) {
|
||||||
// profile is preferred but not connected: disable auto-connect
|
// profile is preferred but not connected: disable auto-connect
|
||||||
|
Reference in New Issue
Block a user