Changes to icon picker for reusability in "add mode" flow

* Don't finish the fragment from the controller (ugh!) instead just report the selected icon via a listener.
* Highlight the selected icon in the list.
* Cache the icon drawables (since we're using selectors for the colors, we don't need to swap them, one per icon resource id is enough).
* Improved the tests a bit too.

Bug: 333901673
Bug: 326442408
Test: ates
Flag: android.app.modes_ui
Change-Id: Ib2ec7a7e3ed99b13f9264aa6f7c209ee3f6967a0
This commit is contained in:
Matías Hernández
2024-06-25 20:29:14 +02:00
parent 67d977b72e
commit c2d2de085d
9 changed files with 190 additions and 67 deletions

View File

@@ -50,14 +50,16 @@ class IconUtil {
/**
* Returns a variant of the supplied {@code icon} to be used in the icon picker. The inner icon
* is 36x36dp and it's contained into a circle of diameter 54dp.
* is 36x36dp and it's contained into a circle of diameter 54dp. It's also set up so that
* selection and pressed states are represented in the color.
*/
static Drawable makeIconCircle(@NonNull Context context, @NonNull Drawable icon) {
ShapeDrawable background = new ShapeDrawable(new OvalShape());
background.getPaint().setColor(Utils.getColorAttrDefaultColor(context,
com.android.internal.R.attr.materialColorSecondaryContainer));
icon.setTint(Utils.getColorAttrDefaultColor(context,
com.android.internal.R.attr.materialColorOnSecondaryContainer));
background.setTintList(
context.getColorStateList(R.color.modes_icon_picker_item_background));
icon = icon.mutate();
icon.setTintList(
context.getColorStateList(R.color.modes_icon_picker_item_icon));
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, icon });