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:
@@ -394,8 +394,6 @@
|
|||||||
<!-- Maximum height for SliceView, override on slices/view/src/main/res/values/dimens.xml -->
|
<!-- Maximum height for SliceView, override on slices/view/src/main/res/values/dimens.xml -->
|
||||||
<!-- A single Row Slice height is 60dp -->
|
<!-- A single Row Slice height is 60dp -->
|
||||||
<dimen name="abc_slice_large_height">1200dp</dimen>
|
<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 -->
|
<!-- System navigation settings illustration height -->
|
||||||
<dimen name="system_navigation_illustration_height">320dp</dimen>
|
<dimen name="system_navigation_illustration_height">320dp</dimen>
|
||||||
|
@@ -144,6 +144,8 @@
|
|||||||
<string name="bluetooth_lock_voice_dialing_summary">
|
<string name="bluetooth_lock_voice_dialing_summary">
|
||||||
Prevent use of the bluetooth dialer when the screen is locked
|
Prevent use of the bluetooth dialer when the screen is locked
|
||||||
</string>
|
</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 -->
|
<!-- Bluetooth settings screen, title for the current bluetooth name setting -->
|
||||||
<string name="bluetooth_device_name">Device name</string>
|
<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. -->
|
<!-- Bluetooth settings screen, image description for device details button. This opens the screen to rename, unpair, etc. a single device. -->
|
||||||
|
@@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package com.android.settings.homepage.contextualcards.slices;
|
package com.android.settings.homepage.contextualcards.slices;
|
||||||
|
|
||||||
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.graphics.PorterDuffColorFilter;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -77,8 +77,6 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
|
|
||||||
private static final String TAG = "BluetoothDevicesSlice";
|
private static final String TAG = "BluetoothDevicesSlice";
|
||||||
|
|
||||||
private static int sToggledState;
|
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public BluetoothDevicesSlice(Context context) {
|
public BluetoothDevicesSlice(Context context) {
|
||||||
@@ -103,37 +101,26 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
|
|
||||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||||
com.android.internal.R.drawable.ic_settings_bluetooth);
|
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,
|
final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, 0,
|
||||||
getIntent(), 0);
|
getIntent(), 0);
|
||||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon,
|
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon,
|
||||||
ListBuilder.ICON_IMAGE, title);
|
ListBuilder.ICON_IMAGE, title);
|
||||||
|
final SliceAction pairNewDeviceAction = getPairNewDeviceAction();
|
||||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||||
.setAccentColor(COLOR_NOT_TINTED)
|
.setAccentColor(COLOR_NOT_TINTED)
|
||||||
|
.addAction(pairNewDeviceAction)
|
||||||
.setHeader(new ListBuilder.HeaderBuilder()
|
.setHeader(new ListBuilder.HeaderBuilder()
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setPrimaryAction(primarySliceAction));
|
.setPrimaryAction(primarySliceAction));
|
||||||
|
|
||||||
// Only show a toggle when Bluetooth is off and not turning on.
|
// Only show a header when Bluetooth is off.
|
||||||
if ((!isBluetoothEnabled(btAdapter) && sToggledState != BluetoothAdapter.STATE_TURNING_ON)
|
if (!isBluetoothEnabled(btAdapter)) {
|
||||||
|| sToggledState == BluetoothAdapter.STATE_TURNING_OFF) {
|
return listBuilder.build();
|
||||||
sToggledState = 0;
|
|
||||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
|
||||||
final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction,
|
|
||||||
null /* actionTitle */, false /* isChecked */);
|
|
||||||
return listBuilder
|
|
||||||
.addAction(toggleSliceAction)
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
sToggledState = 0;
|
|
||||||
|
|
||||||
// Get row builders by Bluetooth devices.
|
// Get row builders by Bluetooth devices.
|
||||||
final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder();
|
final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder();
|
||||||
if (rows.isEmpty()) {
|
|
||||||
return listBuilder
|
|
||||||
.addRow(getPairNewDeviceRow())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get displayable device count.
|
// Get displayable device count.
|
||||||
final int deviceCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT);
|
final int deviceCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT);
|
||||||
@@ -161,20 +148,6 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotifyChange(Intent intent) {
|
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.
|
// Activate available media device.
|
||||||
final int bluetoothDeviceHashCode = intent.getIntExtra(BLUETOOTH_DEVICE_HASH_CODE, -1);
|
final int bluetoothDeviceHashCode = intent.getIntExtra(BLUETOOTH_DEVICE_HASH_CODE, -1);
|
||||||
for (CachedBluetoothDevice cachedBluetoothDevice : getConnectedBluetoothDevices()) {
|
for (CachedBluetoothDevice cachedBluetoothDevice : getConnectedBluetoothDevices()) {
|
||||||
@@ -250,8 +223,11 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
return Utils.createIconWithDrawable(drawable);
|
return Utils.createIconWithDrawable(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListBuilder.RowBuilder getPairNewDeviceRow() {
|
private SliceAction getPairNewDeviceAction() {
|
||||||
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp);
|
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 String title = mContext.getString(R.string.bluetooth_pairing_pref_title);
|
||||||
final Intent intent = new SubSettingLauncher(mContext)
|
final Intent intent = new SubSettingLauncher(mContext)
|
||||||
.setDestination(BluetoothPairingDetail.class.getName())
|
.setDestination(BluetoothPairingDetail.class.getName())
|
||||||
@@ -260,11 +236,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
.toIntent();
|
.toIntent();
|
||||||
final PendingIntent pi = PendingIntent.getActivity(mContext, intent.hashCode(), intent,
|
final PendingIntent pi = PendingIntent.getActivity(mContext, intent.hashCode(), intent,
|
||||||
0 /* flags */);
|
0 /* flags */);
|
||||||
final SliceAction action = SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE,
|
return SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE, title);
|
||||||
title);
|
|
||||||
return new ListBuilder.RowBuilder()
|
|
||||||
.setTitleItem(action)
|
|
||||||
.setTitle(title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ListBuilder.RowBuilder> getBluetoothRowBuilder() {
|
private List<ListBuilder.RowBuilder> getBluetoothRowBuilder() {
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.homepage.contextualcards.slices;
|
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.Slice.HINT_LIST_ITEM;
|
||||||
import static android.app.slice.SliceItem.FORMAT_SLICE;
|
import static android.app.slice.SliceItem.FORMAT_SLICE;
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@ import androidx.slice.Slice;
|
|||||||
import androidx.slice.SliceItem;
|
import androidx.slice.SliceItem;
|
||||||
import androidx.slice.SliceMetadata;
|
import androidx.slice.SliceMetadata;
|
||||||
import androidx.slice.SliceProvider;
|
import androidx.slice.SliceProvider;
|
||||||
import androidx.slice.core.SliceAction;
|
|
||||||
import androidx.slice.core.SliceQuery;
|
import androidx.slice.core.SliceQuery;
|
||||||
import androidx.slice.widget.SliceLiveData;
|
import androidx.slice.widget.SliceLiveData;
|
||||||
|
|
||||||
@@ -117,91 +115,17 @@ public class BluetoothDevicesSliceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||||
public void getSlice_bluetoothOff_shouldHaveToggle() {
|
public void getSlice_hasBluetoothHardware_shouldHaveBluetoothDevicesTitleAndPairNewDevice() {
|
||||||
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
|
||||||
adapter.setState(BluetoothAdapter.STATE_OFF);
|
|
||||||
|
|
||||||
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||||
|
|
||||||
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
||||||
assertTitleAndIcon(metadata);
|
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_devices));
|
||||||
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();
|
|
||||||
|
|
||||||
final List<SliceItem> sliceItems = slice.getItems();
|
final List<SliceItem> sliceItems = slice.getItems();
|
||||||
SliceTester.assertAnySliceItemContainsTitle(sliceItems, mContext.getString(
|
SliceTester.assertAnySliceItemContainsTitle(sliceItems, mContext.getString(
|
||||||
R.string.bluetooth_pairing_pref_title));
|
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
|
@Test
|
||||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||||
public void getSlice_hasBluetoothDevices_shouldMatchBluetoothMockTitle() {
|
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)
|
@Implements(BluetoothAdapter.class)
|
||||||
public static class ShadowNoBluetoothAdapter extends ShadowBluetoothAdapter {
|
public static class ShadowNoBluetoothAdapter extends ShadowBluetoothAdapter {
|
||||||
@Implementation
|
@Implementation
|
||||||
|
@@ -242,16 +242,6 @@ public class SliceTester {
|
|||||||
assertThat(hasText(sliceItems, title, HINT_TITLE)).isTrue();
|
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.
|
* Assert any slice item contains subtitle.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user