Import updated Android Setupdesign Library 377192531 am: fdbcc61ac6

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/setupdesign/+/14804132

Change-Id: I5723e2e88af3923e393863141b1198f350f3de82
diff --git a/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java b/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java
index ce6609e..c6b2b2a 100644
--- a/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java
+++ b/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java
@@ -17,7 +17,6 @@
 package com.google.android.setupdesign;
 
 import static com.google.android.setupcompat.partnerconfig.Util.isNightMode;
-import static java.lang.Math.min;
 
 import android.animation.Animator;
 import android.animation.Animator.AnimatorListener;
@@ -396,7 +395,7 @@
           paddingBottom =
               (int) configPaddingBottom
                   - (int)
-                      min(
+                      Math.min(
                           configPaddingBottom,
                           getButtonContainerHeight(footerBarMixin.getButtonContainer()));
         }
@@ -408,8 +407,8 @@
 
   private static final int getButtonContainerHeight(View view) {
     view.measure(
-        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
-        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
+        MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(), MeasureSpec.EXACTLY),
+        MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(), MeasureSpec.EXACTLY));
     return view.getMeasuredHeight();
   }
 
diff --git a/main/res/values-night-v31/colors.xml b/main/res/values-night-v31/colors.xml
index fda7fa0..7aee45c 100644
--- a/main/res/values-night-v31/colors.xml
+++ b/main/res/values-night-v31/colors.xml
@@ -19,9 +19,11 @@
   <!-- Accent color -->
   <color name="sud_dynamic_color_accent_glif_v3">@color/sud_dynamic_color_accent_glif_v3_dark</color>
 
+
   <color name="sud_system_primary_text">@color/sud_system_neutral1_50</color>
   <color name="sud_system_secondary_text">@color/sud_system_neutral2_200</color>
   <color name="sud_system_tertiary_text_inactive">@color/sud_system_neutral2_400</color>
+  <color name="sud_system_error_warning">@color/sud_error_warning_default_dark</color>
   <color name="sud_system_background_surface">@color/sud_system_neutral1_900</color>
   <color name="sud_system_accent_icon_text_button">@color/sud_system_accent1_200</color>
   <color name="sud_system_button_surface">@color/sud_system_accent1_100</color>
diff --git a/main/res/values-night/colors.xml b/main/res/values-night/colors.xml
index b9a0975..1062ea7 100644
--- a/main/res/values-night/colors.xml
+++ b/main/res/values-night/colors.xml
@@ -26,4 +26,6 @@
 
   <color name="sud_portal_pending_progress">@color/sud_portal_pending_progress_dark</color>
 
+
+  <color name="sud_uniformity_backdrop_color">#2A2B2E</color>
 </resources>
\ No newline at end of file
diff --git a/main/res/values-v31/colors.xml b/main/res/values-v31/colors.xml
index b2067c1..c3c6ab5 100644
--- a/main/res/values-v31/colors.xml
+++ b/main/res/values-v31/colors.xml
@@ -28,6 +28,11 @@
   <color name="sud_dynamic_color_accent_glif_v3_light">@color/sud_system_accent1_600</color>
 
 
+  <color name="sud_error_warning_default_dark">#F28B82</color>
+
+  <color name="sud_error_warning_default_light">#EA4335</color>
+
+
 
   <color name="sud_system_accent1_100">@android:color/system_accent1_100</color>
 
@@ -65,6 +70,7 @@
   <color name="sud_system_primary_text">@color/sud_system_neutral1_900</color>
   <color name="sud_system_secondary_text">@color/sud_system_neutral2_700</color>
   <color name="sud_system_tertiary_text_inactive">@color/sud_system_neutral2_500</color>
+  <color name="sud_system_error_warning">@color/sud_error_warning_default_light</color>
   <color name="sud_system_background_surface">@color/sud_system_neutral1_50</color>
   <color name="sud_system_accent_icon_text_button">@color/sud_system_accent1_600</color>
   <color name="sud_system_button_surface">@color/sud_system_accent1_100</color>
