Import updated Android SetupCompat Library 377091999

Copied from google3/third_party/java_src/android_libs/setupcompat

Test: mm
Bug: 189741363

Included changes:
  - 377091999 [BC SUW] Apply primary button style to the "Start Recordi...
  - 376995553 Apply dynamic color P100 on footer button background
  - 376600294 [DynamicColor] Fix when enabling button, the text color c...

PiperOrigin-RevId: 377091999
Change-Id: I8d20ff3cecfd1306e553d5bc4e04f86dc6e8d482
diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
index 85972f5..a0bb65b 100644
--- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
+++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
@@ -103,7 +103,7 @@
           Button button = buttonContainer.findViewById(id);
           if (button != null) {
             button.setEnabled(enabled);
-            if (applyPartnerResources) {
+            if (applyPartnerResources && !applyDynamicColor) {
               updateButtonTextColorWithEnabledState(
                   button,
                   (id == primaryButtonId || isSecondaryButtonInPrimaryStyle)
@@ -358,6 +358,10 @@
 
     onFooterButtonInflated(button, footerBarPrimaryBackgroundColor);
     onFooterButtonApplyPartnerResource(button, footerButtonPartnerConfig);
+    // Sets the primary button background to a light accent color
+    if (applyDynamicColor) {
+      FooterButtonStyleUtils.applyDynamicColorOnPrimaryButton(context, button);
+    }
 
     // Make sure the position of buttons are correctly and prevent primary button create twice or
     // more.
diff --git a/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java b/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java
index 5fd4d96..ca4d56b 100644
--- a/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java
+++ b/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java
@@ -148,12 +148,33 @@
         context, button, footerButtonPartnerConfig.getButtonIconConfig(), isButtonIconAtEnd);
   }
 
+  @TargetApi(VERSION_CODES.S)
+  static void applyDynamicColorOnPrimaryButton(Context context, Button button) {
+    // only update the text color of enable state
+    if (button.isEnabled()) {
+      FooterButtonStyleUtils.updateButtonTextEnabledColor(
+          button, context.getResources().getColor(R.color.suc_system_neutral1_900));
+    }
+    FooterButtonStyleUtils.updateButtonBackgroundTintList(
+        context,
+        button,
+        context.getResources().getColor(R.color.suc_system_accent1_100),
+        /* disabledAlpha=*/ 0f,
+        /* disabledColor=*/ 0);
+    FooterButtonStyleUtils.updateButtonRippleColor(
+        button, context.getResources().getColor(R.color.suc_system_neutral1_900));
+  }
+
   static void updateButtonTextEnabledColorWithPartnerConfig(
       Context context, Button button, PartnerConfig buttonEnableTextColorConfig) {
     @ColorInt
     int color = PartnerConfigHelper.get(context).getColor(context, buttonEnableTextColorConfig);
-    if (color != Color.TRANSPARENT) {
-      button.setTextColor(ColorStateList.valueOf(color));
+    updateButtonTextEnabledColor(button, color);
+  }
+
+  static void updateButtonTextEnabledColor(Button button, @ColorInt int textColor) {
+    if (textColor != Color.TRANSPARENT) {
+      button.setTextColor(ColorStateList.valueOf(textColor));
     }
   }
 
@@ -174,17 +195,27 @@
     Preconditions.checkArgument(
         Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q,
         "Update button background only support on sdk Q or higher");
-    @ColorInt int disabledColor;
-    float disabledAlpha;
-    int[] DISABLED_STATE_SET = {-android.R.attr.state_enabled};
-    int[] ENABLED_STATE_SET = {};
     @ColorInt
     int color = PartnerConfigHelper.get(context).getColor(context, buttonBackgroundConfig);
-    disabledAlpha =
+    float disabledAlpha =
         PartnerConfigHelper.get(context).getFraction(context, buttonDisableAlphaConfig, 0f);
-    disabledColor =
+    @ColorInt
+    int disabledColor =
         PartnerConfigHelper.get(context).getColor(context, buttonDisableBackgroundConfig);
 
+    updateButtonBackgroundTintList(context, button, color, disabledAlpha, disabledColor);
+  }
+
+  @TargetApi(VERSION_CODES.Q)
+  static void updateButtonBackgroundTintList(
+      Context context,
+      Button button,
+      @ColorInt int color,
+      float disabledAlpha,
+      @ColorInt int disabledColor) {
+    int[] DISABLED_STATE_SET = {-android.R.attr.state_enabled};
+    int[] ENABLED_STATE_SET = {};
+
     if (color != Color.TRANSPARENT) {
       if (disabledAlpha <= 0f) {
         // if no partner resource, fallback to theme disable alpha
@@ -247,6 +278,27 @@
     }
   }
 
+  static void updateButtonRippleColor(Button button, @ColorInt int rippleColor) {
+    // RippleDrawable is available after sdk 21. And because on lower sdk the RippleDrawable is
+    // unavailable. Since Stencil customization provider only works on Q+, there is no need to
+    // perform any customization for versions 21.
+    if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+      RippleDrawable rippleDrawable = getRippleDrawable(button);
+      if (rippleDrawable == null) {
+        return;
+      }
+
+      int[] pressedState = {android.R.attr.state_pressed};
+
+      // Set text color for ripple.
+      ColorStateList colorStateList =
+          new ColorStateList(
+              new int[][] {pressedState, StateSet.NOTHING},
+              new int[] {rippleColor, Color.TRANSPARENT});
+      rippleDrawable.setColor(colorStateList);
+    }
+  }
+
   static void updateButtonTextSizeWithPartnerConfig(
       Context context, Button button, PartnerConfig buttonTextSizeConfig) {
     float size = PartnerConfigHelper.get(context).getDimension(context, buttonTextSizeConfig);
@@ -349,6 +401,9 @@
         LayerDrawable layerDrawable = (LayerDrawable) ((InsetDrawable) drawable).getDrawable();
         return (GradientDrawable) layerDrawable.getDrawable(0);
       } else if (drawable instanceof RippleDrawable) {
+        if (((RippleDrawable) drawable).getDrawable(0) instanceof GradientDrawable) {
+          return (GradientDrawable) ((RippleDrawable) drawable).getDrawable(0);
+        }
         InsetDrawable insetDrawable = (InsetDrawable) ((RippleDrawable) drawable).getDrawable(0);
         return (GradientDrawable) insetDrawable.getDrawable();
       }
diff --git a/main/res/values-v31/colors.xml b/main/res/values-v31/colors.xml
new file mode 100644
index 0000000..da7f1e8
--- /dev/null
+++ b/main/res/values-v31/colors.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    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.
+-->
+
+<resources>
+  <color name="suc_system_accent1_100">@android:color/system_accent1_100</color>
+  <color name="suc_system_neutral1_900">@android:color/system_neutral1_900</color>
+</resources>
\ No newline at end of file
diff --git a/main/res/values/colors.xml b/main/res/values/colors.xml
index f472b35..e9f25a5 100644
--- a/main/res/values/colors.xml
+++ b/main/res/values/colors.xml
@@ -23,4 +23,7 @@
 
     <color name="suc_customization_button_highlight_default">#ff1a73e8</color>
 
+    <color name="suc_system_accent1_100">#8DF5E3</color>
+
+    <color name="suc_system_neutral1_900">#1b1b1b</color>
 </resources>
\ No newline at end of file