Merge "Make BT icon colorful"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c48cdcd5f9
@@ -26,7 +26,6 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
@@ -66,10 +65,8 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
|
||||
}
|
||||
|
||||
protected void setHeaderProperties() {
|
||||
final Pair<Drawable, String> pair = BluetoothUtils
|
||||
.getBtClassDrawableWithDescription(mContext, mCachedDevice,
|
||||
mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1,
|
||||
1));
|
||||
final Pair<Drawable, String> pair = Utils.getBtRainbowDrawableWithDescription(mContext,
|
||||
mCachedDevice);
|
||||
String summaryText = mCachedDevice.getConnectionSummary();
|
||||
// If both the hearing aids are connected, two device status should be shown.
|
||||
// If Second Summary is unavailable, to set it to null.
|
||||
|
@@ -38,7 +38,6 @@ import androidx.preference.PreferenceViewHolder;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -130,8 +129,8 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
// Null check is done at the framework
|
||||
setSummary(mCachedDevice.getConnectionSummary());
|
||||
|
||||
final Pair<Drawable, String> pair = BluetoothUtils
|
||||
.getBtClassDrawableWithDescription(getContext(), mCachedDevice);
|
||||
final Pair<Drawable, String> pair = Utils
|
||||
.getBtRainbowDrawableWithDescription(getContext(), mCachedDevice);
|
||||
if (pair.first != null) {
|
||||
setIcon(pair.first);
|
||||
contentDescription = pair.second;
|
||||
@@ -246,5 +245,4 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
R.string.bluetooth_pairing_error_message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -21,8 +21,12 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -30,8 +34,10 @@ import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.AdaptiveIcon;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
||||
|
||||
@@ -179,4 +185,25 @@ public final class Utils {
|
||||
return META_INT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get colorful bluetooth icon with description
|
||||
*/
|
||||
public static Pair<Drawable, String> getBtRainbowDrawableWithDescription(Context context,
|
||||
CachedBluetoothDevice cachedDevice) {
|
||||
final Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
|
||||
context, cachedDevice);
|
||||
final Resources resources = context.getResources();
|
||||
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);
|
||||
((AdaptiveIcon) adaptiveIcon).setBackgroundColor(iconBgColors[index]);
|
||||
|
||||
return new Pair<>(adaptiveIcon, pair.second);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.AdaptiveHomepageIcon;
|
||||
import com.android.settings.widget.AdaptiveIcon;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
@@ -197,8 +197,8 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
Drawable iconDrawable = tileIcon.loadDrawable(preference.getContext());
|
||||
if (forceRoundedIcon
|
||||
&& !TextUtils.equals(mContext.getPackageName(), tile.getPackageName())) {
|
||||
iconDrawable = new AdaptiveHomepageIcon(mContext, iconDrawable);
|
||||
((AdaptiveHomepageIcon) iconDrawable).setBackgroundColor(mContext, tile);
|
||||
iconDrawable = new AdaptiveIcon(mContext, iconDrawable);
|
||||
((AdaptiveIcon) iconDrawable).setBackgroundColor(mContext, tile);
|
||||
}
|
||||
preference.setIcon(iconDrawable);
|
||||
} else if (tile.getMetaData() != null
|
||||
|
@@ -46,7 +46,6 @@ import com.android.settings.slices.CustomSliceRegistry;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
import com.android.settings.slices.SliceBuilderUtils;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
@@ -211,8 +210,9 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
||||
|
||||
@VisibleForTesting
|
||||
IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) {
|
||||
final Pair<Drawable, String> pair = BluetoothUtils
|
||||
.getBtClassDrawableWithDescription(mContext, device);
|
||||
final Pair<Drawable, String> pair =
|
||||
com.android.settings.bluetooth.Utils.getBtRainbowDrawableWithDescription(mContext,
|
||||
device);
|
||||
final Drawable drawable = pair.first;
|
||||
|
||||
// Use default bluetooth icon if can't get icon.
|
||||
|
@@ -35,14 +35,15 @@ import com.android.settings.R;
|
||||
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
public class AdaptiveHomepageIcon extends LayerDrawable {
|
||||
public class AdaptiveIcon extends LayerDrawable {
|
||||
|
||||
private static final String TAG = "AdaptiveHomepageIcon";
|
||||
|
||||
@VisibleForTesting(otherwise = NONE)
|
||||
int mBackgroundColor = -1;
|
||||
private AdaptiveConstantState mAdaptiveConstantState;
|
||||
|
||||
public AdaptiveHomepageIcon(Context context, Drawable foreground) {
|
||||
public AdaptiveIcon(Context context, Drawable foreground) {
|
||||
super(new Drawable[]{
|
||||
new AdaptiveIconShapeDrawable(context.getResources()),
|
||||
foreground
|
||||
@@ -50,6 +51,7 @@ public class AdaptiveHomepageIcon extends LayerDrawable {
|
||||
final int insetPx = context.getResources()
|
||||
.getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
|
||||
setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
|
||||
mAdaptiveConstantState = new AdaptiveConstantState(context, foreground);
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Context context, Tile tile) {
|
||||
@@ -85,5 +87,36 @@ public class AdaptiveHomepageIcon extends LayerDrawable {
|
||||
mBackgroundColor = color;
|
||||
getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
Log.d(TAG, "Setting background color " + mBackgroundColor);
|
||||
mAdaptiveConstantState.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstantState getConstantState() {
|
||||
return mAdaptiveConstantState;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static class AdaptiveConstantState extends ConstantState {
|
||||
Context context;
|
||||
Drawable drawable;
|
||||
int color;
|
||||
|
||||
public AdaptiveConstantState(Context context, Drawable drawable) {
|
||||
this.context = context;
|
||||
this.drawable = drawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable newDrawable() {
|
||||
final AdaptiveIcon icon = new AdaptiveIcon(context, drawable);
|
||||
icon.setBackgroundColor(color);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChangingConfigurations() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user