Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3adfc10 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Bluetooth slice polish"

parents 9ada7355 5cc60a81
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -16,11 +16,14 @@

package com.android.settings.homepage.contextualcards.slices;

import android.annotation.ColorInt;
import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
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;
@@ -87,6 +90,9 @@ public class BluetoothDevicesSlice implements CustomSliceable {

    @Override
    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,
                com.android.internal.R.drawable.ic_settings_bluetooth);
        final CharSequence title = mContext.getText(R.string.bluetooth_devices);
@@ -98,7 +104,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
                ListBuilder.ICON_IMAGE, title);
        final ListBuilder listBuilder =
                new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
                        .setAccentColor(Utils.getColorAccentDefaultColor(mContext));
                        .setAccentColor(COLOR_NOT_TINTED);

        // Get row builders by Bluetooth devices.
        final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder();
@@ -207,13 +213,23 @@ public class BluetoothDevicesSlice implements CustomSliceable {
    IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) {
        final Pair<Drawable, String> pair = BluetoothUtils
                .getBtClassDrawableWithDescription(mContext, device);
        final Drawable drawable = pair.first;

        if (pair.first != null) {
            return Utils.createIconWithDrawable(pair.first);
        } else {
        // Use default bluetooth icon if can't get icon.
        if (drawable == null) {
            return IconCompat.createWithResource(mContext,
                    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() {
@@ -227,7 +243,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
                    .setSubtitle(bluetoothDevice.getConnectionSummary());

            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.
                rowBuilder.setPrimaryAction(buildMediaBluetoothAction(bluetoothDevice));
                rowBuilder.addEndItem(buildBluetoothDetailDeepLinkAction(bluetoothDevice));
@@ -260,7 +276,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
    SliceAction buildBluetoothDetailDeepLinkAction(CachedBluetoothDevice bluetoothDevice) {
        return SliceAction.createDeeplink(
                getBluetoothDetailIntent(bluetoothDevice),
                IconCompat.createWithResource(mContext, R.drawable.ic_settings_24dp),
                IconCompat.createWithResource(mContext, R.drawable.ic_settings_accent),
                ListBuilder.ICON_IMAGE,
                bluetoothDevice.getName());
    }