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

Commit 7e853a45 authored by hughchen's avatar hughchen
Browse files

According Bluetooth device type to get icon

- Change getIcon() type from int to Drawable
- According Bluetooth device type to get icon
  e.g: fast pair device, hearing aid device, a2dp device

Bug: 128570540
Test: make -j42 RunSettingsLibRoboTests
Change-Id: I662e31958f6102c1c83b2de9112bf8967c8efbbc
parent 678f4fc1
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2019 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:width="24dp"
        android:height="24dp"
        android:tint="?android:attr/colorControlNormal">
    <path
        android:fillColor="#00000000"
        android:fillAlpha=".1"
        android:pathData="M0 0h24v24H0z" />
    <path
        android:fillColor="#00000000"
        android:pathData="M0 0h24v24H0z" />
    <path
        android:fillColor="#000000"
        android:pathData="M21 3H3c-1.1 0-2 0.9-2 2v3h2V5h18v14h-7v2h7c1.1 0 2 -0.9 2-2V5c0-1.1 -0.9-2-2-2zM1 18v3h3c0-1.66-1.34-3-3-3zm0-4v2c2.76 0 5 2.24 5 5h2c0-3.87-3.13-7-7-7zm0-4v2c4.97 0 9 4.03 9 9h2c0-6.08-4.93-11-11-11z" />
</vector>
 No newline at end of file
+15 −4
Original line number Diff line number Diff line
@@ -165,16 +165,27 @@ public class BluetoothUtils {
            }
        }

        return new Pair<>(buildBtRainbowDrawable(context,
                pair.first, cachedDevice.getAddress().hashCode()), pair.second);
    }

    /**
     * Build Bluetooth device icon with rainbow
     */
    public static Drawable buildBtRainbowDrawable(Context context, Drawable drawable,
            int hashCode) {
        final Resources resources = context.getResources();

        // Deal with normal headset
        final int[] iconFgColors = resources.getIntArray(R.array.bt_icon_fg_colors);
        final int[] iconBgColors = resources.getIntArray(R.array.bt_icon_bg_colors);

        // get color index based on mac address
        final int index =  Math.abs(cachedDevice.getAddress().hashCode()) % iconBgColors.length;
        pair.first.setColorFilter(iconFgColors[index], PorterDuff.Mode.SRC_ATOP);
        final Drawable adaptiveIcon = new AdaptiveIcon(context, pair.first);
        final int index =  Math.abs(hashCode % iconBgColors.length);
        drawable.setColorFilter(iconFgColors[index], PorterDuff.Mode.SRC_ATOP);
        final Drawable adaptiveIcon = new AdaptiveIcon(context, drawable);
        ((AdaptiveIcon) adaptiveIcon).setBackgroundColor(iconBgColors[index]);

        return new Pair<>(adaptiveIcon, pair.second);
        return adaptiveIcon;
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -18,8 +18,11 @@ package com.android.settingslib.media;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.Pair;

import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;

/**
@@ -48,9 +51,10 @@ public class BluetoothMediaDevice extends MediaDevice {
    }

    @Override
    public int getIcon() {
        //TODO(b/117129183): This is not final icon for bluetooth device, just for demo.
        return com.android.internal.R.drawable.ic_bt_headphones_a2dp;
    public Drawable getIcon() {
        final Pair<Drawable, String> pair = BluetoothUtils
                .getBtRainbowDrawableWithDescription(mContext, mCachedDevice);
        return pair.first;
    }

    @Override
+8 −3
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@
package com.android.settingslib.media;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import androidx.mediarouter.media.MediaRouter;

import com.android.settingslib.R;
import com.android.settingslib.bluetooth.BluetoothUtils;

/**
 * InfoMediaDevice extends MediaDevice to represents wifi device.
 */
@@ -46,9 +50,10 @@ public class InfoMediaDevice extends MediaDevice {
    }

    @Override
    public int getIcon() {
        //TODO(b/121083246): This is not final icon for cast device, just for demo.
        return com.android.internal.R.drawable.ic_settings_print;
    public Drawable getIcon() {
        //TODO(b/120669861): Return remote device icon uri once api is ready.
        return BluetoothUtils.buildBtRainbowDrawable(mContext,
                mContext.getDrawable(R.drawable.ic_media_device), getId().hashCode());
    }

    @Override
+4 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.settingslib.media;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;

import androidx.annotation.IntDef;
@@ -70,11 +71,11 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
    public abstract String getSummary();

    /**
     * Get resource id of MediaDevice.
     * Get icon of MediaDevice.
     *
     * @return resource id of MediaDevice.
     * @return drawable of icon.
     */
    public abstract int getIcon();
    public abstract Drawable getIcon();

    /**
     * Get unique ID that represent MediaDevice
Loading