Merge "Decouple BluetoothDevicePreference and DeviceListPreferenceFragment"

This commit is contained in:
Lei Yu
2017-11-20 21:27:20 +00:00
committed by Android (Google) Code Review
3 changed files with 19 additions and 42 deletions

View File

@@ -52,19 +52,19 @@ public final class BluetoothDevicePreference extends GearPreference implements
private final CachedBluetoothDevice mCachedDevice;
private final UserManager mUserManager;
private final boolean mShowDevicesWithoutNames;
private AlertDialog mDisconnectDialog;
private String contentDescription = null;
private DeviceListPreferenceFragment mDeviceListPreferenceFragment;
/* Talk-back descriptions for various BT icons */
Resources mResources;
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice,
DeviceListPreferenceFragment deviceListPreferenceFragment) {
boolean showDeviceWithoutNames) {
super(context, null);
mResources = getContext().getResources();
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mDeviceListPreferenceFragment = deviceListPreferenceFragment;
mShowDevicesWithoutNames = showDeviceWithoutNames;
if (sDimAlpha == Integer.MIN_VALUE) {
TypedValue outValue = new TypedValue();
@@ -134,8 +134,7 @@ public final class BluetoothDevicePreference extends GearPreference implements
// Device is only visible in the UI if it has a valid name besides MAC address or when user
// allows showing devices without user-friendly name in developer settings
setVisible(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()
|| mCachedDevice.hasHumanReadableName());
setVisible(mShowDevicesWithoutNames || mCachedDevice.hasHumanReadableName());
// This could affect ordering, so notify that
notifyHierarchyChanged();

View File

@@ -98,6 +98,8 @@ public abstract class DeviceListPreferenceFragment extends
return;
}
mLocalAdapter = mLocalManager.getBluetoothAdapter();
mShowDevicesWithoutNames = SystemProperties.getBoolean(
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false);
initPreferencesFromPreferenceScreen();
@@ -110,8 +112,6 @@ public abstract class DeviceListPreferenceFragment extends
@Override
public void onStart() {
super.onStart();
mShowDevicesWithoutNames = SystemProperties.getBoolean(
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false);
if (mLocalManager == null || isUiRestricted()) return;
mLocalManager.setForegroundActivity(getActivity());
@@ -190,7 +190,8 @@ public abstract class DeviceListPreferenceFragment extends
BluetoothDevicePreference preference = (BluetoothDevicePreference) getCachedPreference(key);
if (preference == null) {
preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice, this);
preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice,
mShowDevicesWithoutNames);
preference.setKey(key);
mDeviceListGroup.addPreference(preference);
} else {