Loading src/com/android/settings/bluetooth/BluetoothDevicePreference.java +8 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.util.Pair; import android.util.TypedValue; import android.widget.ImageView; import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.AlertDialog; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; Loading Loading @@ -59,6 +60,8 @@ public final class BluetoothDevicePreference extends GearPreference implements private AlertDialog mDisconnectDialog; private String contentDescription = null; private boolean mHideSecondTarget = false; @VisibleForTesting boolean mNeedNotifyHierarchyChanged = false; /* Talk-back descriptions for various BT icons */ Resources mResources; Loading @@ -81,8 +84,8 @@ public final class BluetoothDevicePreference extends GearPreference implements onDeviceAttributesChanged(); } void rebind() { notifyChanged(); public void setNeedNotifyHierarchyChanged(boolean needNotifyHierarchyChanged) { mNeedNotifyHierarchyChanged = needNotifyHierarchyChanged; } @Override Loading Loading @@ -145,8 +148,10 @@ public final class BluetoothDevicePreference extends GearPreference implements setVisible(mShowDevicesWithoutNames || mCachedDevice.hasHumanReadableName()); // This could affect ordering, so notify that if (mNeedNotifyHierarchyChanged) { notifyHierarchyChanged(); } } @Override public void onBindViewHolder(PreferenceViewHolder view) { Loading src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java +4 −7 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; import java.util.Collection; import java.util.HashMap; import java.util.WeakHashMap; /** Loading Loading @@ -69,8 +70,8 @@ public abstract class DeviceListPreferenceFragment extends @VisibleForTesting PreferenceGroup mDeviceListGroup; final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap = new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>(); final HashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap = new HashMap<>(); boolean mShowDevicesWithoutNames; Loading Loading @@ -195,17 +196,13 @@ public abstract class DeviceListPreferenceFragment extends //Set hideSecondTarget is true if it's bonded device. preference.hideSecondTarget(true); mDeviceListGroup.addPreference(preference); } else { // Tell the preference it is being re-used in case there is new info in the // cached device. preference.rebind(); } initDevicePreference(preference); mDevicePreferenceMap.put(cachedDevice, preference); } void initDevicePreference(BluetoothDevicePreference preference) { protected void initDevicePreference(BluetoothDevicePreference preference) { // Does nothing by default } Loading src/com/android/settings/bluetooth/DevicePickerFragment.java +6 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,12 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { } } @Override protected void initDevicePreference(BluetoothDevicePreference preference) { super.initDevicePreference(preference); preference.setNeedNotifyHierarchyChanged(true); } @Override public void onBluetoothStateChanged(int bluetoothState) { super.onBluetoothStateChanged(bluetoothState); Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java +9 −2 Original line number Diff line number Diff line Loading @@ -166,7 +166,7 @@ public class BluetoothDevicePreferenceTest { } @Test public void testVisible_showDeviceWithoutNames_visible() { public void isVisible_showDeviceWithoutNames_visible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, Loading @@ -176,11 +176,18 @@ public class BluetoothDevicePreferenceTest { } @Test public void testVisible_hideDeviceWithoutNames_invisible() { public void isVisible_hideDeviceWithoutNames_invisible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false); assertThat(preference.isVisible()).isFalse(); } @Test public void setNeedNotifyHierarchyChanged_updateValue() { mPreference.setNeedNotifyHierarchyChanged(true); assertThat(mPreference.mNeedNotifyHierarchyChanged).isTrue(); } } Loading
src/com/android/settings/bluetooth/BluetoothDevicePreference.java +8 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.util.Pair; import android.util.TypedValue; import android.widget.ImageView; import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.AlertDialog; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; Loading Loading @@ -59,6 +60,8 @@ public final class BluetoothDevicePreference extends GearPreference implements private AlertDialog mDisconnectDialog; private String contentDescription = null; private boolean mHideSecondTarget = false; @VisibleForTesting boolean mNeedNotifyHierarchyChanged = false; /* Talk-back descriptions for various BT icons */ Resources mResources; Loading @@ -81,8 +84,8 @@ public final class BluetoothDevicePreference extends GearPreference implements onDeviceAttributesChanged(); } void rebind() { notifyChanged(); public void setNeedNotifyHierarchyChanged(boolean needNotifyHierarchyChanged) { mNeedNotifyHierarchyChanged = needNotifyHierarchyChanged; } @Override Loading Loading @@ -145,8 +148,10 @@ public final class BluetoothDevicePreference extends GearPreference implements setVisible(mShowDevicesWithoutNames || mCachedDevice.hasHumanReadableName()); // This could affect ordering, so notify that if (mNeedNotifyHierarchyChanged) { notifyHierarchyChanged(); } } @Override public void onBindViewHolder(PreferenceViewHolder view) { Loading
src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java +4 −7 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; import java.util.Collection; import java.util.HashMap; import java.util.WeakHashMap; /** Loading Loading @@ -69,8 +70,8 @@ public abstract class DeviceListPreferenceFragment extends @VisibleForTesting PreferenceGroup mDeviceListGroup; final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap = new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>(); final HashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap = new HashMap<>(); boolean mShowDevicesWithoutNames; Loading Loading @@ -195,17 +196,13 @@ public abstract class DeviceListPreferenceFragment extends //Set hideSecondTarget is true if it's bonded device. preference.hideSecondTarget(true); mDeviceListGroup.addPreference(preference); } else { // Tell the preference it is being re-used in case there is new info in the // cached device. preference.rebind(); } initDevicePreference(preference); mDevicePreferenceMap.put(cachedDevice, preference); } void initDevicePreference(BluetoothDevicePreference preference) { protected void initDevicePreference(BluetoothDevicePreference preference) { // Does nothing by default } Loading
src/com/android/settings/bluetooth/DevicePickerFragment.java +6 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,12 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { } } @Override protected void initDevicePreference(BluetoothDevicePreference preference) { super.initDevicePreference(preference); preference.setNeedNotifyHierarchyChanged(true); } @Override public void onBluetoothStateChanged(int bluetoothState) { super.onBluetoothStateChanged(bluetoothState); Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java +9 −2 Original line number Diff line number Diff line Loading @@ -166,7 +166,7 @@ public class BluetoothDevicePreferenceTest { } @Test public void testVisible_showDeviceWithoutNames_visible() { public void isVisible_showDeviceWithoutNames_visible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, Loading @@ -176,11 +176,18 @@ public class BluetoothDevicePreferenceTest { } @Test public void testVisible_hideDeviceWithoutNames_invisible() { public void isVisible_hideDeviceWithoutNames_invisible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false); assertThat(preference.isVisible()).isFalse(); } @Test public void setNeedNotifyHierarchyChanged_updateValue() { mPreference.setNeedNotifyHierarchyChanged(true); assertThat(mPreference.mNeedNotifyHierarchyChanged).isTrue(); } }