Merge "Bluetooth slice polish"

This commit is contained in:
TreeHugger Robot
2019-03-09 07:00:48 +00:00
committed by Android (Google) Code Review

View File

@@ -16,11 +16,14 @@
package com.android.settings.homepage.contextualcards.slices; package com.android.settings.homepage.contextualcards.slices;
import android.annotation.ColorInt;
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.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;
@@ -87,6 +90,9 @@ public class BluetoothDevicesSlice implements CustomSliceable {
@Override @Override
public Slice getSlice() { public Slice getSlice() {
// Reload theme for switching dark mode on/off
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
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_devices); final CharSequence title = mContext.getText(R.string.bluetooth_devices);
@@ -98,7 +104,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
ListBuilder.ICON_IMAGE, title); ListBuilder.ICON_IMAGE, title);
final ListBuilder listBuilder = final ListBuilder listBuilder =
new ListBuilder(mContext, getUri(), ListBuilder.INFINITY) new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
.setAccentColor(Utils.getColorAccentDefaultColor(mContext)); .setAccentColor(COLOR_NOT_TINTED);
// Get row builders by Bluetooth devices. // Get row builders by Bluetooth devices.
final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder(); final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder();
@@ -207,13 +213,23 @@ public class BluetoothDevicesSlice implements CustomSliceable {
IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) { IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) {
final Pair<Drawable, String> pair = BluetoothUtils final Pair<Drawable, String> pair = BluetoothUtils
.getBtClassDrawableWithDescription(mContext, device); .getBtClassDrawableWithDescription(mContext, device);
final Drawable drawable = pair.first;
if (pair.first != null) { // Use default bluetooth icon if can't get icon.
return Utils.createIconWithDrawable(pair.first); if (drawable == null) {
} else {
return IconCompat.createWithResource(mContext, return IconCompat.createWithResource(mContext,
com.android.internal.R.drawable.ic_settings_bluetooth); com.android.internal.R.drawable.ic_settings_bluetooth);
} }
// Tint icon: Accent color for connected state; Disable color for busy state.
@ColorInt int color = Utils.getColorAccentDefaultColor(mContext);
if (device.isBusy()) {
color = Utils.getDisabled(mContext,
Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal));
}
drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
return Utils.createIconWithDrawable(drawable);
} }
private List<ListBuilder.RowBuilder> getBluetoothRowBuilder() { private List<ListBuilder.RowBuilder> getBluetoothRowBuilder() {
@@ -227,7 +243,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
.setSubtitle(bluetoothDevice.getConnectionSummary()); .setSubtitle(bluetoothDevice.getConnectionSummary());
if (bluetoothDevice.isConnectedA2dpDevice()) { if (bluetoothDevice.isConnectedA2dpDevice()) {
// For available media devices, the primary action is to active audio stream and // For available media devices, the primary action is to activate audio stream and
// add setting icon to the end to link detail page. // add setting icon to the end to link detail page.
rowBuilder.setPrimaryAction(buildMediaBluetoothAction(bluetoothDevice)); rowBuilder.setPrimaryAction(buildMediaBluetoothAction(bluetoothDevice));
rowBuilder.addEndItem(buildBluetoothDetailDeepLinkAction(bluetoothDevice)); rowBuilder.addEndItem(buildBluetoothDetailDeepLinkAction(bluetoothDevice));
@@ -260,7 +276,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
SliceAction buildBluetoothDetailDeepLinkAction(CachedBluetoothDevice bluetoothDevice) { SliceAction buildBluetoothDetailDeepLinkAction(CachedBluetoothDevice bluetoothDevice) {
return SliceAction.createDeeplink( return SliceAction.createDeeplink(
getBluetoothDetailIntent(bluetoothDevice), getBluetoothDetailIntent(bluetoothDevice),
IconCompat.createWithResource(mContext, R.drawable.ic_settings_24dp), IconCompat.createWithResource(mContext, R.drawable.ic_settings_accent),
ListBuilder.ICON_IMAGE, ListBuilder.ICON_IMAGE,
bluetoothDevice.getName()); bluetoothDevice.getName());
} }