diff --git a/main/res/values/colors.xml b/main/res/values/colors.xml
index 7d1acad..7c27547 100644
--- a/main/res/values/colors.xml
+++ b/main/res/values/colors.xml
@@ -128,11 +128,13 @@
 
     <color name="sud_error_warning_default_dark">#EE675C</color>
 
+    <color name="sud_error_warning_default_light">#D93025</color>
+
 
     <color name="sud_system_primary_text">@color/sud_primary_default_text_light</color>
     <color name="sud_system_secondary_text">@color/sud_secondary_default_text_light</color>
     <color name="sud_system_tertiary_text_inactive">@color/sud_inactive_default_light</color>
-    <color name="sud_system_error_warning">@color/sud_color_error_text_light</color>
+    <color name="sud_system_error_warning">@color/sud_error_warning_default_light</color>
     <color name="sud_system_success_done">@color/success_color_device_default_light</color>
     <color name="sud_system_fallback_accent">@color/fallback_color_device_default_light</color>
 
@@ -141,4 +143,7 @@
     <color name="sud_switch_track_off">#FF757575</color>
     <color name="sud_switch_thumb_off">#BFFFFFFF</color>
 
+
+    <color name="sud_uniformity_backdrop_color">@android:color/white</color>
+
 </resources>
diff --git a/main/res/values/dimens.xml b/main/res/values/dimens.xml
index e2d0a94..64970c8 100644
--- a/main/res/values/dimens.xml
+++ b/main/res/values/dimens.xml
@@ -213,4 +213,8 @@
     <!-- Radius of switch track -->
     <dimen name="sud_switch_track_radius">35dp</dimen>
 
+    <!-- IconUniformityAppImageView -->
+    <!-- Set 0dp since we don't want shadow. -->
+    <dimen name="sud_icon_uniformity_elevation">0dp</dimen>
+
 </resources>
diff --git a/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java b/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java
index d681d9f..2541c66 100644
--- a/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java
+++ b/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java
@@ -58,7 +58,6 @@
       case ColorType.ACCENT:
         colorRes = R.color.sud_dynamic_color_accent_glif_v3;
         break;
-        // TODO: Add testcase for getColor attributes.
       case ColorType.PRIMARY_TEXT:
         colorRes = R.color.sud_system_primary_text;
         break;
