Bluetooth device slice improvement

- remove "Pair new device" row
- change the on/off toggle to a plus button for pairing new device
- roll back the title "Bluetooth devices"

Bug: 149667096
Test: robotest
Change-Id: I47e9c47b2ab0adacdbdbde34522d7c0172adda75
Merged-In: I47e9c47b2ab0adacdbdbde34522d7c0172adda75
(cherry picked from commit 5e462a852b)
This commit is contained in:
Jason Chiu
2020-02-20 16:53:50 +08:00
parent 34fdec2668
commit 05f5b8e7c4
5 changed files with 18 additions and 142 deletions

View File

@@ -394,8 +394,6 @@
<!-- Maximum height for SliceView, override on slices/view/src/main/res/values/dimens.xml -->
<!-- A single Row Slice height is 60dp -->
<dimen name="abc_slice_large_height">1200dp</dimen>
<!-- Min height of slice row view, override on slices/view/src/main/res/values/dimens.xml -->
<dimen name="abc_slice_row_min_height">@dimen/abc_slice_row_max_height</dimen>
<!-- System navigation settings illustration height -->
<dimen name="system_navigation_illustration_height">320dp</dimen>

View File

@@ -144,6 +144,8 @@
<string name="bluetooth_lock_voice_dialing_summary">
Prevent use of the bluetooth dialer when the screen is locked
</string>
<!-- Bluetooth settings screen, heading above the list of nearby bluetooth devices. [CHAR LIMIT=NONE] -->
<string name="bluetooth_devices">Bluetooth devices</string>
<!-- Bluetooth settings screen, title for the current bluetooth name setting -->
<string name="bluetooth_device_name">Device name</string>
<!-- Bluetooth settings screen, image description for device details button. This opens the screen to rename, unpair, etc. a single device. -->

View File

