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:
hughchen
2018-04-24 15:46:30 +08:00
committed by tim peng
parent 1a38390728
commit 8dcd550d36
4 changed files with 63 additions and 19 deletions

View File

@@ -56,6 +56,7 @@ public final class BluetoothDevicePreference extends GearPreference implements
private AlertDialog mDisconnectDialog;
private String contentDescription = null;
private boolean mHideSecondTarget = false;
/* Talk-back descriptions for various BT icons */
Resources mResources;
@@ -86,7 +87,8 @@ public final class BluetoothDevicePreference extends GearPreference implements
protected boolean shouldHideSecondTarget() {
return mCachedDevice == null
|| mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED
|| mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH);
|| mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)
|| mHideSecondTarget;
}
@Override
@@ -112,6 +114,10 @@ public final class BluetoothDevicePreference extends GearPreference implements
return mCachedDevice;
}
public void hideSecondTarget(boolean hideSecondTarget) {
mHideSecondTarget = hideSecondTarget;
}
public void onDeviceAttributesChanged() {
/*
* The preference framework takes care of making sure the value has

View File

@@ -56,29 +56,14 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
protected final DevicePreferenceCallback mDevicePreferenceCallback;
protected final Map<BluetoothDevice, Preference> mPreferenceMap;
protected Context mPrefContext;
protected DashboardFragment mFragment;
private final boolean mShowDeviceWithoutNames;
private DashboardFragment mFragment;
private Preference.OnPreferenceClickListener mDevicePreferenceClickListener = null;
@VisibleForTesting
final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
final CachedBluetoothDevice device =
((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();
launchDeviceDetails(pref);
};
private class PreferenceClickListener implements
@@ -201,7 +186,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
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) {
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
* and the bond state is bonded.

View File

@@ -16,11 +16,14 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.media.AudioManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.util.Log;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -116,4 +119,20 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
}
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;
});
}
}
}

View File

@@ -15,6 +15,7 @@
*/
package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -207,4 +208,15 @@ public class ConnectedBluetoothDeviceUpdaterTest {
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();
}
}