Add fp icon with background shape

Fixes: 126425211
Test: RunSettingsRoboTests

Change-Id: I779f76f597b80d73b6dd6eb9e43a96abc9fee0bb
This commit is contained in:
jackqdyulei
2019-03-19 10:18:19 -07:00
parent b4ae464e99
commit 36ce63dcb5
9 changed files with 221 additions and 2 deletions

View File

@@ -80,8 +80,10 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
@Override
protected void refresh() {
setHeaderProperties();
mHeaderController.done(mFragment.getActivity(), true /* rebindActions */);
if (isAvailable()) {
setHeaderProperties();
mHeaderController.done(mFragment.getActivity(), true /* rebindActions */);
}
}
@Override

View File

@@ -164,6 +164,8 @@ public final class BluetoothDevicePreference extends GearPreference implements
final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
if (imageView != null) {
imageView.setContentDescription(contentDescription);
imageView.setElevation(
getContext().getResources().getDimension(R.dimen.bt_icon_elevation));
}
super.onBindViewHolder(view);
}

View File

@@ -22,8 +22,11 @@ import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.MediaStore;
import android.provider.Settings;
import android.util.Log;
import android.util.Pair;
@@ -33,14 +36,18 @@ import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.AdaptiveIcon;
import com.android.settings.widget.AdaptiveOutlineDrawable;
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;
import java.io.IOException;
/**
* Utils is a helper class that contains constants for various
* Android resource IDs, debug logging flags, and static methods
@@ -165,6 +172,7 @@ public final class Utils {
if (bluetoothDevice == null) {
return false;
}
return Boolean.parseBoolean(bluetoothDevice.getMetadata(key));
}
@@ -193,7 +201,36 @@ public final class Utils {
CachedBluetoothDevice cachedDevice) {
final Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
context, cachedDevice);
final boolean untetheredHeadset = Utils.getBooleanMetaData(cachedDevice.getDevice(),
BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET);
final int iconSize = context.getResources().getDimensionPixelSize(
R.dimen.bt_nearby_icon_size);
final Resources resources = context.getResources();
// Deal with untethered headset
if (untetheredHeadset) {
final String uriString = Utils.getStringMetaData(cachedDevice.getDevice(),
BluetoothDevice.METADATA_MAIN_ICON);
final Uri iconUri = uriString != null ? Uri.parse(uriString) : null;
if (iconUri != null) {
try {
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(
context.getContentResolver(), iconUri);
if (bitmap != null) {
final Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, iconSize,
iconSize, false);
bitmap.recycle();
final AdaptiveOutlineDrawable drawable = new AdaptiveOutlineDrawable(
resources, resizedBitmap);
return new Pair<>(drawable, pair.second);
}
} catch (IOException e) {
Log.e(TAG, "Failed to get drawable for: " + iconUri, e);
}
}
}
// 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);

View File

@@ -0,0 +1,90 @@
/*
* 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.
*/
package com.android.settings.widget;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.DrawableWrapper;
import android.util.PathParser;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
/**
* Adaptive outline drawable with white plain background color and black outline
*/
public class AdaptiveOutlineDrawable extends DrawableWrapper {
@VisibleForTesting
final Paint mOutlinePaint;
private Path mPath;
private final int mInsetPx;
private final Bitmap mBitmap;
public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap) {
super(new AdaptiveIconShapeDrawable(resources));
getDrawable().setTint(Color.WHITE);
mPath = new Path(PathParser.createPathFromPathData(
resources.getString(com.android.internal.R.string.config_icon_mask)));
mOutlinePaint = new Paint();
mOutlinePaint.setColor(resources.getColor(R.color.bt_outline_color, null));
mOutlinePaint.setStyle(Paint.Style.STROKE);
mOutlinePaint.setStrokeWidth(resources.getDimension(R.dimen.adaptive_outline_stroke));
mOutlinePaint.setAntiAlias(true);
mInsetPx = resources
.getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
mBitmap = bitmap;
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
final Rect bounds = getBounds();
final float pathSize = AdaptiveIconDrawable.MASK_SIZE;
final float scaleX = (bounds.right - bounds.left) / pathSize;
final float scaleY = (bounds.bottom - bounds.top) / pathSize;
final int count = canvas.save();
canvas.scale(scaleX, scaleY);
// Draw outline
canvas.drawPath(mPath, mOutlinePaint);
canvas.restoreToCount(count);
// Draw the foreground icon
canvas.drawBitmap(mBitmap, bounds.left + mInsetPx, bounds.top + mInsetPx, null);
}
@Override
public int getIntrinsicHeight() {
return mBitmap.getHeight() + 2 * mInsetPx;
}
@Override
public int getIntrinsicWidth() {
return mBitmap.getWidth() + 2 * mInsetPx;
}
}