Loading packages/SettingsLib/AdaptiveIcon/res/values/colors.xml +4 −0 Original line number Diff line number Diff line Loading @@ -18,4 +18,8 @@ <color name="homepage_generic_icon_background">#1A73E8</color> <color name="bt_outline_color">#1f000000</color> <!-- icon outline color --> <color name="advanced_outline_color">#BDC1C6</color> <!-- icon outline color --> <color name="advanced_icon_color">#3C4043</color> </resources> packages/SettingsLib/AdaptiveIcon/res/values/dimens.xml +2 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ <resources> <!-- Dashboard foreground image inset (from background edge to foreground edge) --> <dimen name="dashboard_tile_foreground_image_inset">6dp</dimen> <!-- Advanced dashboard foreground image inset (from background edge to foreground edge) --> <dimen name="advanced_dashboard_tile_foreground_image_inset">9dp</dimen> <!-- Stroke size of adaptive outline --> <dimen name="adaptive_outline_stroke">1dp</dimen> Loading packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveOutlineDrawable.java +72 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package com.android.settingslib.widget; import static com.android.settingslib.widget.AdaptiveOutlineDrawable.AdaptiveOutlineIconType.TYPE_ADVANCED; import static com.android.settingslib.widget.AdaptiveOutlineDrawable.AdaptiveOutlineIconType.TYPE_DEFAULT; import android.annotation.ColorInt; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; Loading @@ -27,35 +31,90 @@ import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.DrawableWrapper; import android.util.PathParser; import androidx.annotation.IntDef; import androidx.annotation.VisibleForTesting; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * Adaptive outline drawable with white plain background color and black outline */ public class AdaptiveOutlineDrawable extends DrawableWrapper { @Retention(RetentionPolicy.SOURCE) @IntDef({TYPE_DEFAULT, TYPE_ADVANCED}) public @interface AdaptiveOutlineIconType { int TYPE_DEFAULT = 0; int TYPE_ADVANCED = 1; } @VisibleForTesting final Paint mOutlinePaint; Paint mOutlinePaint; private Path mPath; private final int mInsetPx; private final Bitmap mBitmap; private int mInsetPx; private int mStrokeWidth; private Bitmap mBitmap; private int mType; public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap) { super(new AdaptiveIconShapeDrawable(resources)); init(resources, bitmap, TYPE_DEFAULT); } public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap, @AdaptiveOutlineIconType int type) { super(new AdaptiveIconShapeDrawable(resources)); init(resources, bitmap, type); } private void init(Resources resources, Bitmap bitmap, @AdaptiveOutlineIconType int type) { mType = type; getDrawable().setTint(Color.WHITE); mPath = new Path(PathParser.createPathFromPathData( resources.getString(com.android.internal.R.string.config_icon_mask))); mStrokeWidth = resources.getDimensionPixelSize(R.dimen.adaptive_outline_stroke); mOutlinePaint = new Paint(); mOutlinePaint.setColor(resources.getColor(R.color.bt_outline_color, null)); mOutlinePaint.setColor(getColor(resources, type)); mOutlinePaint.setStyle(Paint.Style.STROKE); mOutlinePaint.setStrokeWidth(resources.getDimension(R.dimen.adaptive_outline_stroke)); mOutlinePaint.setStrokeWidth(mStrokeWidth); mOutlinePaint.setAntiAlias(true); mInsetPx = resources .getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset); mInsetPx = getDimensionPixelSize(resources, type); mBitmap = bitmap; } private @ColorInt int getColor(Resources resources, @AdaptiveOutlineIconType int type) { int resId; switch (type) { case TYPE_ADVANCED: resId = R.color.advanced_outline_color; break; case TYPE_DEFAULT: default: resId = R.color.bt_outline_color; break; } return resources.getColor(resId, /* theme */ null); } private int getDimensionPixelSize(Resources resources, @AdaptiveOutlineIconType int type) { int resId; switch (type) { case TYPE_ADVANCED: resId = R.dimen.advanced_dashboard_tile_foreground_image_inset; break; case TYPE_DEFAULT: default: resId = R.dimen.dashboard_tile_foreground_image_inset; break; } return resources.getDimensionPixelSize(resId); } @Override public void draw(Canvas canvas) { super.draw(canvas); Loading @@ -68,7 +127,12 @@ public class AdaptiveOutlineDrawable extends DrawableWrapper { final int count = canvas.save(); canvas.scale(scaleX, scaleY); // Draw outline if (mType == TYPE_DEFAULT) { canvas.drawPath(mPath, mOutlinePaint); } else { canvas.drawCircle(2 * mInsetPx, 2 * mInsetPx, 2 * mInsetPx - mStrokeWidth, mOutlinePaint); } canvas.restoreToCount(count); // Draw the foreground icon Loading packages/SettingsLib/res/values/dimens.xml +3 −0 Original line number Diff line number Diff line Loading @@ -94,4 +94,7 @@ <!-- Define minimal size of the tap area --> <dimen name="min_tap_target_size">48dp</dimen> <!-- Size of advanced icon --> <dimen name="advanced_icon_size">18dp</dimen> </resources> packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +43 −0 Original line number Diff line number Diff line package com.android.settingslib.bluetooth; import static com.android.settingslib.widget.AdaptiveOutlineDrawable.AdaptiveOutlineIconType.TYPE_ADVANCED; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; Loading @@ -7,6 +9,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; Loading Loading @@ -212,6 +215,46 @@ public class BluetoothUtils { return new Pair<>(pair.first, pair.second); } /** * Build device icon with advanced outline */ public static Drawable buildAdvancedDrawable(Context context, Drawable drawable) { final int iconSize = context.getResources().getDimensionPixelSize( R.dimen.advanced_icon_size); final Resources resources = context.getResources(); Bitmap bitmap = null; if (drawable instanceof BitmapDrawable) { bitmap = ((BitmapDrawable) drawable).getBitmap(); } else { final int width = drawable.getIntrinsicWidth(); final int height = drawable.getIntrinsicHeight(); bitmap = createBitmap(drawable, width > 0 ? width : 1, height > 0 ? height : 1); } if (bitmap != null) { final Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, false); bitmap.recycle(); return new AdaptiveOutlineDrawable(resources, resizedBitmap, TYPE_ADVANCED); } return drawable; } /** * Creates a drawable with specified width and height. */ public static Bitmap createBitmap(Drawable drawable, int width, int height) { final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } /** * Get boolean Bluetooth metadata * Loading Loading
packages/SettingsLib/AdaptiveIcon/res/values/colors.xml +4 −0 Original line number Diff line number Diff line Loading @@ -18,4 +18,8 @@ <color name="homepage_generic_icon_background">#1A73E8</color> <color name="bt_outline_color">#1f000000</color> <!-- icon outline color --> <color name="advanced_outline_color">#BDC1C6</color> <!-- icon outline color --> <color name="advanced_icon_color">#3C4043</color> </resources>
packages/SettingsLib/AdaptiveIcon/res/values/dimens.xml +2 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ <resources> <!-- Dashboard foreground image inset (from background edge to foreground edge) --> <dimen name="dashboard_tile_foreground_image_inset">6dp</dimen> <!-- Advanced dashboard foreground image inset (from background edge to foreground edge) --> <dimen name="advanced_dashboard_tile_foreground_image_inset">9dp</dimen> <!-- Stroke size of adaptive outline --> <dimen name="adaptive_outline_stroke">1dp</dimen> Loading
packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveOutlineDrawable.java +72 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package com.android.settingslib.widget; import static com.android.settingslib.widget.AdaptiveOutlineDrawable.AdaptiveOutlineIconType.TYPE_ADVANCED; import static com.android.settingslib.widget.AdaptiveOutlineDrawable.AdaptiveOutlineIconType.TYPE_DEFAULT; import android.annotation.ColorInt; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; Loading @@ -27,35 +31,90 @@ import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.DrawableWrapper; import android.util.PathParser; import androidx.annotation.IntDef; import androidx.annotation.VisibleForTesting; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * Adaptive outline drawable with white plain background color and black outline */ public class AdaptiveOutlineDrawable extends DrawableWrapper { @Retention(RetentionPolicy.SOURCE) @IntDef({TYPE_DEFAULT, TYPE_ADVANCED}) public @interface AdaptiveOutlineIconType { int TYPE_DEFAULT = 0; int TYPE_ADVANCED = 1; } @VisibleForTesting final Paint mOutlinePaint; Paint mOutlinePaint; private Path mPath; private final int mInsetPx; private final Bitmap mBitmap; private int mInsetPx; private int mStrokeWidth; private Bitmap mBitmap; private int mType; public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap) { super(new AdaptiveIconShapeDrawable(resources)); init(resources, bitmap, TYPE_DEFAULT); } public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap, @AdaptiveOutlineIconType int type) { super(new AdaptiveIconShapeDrawable(resources)); init(resources, bitmap, type); } private void init(Resources resources, Bitmap bitmap, @AdaptiveOutlineIconType int type) { mType = type; getDrawable().setTint(Color.WHITE); mPath = new Path(PathParser.createPathFromPathData( resources.getString(com.android.internal.R.string.config_icon_mask))); mStrokeWidth = resources.getDimensionPixelSize(R.dimen.adaptive_outline_stroke); mOutlinePaint = new Paint(); mOutlinePaint.setColor(resources.getColor(R.color.bt_outline_color, null)); mOutlinePaint.setColor(getColor(resources, type)); mOutlinePaint.setStyle(Paint.Style.STROKE); mOutlinePaint.setStrokeWidth(resources.getDimension(R.dimen.adaptive_outline_stroke)); mOutlinePaint.setStrokeWidth(mStrokeWidth); mOutlinePaint.setAntiAlias(true); mInsetPx = resources .getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset); mInsetPx = getDimensionPixelSize(resources, type); mBitmap = bitmap; } private @ColorInt int getColor(Resources resources, @AdaptiveOutlineIconType int type) { int resId; switch (type) { case TYPE_ADVANCED: resId = R.color.advanced_outline_color; break; case TYPE_DEFAULT: default: resId = R.color.bt_outline_color; break; } return resources.getColor(resId, /* theme */ null); } private int getDimensionPixelSize(Resources resources, @AdaptiveOutlineIconType int type) { int resId; switch (type) { case TYPE_ADVANCED: resId = R.dimen.advanced_dashboard_tile_foreground_image_inset; break; case TYPE_DEFAULT: default: resId = R.dimen.dashboard_tile_foreground_image_inset; break; } return resources.getDimensionPixelSize(resId); } @Override public void draw(Canvas canvas) { super.draw(canvas); Loading @@ -68,7 +127,12 @@ public class AdaptiveOutlineDrawable extends DrawableWrapper { final int count = canvas.save(); canvas.scale(scaleX, scaleY); // Draw outline if (mType == TYPE_DEFAULT) { canvas.drawPath(mPath, mOutlinePaint); } else { canvas.drawCircle(2 * mInsetPx, 2 * mInsetPx, 2 * mInsetPx - mStrokeWidth, mOutlinePaint); } canvas.restoreToCount(count); // Draw the foreground icon Loading
packages/SettingsLib/res/values/dimens.xml +3 −0 Original line number Diff line number Diff line Loading @@ -94,4 +94,7 @@ <!-- Define minimal size of the tap area --> <dimen name="min_tap_target_size">48dp</dimen> <!-- Size of advanced icon --> <dimen name="advanced_icon_size">18dp</dimen> </resources>
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +43 −0 Original line number Diff line number Diff line package com.android.settingslib.bluetooth; import static com.android.settingslib.widget.AdaptiveOutlineDrawable.AdaptiveOutlineIconType.TYPE_ADVANCED; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; Loading @@ -7,6 +9,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; Loading Loading @@ -212,6 +215,46 @@ public class BluetoothUtils { return new Pair<>(pair.first, pair.second); } /** * Build device icon with advanced outline */ public static Drawable buildAdvancedDrawable(Context context, Drawable drawable) { final int iconSize = context.getResources().getDimensionPixelSize( R.dimen.advanced_icon_size); final Resources resources = context.getResources(); Bitmap bitmap = null; if (drawable instanceof BitmapDrawable) { bitmap = ((BitmapDrawable) drawable).getBitmap(); } else { final int width = drawable.getIntrinsicWidth(); final int height = drawable.getIntrinsicHeight(); bitmap = createBitmap(drawable, width > 0 ? width : 1, height > 0 ? height : 1); } if (bitmap != null) { final Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, false); bitmap.recycle(); return new AdaptiveOutlineDrawable(resources, resizedBitmap, TYPE_ADVANCED); } return drawable; } /** * Creates a drawable with specified width and height. */ public static Bitmap createBitmap(Drawable drawable, int width, int height) { final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } /** * Get boolean Bluetooth metadata * Loading