Remove the gear icon and change tapping event
* Remove the gear icon in "currently connected" section. * Change the tapping event in "currently connected" section. When tapping device in this section, take user to device detail page. Bug: 78490845 Test: make -j40 RunSettingsRoboTests Change-Id: I25f8455def3c38e24dea9af9e9e29ba37c250f67 Merged-In: I25f8455def3c38e24dea9af9e9e29ba37c250f67
This commit is contained in:
@@ -56,6 +56,7 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
|
|
||||||
private AlertDialog mDisconnectDialog;
|
private AlertDialog mDisconnectDialog;
|
||||||
private String contentDescription = null;
|
private String contentDescription = null;
|
||||||
|
private boolean mHideSecondTarget = false;
|
||||||
/* Talk-back descriptions for various BT icons */
|
/* Talk-back descriptions for various BT icons */
|
||||||
Resources mResources;
|
Resources mResources;
|
||||||
|
|
||||||
@@ -86,7 +87,8 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
protected boolean shouldHideSecondTarget() {
|
protected boolean shouldHideSecondTarget() {
|
||||||
return mCachedDevice == null
|
return mCachedDevice == null
|
||||||
|| mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED
|
|| mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED
|
||||||
|| mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH);
|
|| mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)
|
||||||
|
|| mHideSecondTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,6 +114,10 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
return mCachedDevice;
|
return mCachedDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hideSecondTarget(boolean hideSecondTarget) {
|
||||||
|
mHideSecondTarget = hideSecondTarget;
|
||||||
|
}
|
||||||
|
|
||||||
public void onDeviceAttributesChanged() {
|
public void onDeviceAttributesChanged() {
|
||||||
/*
|
/*
|
||||||
* The preference framework takes care of making sure the value has
|
* The preference framework takes care of making sure the value has
|
||||||
|
@@ -56,29 +56,14 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
|
|||||||
protected final DevicePreferenceCallback mDevicePreferenceCallback;
|
protected final DevicePreferenceCallback mDevicePreferenceCallback;
|
||||||
protected final Map<BluetoothDevice, Preference> mPreferenceMap;
|
protected final Map<BluetoothDevice, Preference> mPreferenceMap;
|
||||||
protected Context mPrefContext;
|
protected Context mPrefContext;
|
||||||
|
protected DashboardFragment mFragment;
|
||||||
|
|
||||||
private final boolean mShowDeviceWithoutNames;
|
private final boolean mShowDeviceWithoutNames;
|
||||||
private DashboardFragment mFragment;
|
|
||||||
private Preference.OnPreferenceClickListener mDevicePreferenceClickListener = null;
|
private Preference.OnPreferenceClickListener mDevicePreferenceClickListener = null;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
|
final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
|
||||||
final CachedBluetoothDevice device =
|
launchDeviceDetails(pref);
|
||||||
((BluetoothDevicePreference) pref).getBluetoothDevice();
|
|
||||||
if (device == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Bundle args = new Bundle();
|
|
||||||
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS,
|
|
||||||
device.getDevice().getAddress());
|
|
||||||
|
|
||||||
new SubSettingLauncher(mFragment.getContext())
|
|
||||||
.setDestination(BluetoothDeviceDetailsFragment.class.getName())
|
|
||||||
.setArguments(args)
|
|
||||||
.setTitle(R.string.device_details_title)
|
|
||||||
.setSourceMetricsCategory(mFragment.getMetricsCategory())
|
|
||||||
.launch();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private class PreferenceClickListener implements
|
private class PreferenceClickListener implements
|
||||||
@@ -201,7 +186,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
|
|||||||
public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice);
|
public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update whether to show {@cde cachedBluetoothDevice} in the list.
|
* Update whether to show {@link CachedBluetoothDevice} in the list.
|
||||||
*/
|
*/
|
||||||
protected void update(CachedBluetoothDevice cachedBluetoothDevice) {
|
protected void update(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||||
if (isFilterMatched(cachedBluetoothDevice)) {
|
if (isFilterMatched(cachedBluetoothDevice)) {
|
||||||
@@ -239,6 +224,28 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get {@link CachedBluetoothDevice} from {@link Preference} and it is used to init
|
||||||
|
* {@link SubSettingLauncher} to launch {@link BluetoothDeviceDetailsFragment}
|
||||||
|
*/
|
||||||
|
protected void launchDeviceDetails(Preference preference) {
|
||||||
|
final CachedBluetoothDevice device =
|
||||||
|
((BluetoothDevicePreference) preference).getBluetoothDevice();
|
||||||
|
if (device == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Bundle args = new Bundle();
|
||||||
|
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS,
|
||||||
|
device.getDevice().getAddress());
|
||||||
|
|
||||||
|
new SubSettingLauncher(mFragment.getContext())
|
||||||
|
.setDestination(BluetoothDeviceDetailsFragment.class.getName())
|
||||||
|
.setArguments(args)
|
||||||
|
.setTitle(R.string.device_details_title)
|
||||||
|
.setSourceMetricsCategory(mFragment.getMetricsCategory())
|
||||||
|
.launch();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {@code true} if {@code cachedBluetoothDevice} is connected
|
* @return {@code true} if {@code cachedBluetoothDevice} is connected
|
||||||
* and the bond state is bonded.
|
* and the bond state is bonded.
|
||||||
|
@@ -16,11 +16,14 @@
|
|||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
@@ -116,4 +119,20 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
|||||||
}
|
}
|
||||||
return isFilterMatched;
|
return isFilterMatched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addPreference(CachedBluetoothDevice cachedDevice) {
|
||||||
|
super.addPreference(cachedDevice);
|
||||||
|
final BluetoothDevice device = cachedDevice.getDevice();
|
||||||
|
if (mPreferenceMap.containsKey(device)) {
|
||||||
|
final BluetoothDevicePreference btPreference =
|
||||||
|
(BluetoothDevicePreference) mPreferenceMap.get(device);
|
||||||
|
btPreference.setOnGearClickListener(null);
|
||||||
|
btPreference.hideSecondTarget(true);
|
||||||
|
btPreference.setOnPreferenceClickListener((Preference p) -> {
|
||||||
|
launchDeviceDetails(p);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -207,4 +208,15 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addPreference_addPreference_shouldHideSecondTarget() {
|
||||||
|
BluetoothDevicePreference btPreference =
|
||||||
|
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, true);
|
||||||
|
mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, btPreference);
|
||||||
|
|
||||||
|
mBluetoothDeviceUpdater.addPreference(mCachedBluetoothDevice);
|
||||||
|
|
||||||
|
assertThat(btPreference.shouldHideSecondTarget()).isTrue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user