@@ -16,14 +16,14 @@
package com.android.settings.homepage.contextualcards.slices;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
@@ -77,8 +77,6 @@ public class BluetoothDevicesSlice implements CustomSliceable {
private static final String TAG = "BluetoothDevicesSlice";
private static int sToggledState;
private final Context mContext;
public BluetoothDevicesSlice(Context context) {
@@ -103,37 +101,26 @@ public class BluetoothDevicesSlice implements CustomSliceable {
final IconCompat icon = IconCompat.createWithResource(mContext,
com.android.internal.R.drawable.ic_settings_bluetooth);
final CharSequence title = mContext.getText(R.string.bluetooth_settings_title);
final CharSequence title = mContext.getText(R.string.bluetooth_devices);
final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, 0,
getIntent(), 0);
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon,
ListBuilder.ICON_IMAGE, title);
final SliceAction pairNewDeviceAction = getPairNewDeviceAction();
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
.setAccentColor(COLOR_NOT_TINTED)
.addAction(pairNewDeviceAction)
.setHeader(new ListBuilder.HeaderBuilder()
.setTitle(title)
.setPrimaryAction(primarySliceAction));
// Only show a toggle when Bluetooth is off and not turning on.
if ((!isBluetoothEnabled(btAdapter) && sToggledState != BluetoothAdapter.STATE_TURNING_ON)
|| sToggledState == BluetoothAdapter.STATE_TURNING_OFF) {
sToggledState = 0;
final PendingIntent toggleAction = getBroadcastIntent(mContext);
final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction,
null /* actionTitle */, false /* isChecked */);
return listBuilder
.addAction(toggleSliceAction)
.build();
// Only show a header when Bluetooth is off.
if (!isBluetoothEnabled(btAdapter)) {
return listBuilder.build();
}
sToggledState = 0;
// Get row builders by Bluetooth devices.
final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder();
if (rows.isEmpty()) {
return listBuilder
.addRow(getPairNewDeviceRow())
.build();
}
// Get displayable device count.
final int deviceCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT);
@@ -161,20 +148,6 @@ public class BluetoothDevicesSlice implements CustomSliceable {
@Override
public void onNotifyChange(Intent intent) {
final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
final boolean currentState = isBluetoothEnabled(btAdapter);
final boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, currentState);
if (newState != currentState) {
if (newState) {
sToggledState = BluetoothAdapter.STATE_TURNING_ON;
btAdapter.enable();
} else {
sToggledState = BluetoothAdapter.STATE_TURNING_OFF;
btAdapter.disable();
}
mContext.getContentResolver().notifyChange(getUri(), null);
}
// Activate available media device.
final int bluetoothDeviceHashCode = intent.getIntExtra(BLUETOOTH_DEVICE_HASH_CODE, -1);
for (CachedBluetoothDevice cachedBluetoothDevice : getConnectedBluetoothDevices()) {
@@ -250,8 +223,11 @@ public class BluetoothDevicesSlice implements CustomSliceable {
return Utils.createIconWithDrawable(drawable);
}
private ListBuilder.RowBuilder getPairNewDeviceRow() {
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp);
private SliceAction getPairNewDeviceAction() {
final Drawable d = mContext.getDrawable(R.drawable.ic_add_24dp);
d.setColorFilter(new PorterDuffColorFilter(Utils.getColorAccentDefaultColor(mContext),
PorterDuff.Mode.SRC_IN));
final IconCompat icon = Utils.createIconWithDrawable(d);
final String title = mContext.getString(R.string.bluetooth_pairing_pref_title);
final Intent intent = new SubSettingLauncher(mContext)
.setDestination(BluetoothPairingDetail.class.getName())
@@ -260,11 +236,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
.toIntent();
final PendingIntent pi = PendingIntent.getActivity(mContext, intent.hashCode(), intent,
0 /* flags */);
final SliceAction action = SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE,
title);
return new ListBuilder.RowBuilder()
.setTitleItem(action)
.setTitle(title);
return SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE, title);
}
private List<ListBuilder.RowBuilder> getBluetoothRowBuilder() {

View File

@@ -16,7 +16,6 @@
package com.android.settings.homepage.contextualcards.slices;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static android.app.slice.Slice.HINT_LIST_ITEM;
import static android.app.slice.SliceItem.FORMAT_SLICE;
@@ -38,7 +37,6 @@ import androidx.slice.Slice;
import androidx.slice.SliceItem;
import androidx.slice.SliceMetadata;
import androidx.slice.SliceProvider;
import androidx.slice.core.SliceAction;
import androidx.slice.core.SliceQuery;
import androidx.slice.widget.SliceLiveData;
@@ -117,91 +115,17 @@ public class BluetoothDevicesSliceTest {
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_bluetoothOff_shouldHaveToggle() {
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
adapter.setState(BluetoothAdapter.STATE_OFF);
public void getSlice_hasBluetoothHardware_shouldHaveBluetoothDevicesTitleAndPairNewDevice() {
final Slice slice = mBluetoothDevicesSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
assertTitleAndIcon(metadata);
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
}
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_bluetoothOn_shouldNotHaveToggle() {
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
adapter.setState(BluetoothAdapter.STATE_ON);
final Slice slice = mBluetoothDevicesSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
assertTitleAndIcon(metadata);
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).isEmpty();
}
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_bluetoothTurningOff_shouldHaveToggle() {
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
adapter.setState(BluetoothAdapter.STATE_ON);
final Intent intent = new Intent().putExtra(EXTRA_TOGGLE_STATE, false);
mBluetoothDevicesSlice.onNotifyChange(intent);
final Slice slice = mBluetoothDevicesSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
}
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_bluetoothTurningOn_shouldHaveToggle() {
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
adapter.setState(BluetoothAdapter.STATE_OFF);
final Intent intent = new Intent().putExtra(EXTRA_TOGGLE_STATE, true);
mBluetoothDevicesSlice.onNotifyChange(intent);
final Slice slice = mBluetoothDevicesSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).isEmpty();
}
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_noBluetoothDevice_shouldHavePairNewDeviceRow() {
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
adapter.setState(BluetoothAdapter.STATE_ON);
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
final Slice slice = mBluetoothDevicesSlice.getSlice();
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_devices));
final List<SliceItem> sliceItems = slice.getItems();
SliceTester.assertAnySliceItemContainsTitle(sliceItems, mContext.getString(
R.string.bluetooth_pairing_pref_title));
}
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_hasBluetoothDevices_shouldNotHavePairNewDeviceRow() {
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
adapter.setState(BluetoothAdapter.STATE_ON);
mockBluetoothDeviceList(1);
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
final Slice slice = mBluetoothDevicesSlice.getSlice();
final List<SliceItem> sliceItems = slice.getItems();
SliceTester.assertNoSliceItemContainsTitle(sliceItems, mContext.getString(
R.string.bluetooth_pairing_pref_title));
}
@Test
@Config(shadows = ShadowBluetoothAdapter.class)
public void getSlice_hasBluetoothDevices_shouldMatchBluetoothMockTitle() {
@@ -280,16 +204,6 @@ public class BluetoothDevicesSliceTest {
}
}
private void assertTitleAndIcon(SliceMetadata metadata) {
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(
R.string.bluetooth_settings_title));
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
com.android.internal.R.drawable.ic_settings_bluetooth);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
}
@Implements(BluetoothAdapter.class)
public static class ShadowNoBluetoothAdapter extends ShadowBluetoothAdapter {
@Implementation

View File

@@ -242,16 +242,6 @@ public class SliceTester {
assertThat(hasText(sliceItems, title, HINT_TITLE)).isTrue();
}
/**
* Assert no slice item contains title.
*
* @param sliceItems All slice items of a Slice.
* @param title Title for asserting.
*/
public static void assertNoSliceItemContainsTitle(List<SliceItem> sliceItems, String title) {
assertThat(hasText(sliceItems, title, HINT_TITLE)).isFalse();
}
/**
* Assert any slice item contains subtitle.
*