diff --git a/main/src/com/google/android/setupdesign/view/IconUniformityAppImageView.java b/main/src/com/google/android/setupdesign/view/IconUniformityAppImageView.java
new file mode 100644
index 0000000..9f0e21d
--- /dev/null
+++ b/main/src/com/google/android/setupdesign/view/IconUniformityAppImageView.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2021 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.google.android.setupdesign.view;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.Matrix.ScaleToFit;
+import android.graphics.Outline;
+import android.graphics.RectF;
+import android.graphics.drawable.GradientDrawable;
+import android.os.Build;
+import androidx.annotation.ColorRes;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewOutlineProvider;
+import android.widget.ImageView;
+import androidx.annotation.Nullable;
+import androidx.core.content.ContextCompat;
+import com.google.android.setupdesign.R;
+import com.google.android.setupdesign.widget.CardBackgroundDrawable;
+
+/** An ImageView that displays an app icon according to the icon uniformity spec. */
+public class IconUniformityAppImageView extends ImageView
+    implements IconUniformityAppImageViewBindable {
+  // Scaling factor for inset on each side of legacy icon.
+  private static final Float LEGACY_SIZE_SCALE_FACTOR = 0.75f;
+
+  private static final Float LEGACY_SIZE_SCALE_MARGIN_FACTOR = (1f - LEGACY_SIZE_SCALE_FACTOR) / 2f;
+
+  // Apps & games radius is 20% of icon height.
+  private static final Float APPS_ICON_RADIUS_MULTIPLIER = 0.20f;
+
+  @ColorRes private int backdropColorResId = 0;
+
+  private static final boolean ON_L_PLUS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
+
+  private CardBackgroundDrawable cardBackgroundDrawable;
+  /** Drawable used as background after the actual image data is visible. */
+  private final GradientDrawable backdropDrawable = new GradientDrawable();
+
+  public IconUniformityAppImageView(Context context) {
+    super(context);
+  }
+
+  public IconUniformityAppImageView(Context context, @Nullable AttributeSet attrs) {
+    super(context, attrs);
+  }
+
+  public IconUniformityAppImageView(
+      Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+    super(context, attrs, defStyleAttr);
+  }
+
+  @TargetApi(23)
+  public IconUniformityAppImageView(
+      Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+    super(context, attrs, defStyleAttr, defStyleRes);
+  }
+
+  @Override
+  protected void onFinishInflate() {
+    super.onFinishInflate();
+    backdropColorResId = R.color.sud_uniformity_backdrop_color;
+    backdropDrawable.setColor(ContextCompat.getColor(getContext(), backdropColorResId));
+  }
+
+  @Override
+  public void bindView(IconUniformityAppImageViewData viewData) {
+    if (Build.VERSION.SDK_INT <= 17) {
+      // clipPath is not supported on hardware accelerated canvas so won't take effect unless we
+      // manually set to software.
+      setLayerType(LAYER_TYPE_SOFTWARE, /* paint= */ null);
+    }
+
+    setLegacyTransformationMatrix(
+        viewData.icon.getMinimumWidth(),
+        viewData.icon.getMinimumHeight(),
+        getLayoutParams().width,
+        getLayoutParams().height);
+
+    float radius = getLayoutParams().height * APPS_ICON_RADIUS_MULTIPLIER;
+
+    if (ON_L_PLUS) {
+      setBackgroundColor(ContextCompat.getColor(getContext(), backdropColorResId));
+      backdropDrawable.setCornerRadius(radius);
+      setElevation(getContext().getResources().getDimension(R.dimen.sud_icon_uniformity_elevation));
+      setClipToOutline(true);
+      setOutlineProvider(
+          new ViewOutlineProvider() {
+            @Override
+            public void getOutline(View view, Outline outline) {
+              outline.setRoundRect(
+                  /* left= */ 0,
+                  /* top= */ 0,
+                  /* right= */ getLayoutParams().width,
+                  /* bottom= */ getLayoutParams().height,
+                  /* radius= */ radius);
+            }
+          });
+    } else {
+      cardBackgroundDrawable =
+          new CardBackgroundDrawable(
+              ContextCompat.getColor(getContext(), backdropColorResId),
+              /* radius= */ radius,
+              /* inset= */ 0f);
+      cardBackgroundDrawable.setBounds(
+          /* left= */ 0,
+          /* top= */ 0,
+          /* right= */ getLayoutParams().width,
+          /* bottom= */ getLayoutParams().height);
+    }
+
+    setImageDrawable(viewData.icon);
+  }
+
+  @Override
+  public void onRecycle() {
+    setImageDrawable(null);
+  }
+
+  @Override
+  protected void onDraw(Canvas canvas) {
+    super.onDraw(canvas);
+    if (!ON_L_PLUS && cardBackgroundDrawable != null) {
+      cardBackgroundDrawable.draw(canvas);
+    }
+    super.onDraw(canvas);
+  }
+
+  private void setLegacyTransformationMatrix(
+      float drawableWidth, float drawableHeight, float imageViewWidth, float imageViewHeight) {
+    Matrix scaleMatrix = new Matrix();
+    float verticalMargin = imageViewHeight * LEGACY_SIZE_SCALE_MARGIN_FACTOR;
+    float horizontalMargin = imageViewWidth * LEGACY_SIZE_SCALE_MARGIN_FACTOR;
+    RectF scrRectF = new RectF(0f, 0f, drawableWidth, drawableHeight);
+    RectF destRectF =
+        new RectF(
+            horizontalMargin,
+            verticalMargin,
+            imageViewWidth - horizontalMargin,
+            imageViewHeight - verticalMargin);
+
+    scaleMatrix.setRectToRect(scrRectF, destRectF, ScaleToFit.FILL);
+
+    setScaleType(ScaleType.MATRIX);
+    setImageMatrix(scaleMatrix);
+  }
+}
diff --git a/main/src/com/google/android/setupdesign/view/IconUniformityAppImageViewBindable.java b/main/src/com/google/android/setupdesign/view/IconUniformityAppImageViewBindable.java
new file mode 100644
index 0000000..1eab81b
--- /dev/null
+++ b/main/src/com/google/android/setupdesign/view/IconUniformityAppImageViewBindable.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2021 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.google.android.setupdesign.view;
+
+import android.graphics.drawable.Drawable;
+
+/** ViewBindable for [IconUniformityAppImageView] */
+public interface IconUniformityAppImageViewBindable {
+
+  /** Data for [IconUniformityAppImageView] */
+  class IconUniformityAppImageViewData {
+    public Drawable icon;
+
+    public IconUniformityAppImageViewData(Drawable icon) {
+      this.icon = icon;
+    }
+  }
+
+  void bindView(IconUniformityAppImageViewData viewData);
+
+  void onRecycle();
+}
diff --git a/main/src/com/google/android/setupdesign/widget/CardBackgroundDrawable.java b/main/src/com/google/android/setupdesign/widget/CardBackgroundDrawable.java
new file mode 100644
index 0000000..b354921
--- /dev/null
+++ b/main/src/com/google/android/setupdesign/widget/CardBackgroundDrawable.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2021 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.google.android.setupdesign.widget;
+
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.Path.Direction;
+import android.graphics.Path.FillType;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import androidx.annotation.ColorInt;
+import androidx.annotation.Nullable;
+
+/** A rounded rectangle drawable. */
+public class CardBackgroundDrawable extends Drawable {
+  private final float inset;
+
+  private final Paint paint;
+  private final RectF cardBounds = new RectF();
+  private final Path clipPath = new Path();
+
+  private float cornerRadius;
+  private boolean dirty = false;
+
+  /**
+   * @param color Background color of the card to be rendered
+   * @param radius Corner rounding radius
+   * @param inset Inset from the edge of the canvas to the card
+   */
+  public CardBackgroundDrawable(@ColorInt int color, float radius, float inset) {
+    cornerRadius = radius;
+    paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
+    paint.setColor(color);
+    this.inset = inset;
+  }
+
+  @Override
+  public void onBoundsChange(Rect bounds) {
+    super.onBoundsChange(bounds);
+    dirty = true;
+  }
+
+  @Override
+  public void setColorFilter(@Nullable ColorFilter cf) {
+    paint.setColorFilter(cf);
+  }
+
+  @Override
+  public int getOpacity() {
+    return PixelFormat.OPAQUE;
+  }
+
+  public void setCornerRadius(float radius) {
+    if (cornerRadius == radius) {
+      return;
+    }
+
+    cornerRadius = radius;
+    dirty = true;
+    invalidateSelf();
+  }
+
+  @Override
+  public void draw(Canvas canvas) {
+    if (dirty) {
+      buildComponents(getBounds());
+      dirty = false;
+    }
+
+    if (cornerRadius > 0) {
+      canvas.clipPath(clipPath);
+    }
+  }
+
+  @Override
+  public void setAlpha(int alpha) {}
+
+  private void buildComponents(Rect bounds) {
+    cardBounds.set(bounds);
+    cardBounds.inset(inset, inset);
+
+    clipPath.reset();
+    clipPath.setFillType(FillType.EVEN_ODD);
+    clipPath.addRoundRect(cardBounds, cornerRadius, cornerRadius, Direction.CW);
+  }
+}