Import updated Android SetupCompat Library 375009299 am: e42bc8b1af

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

Change-Id: I053d6c010bd6f5f80b93ed0cd56f7071a5d404e0
diff --git a/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java b/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java
index 08d76e9..5f8bf67 100644
--- a/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java
+++ b/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java
@@ -128,8 +128,10 @@
 
     public Builder(FooterButton footerButton) {
       this.footerButton = footerButton;
-      // default partnerTheme should be the same as footerButton.getTheme();
-      this.partnerTheme = this.footerButton.getTheme();
+      if (this.footerButton != null) {
+        // default partnerTheme should be the same as footerButton.getTheme();
+        this.partnerTheme = this.footerButton.getTheme();
+      }
     }
 
     public Builder setButtonBackgroundConfig(PartnerConfig buttonBackgroundConfig) {
diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
index 8f807e6..85972f5 100644
--- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
+++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
@@ -104,7 +104,7 @@
           if (button != null) {
             button.setEnabled(enabled);
             if (applyPartnerResources) {
-              updateButtonTextColorWithPartnerConfig(
+              updateButtonTextColorWithEnabledState(
                   button,
                   (id == primaryButtonId || isSecondaryButtonInPrimaryStyle)
                       ? PartnerConfig.CONFIG_FOOTER_PRIMARY_BUTTON_TEXT_COLOR
@@ -608,41 +608,20 @@
     if (!applyPartnerResources) {
       return;
     }
-
-    // If dynamic color enabled, these colors won't be overrode by partner config.
-    // Instead, these colors align with the current theme colors.
+    FooterButtonStyleUtils.applyButtonPartnerResources(
+        context,
+        button,
+        applyDynamicColor,
+        /* isButtonIconAtEnd= */ (button.getId() == primaryButtonId),
+        footerButtonPartnerConfig);
     if (!applyDynamicColor) {
-      updateButtonTextColorWithPartnerConfig(
+      // adjust text color based on enabled state
+      updateButtonTextColorWithEnabledState(
           button, footerButtonPartnerConfig.getButtonTextColorConfig());
-      FooterButtonStyleUtils.updateButtonBackgroundWithPartnerConfig(
-          context,
-          button,
-          footerButtonPartnerConfig.getButtonBackgroundConfig(),
-          footerButtonPartnerConfig.getButtonDisableAlphaConfig(),
-          footerButtonPartnerConfig.getButtonDisableBackgroundConfig());
-      FooterButtonStyleUtils.updateButtonRippleColorWithPartnerConfig(
-          context, button, footerButtonPartnerConfig);
     }
-
-    FooterButtonStyleUtils.updateButtonTextSizeWithPartnerConfig(
-        context, button, footerButtonPartnerConfig.getButtonTextSizeConfig());
-    FooterButtonStyleUtils.updateButtonMinHeightWithPartnerConfig(
-        context, button, footerButtonPartnerConfig.getButtonMinHeightConfig());
-    FooterButtonStyleUtils.updateButtonTypeFaceWithPartnerConfig(
-        context,
-        button,
-        footerButtonPartnerConfig.getButtonTextTypeFaceConfig(),
-        footerButtonPartnerConfig.getButtonTextStyleConfig());
-    FooterButtonStyleUtils.updateButtonRadiusWithPartnerConfig(
-        context, button, footerButtonPartnerConfig.getButtonRadiusConfig());
-    FooterButtonStyleUtils.updateButtonIconWithPartnerConfig(
-        context,
-        button,
-        footerButtonPartnerConfig.getButtonIconConfig(),
-        primaryButtonId == button.getId());
   }
 
-  private void updateButtonTextColorWithPartnerConfig(
+  private void updateButtonTextColorWithEnabledState(
       Button button, PartnerConfig buttonTextColorConfig) {
     if (button.isEnabled()) {
       FooterButtonStyleUtils.updateButtonTextEnabledColorWithPartnerConfig(
diff --git a/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java b/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java
index 98a1426..5fd4d96 100644
--- a/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java
+++ b/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java
@@ -35,6 +35,7 @@
 import android.widget.Button;
 import androidx.annotation.ColorInt;
 import androidx.annotation.VisibleForTesting;
+import com.google.android.setupcompat.R;
 import com.google.android.setupcompat.internal.FooterButtonPartnerConfig;
 import com.google.android.setupcompat.internal.Preconditions;
 import com.google.android.setupcompat.partnerconfig.PartnerConfig;
@@ -44,6 +45,109 @@
 public class FooterButtonStyleUtils {
   private static final float DEFAULT_DISABLED_ALPHA = 0.26f;
 
+  /** Apply the partner primary button style to given {@code button}. */
+  public static void applyPrimaryButtonPartnerResource(
+      Context context, Button button, boolean applyDynamicColor) {
+
+    FooterButtonPartnerConfig footerButtonPartnerConfig =
+        new FooterButtonPartnerConfig.Builder(null)
+            .setPartnerTheme(R.style.SucPartnerCustomizationButton_Primary)
+            .setButtonBackgroundConfig(PartnerConfig.CONFIG_FOOTER_PRIMARY_BUTTON_BG_COLOR)
+            .setButtonDisableAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_ALPHA)
+            .setButtonDisableBackgroundConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_BG_COLOR)
+            .setButtonRadiusConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RADIUS)
+            .setButtonRippleColorAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RIPPLE_COLOR_ALPHA)
+            .setTextColorConfig(PartnerConfig.CONFIG_FOOTER_PRIMARY_BUTTON_TEXT_COLOR)
+            .setTextSizeConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_TEXT_SIZE)
+            .setButtonMinHeight(PartnerConfig.CONFIG_FOOTER_BUTTON_MIN_HEIGHT)
+            .setTextTypeFaceConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_FONT_FAMILY)
+            .setTextStyleConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_TEXT_STYLE)
+            .build();
+    applyButtonPartnerResources(
+        context,
+        button,
+        applyDynamicColor,
+        /* isButtonIconAtEnd= */ true,
+        footerButtonPartnerConfig);
+  }
+
+  /** Apply the partner secondary button style to given {@code button}. */
+  public static void applySecondaryButtonPartnerResource(
+      Context context, Button button, boolean applyDynamicColor) {
+
+    int defaultTheme = R.style.SucPartnerCustomizationButton_Secondary;
+    int color =
+        PartnerConfigHelper.get(context)
+            .getColor(context, PartnerConfig.CONFIG_FOOTER_SECONDARY_BUTTON_BG_COLOR);
+    if (color != Color.TRANSPARENT) {
+      defaultTheme = R.style.SucPartnerCustomizationButton_Primary;
+    }
+    // Setup button partner config
+    FooterButtonPartnerConfig footerButtonPartnerConfig =
+        new FooterButtonPartnerConfig.Builder(null)
+            .setPartnerTheme(defaultTheme)
+            .setButtonBackgroundConfig(PartnerConfig.CONFIG_FOOTER_SECONDARY_BUTTON_BG_COLOR)
+            .setButtonDisableAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_ALPHA)
+            .setButtonDisableBackgroundConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_BG_COLOR)
+            .setButtonRadiusConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RADIUS)
+            .setButtonRippleColorAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RIPPLE_COLOR_ALPHA)
+            .setTextColorConfig(PartnerConfig.CONFIG_FOOTER_SECONDARY_BUTTON_TEXT_COLOR)
+            .setTextSizeConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_TEXT_SIZE)
+            .setButtonMinHeight(PartnerConfig.CONFIG_FOOTER_BUTTON_MIN_HEIGHT)
+            .setTextTypeFaceConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_FONT_FAMILY)
+            .setTextStyleConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_TEXT_STYLE)
+            .build();
+    applyButtonPartnerResources(
+        context,
+        button,
+        applyDynamicColor,
+        /* isButtonIconAtEnd= */ false,
+        footerButtonPartnerConfig);
+  }
+
+  static void applyButtonPartnerResources(
+      Context context,
+      Button button,
+      boolean applyDynamicColor,
+      boolean isButtonIconAtEnd,
+      FooterButtonPartnerConfig footerButtonPartnerConfig) {
+
+    // If dynamic color enabled, these colors won't be overrode by partner config.
+    // Instead, these colors align with the current theme colors.
+    if (!applyDynamicColor) {
+      // use default disable color util we support the partner disable text color
+      if (button.isEnabled()) {
+        FooterButtonStyleUtils.updateButtonTextEnabledColorWithPartnerConfig(
+            context, button, footerButtonPartnerConfig.getButtonTextColorConfig());
+      }
+      FooterButtonStyleUtils.updateButtonBackgroundWithPartnerConfig(
+          context,
+          button,
+          footerButtonPartnerConfig.getButtonBackgroundConfig(),
+          footerButtonPartnerConfig.getButtonDisableAlphaConfig(),
+          footerButtonPartnerConfig.getButtonDisableBackgroundConfig());
+      FooterButtonStyleUtils.updateButtonRippleColorWithPartnerConfig(
+          context,
+          button,
+          footerButtonPartnerConfig.getButtonTextColorConfig(),
+          footerButtonPartnerConfig.getButtonRippleColorAlphaConfig());
+    }
+
+    FooterButtonStyleUtils.updateButtonTextSizeWithPartnerConfig(
+        context, button, footerButtonPartnerConfig.getButtonTextSizeConfig());
+    FooterButtonStyleUtils.updateButtonMinHeightWithPartnerConfig(
+        context, button, footerButtonPartnerConfig.getButtonMinHeightConfig());
+    FooterButtonStyleUtils.updateButtonTypeFaceWithPartnerConfig(
+        context,
+        button,
+        footerButtonPartnerConfig.getButtonTextTypeFaceConfig(),
+        footerButtonPartnerConfig.getButtonTextStyleConfig());
+    FooterButtonStyleUtils.updateButtonRadiusWithPartnerConfig(
+        context, button, footerButtonPartnerConfig.getButtonRadiusConfig());
+    FooterButtonStyleUtils.updateButtonIconWithPartnerConfig(
+        context, button, footerButtonPartnerConfig.getButtonIconConfig(), isButtonIconAtEnd);
+  }
+
   static void updateButtonTextEnabledColorWithPartnerConfig(
       Context context, Button button, PartnerConfig buttonEnableTextColorConfig) {
     @ColorInt
@@ -53,11 +157,11 @@
     }
   }
 
-  static void updateButtonTextDisableColor(Button button, ColorStateList defaultTextColor) {
+  static void updateButtonTextDisableColor(Button button, ColorStateList disabledTextColor) {
     // TODO : add disable footer button text color partner config
 
     // disable state will use the default disable state color
-    button.setTextColor(defaultTextColor);
+    button.setTextColor(disabledTextColor);
   }
 
   @TargetApi(VERSION_CODES.Q)
@@ -113,7 +217,10 @@
   }
 
   static void updateButtonRippleColorWithPartnerConfig(
-      Context context, Button button, FooterButtonPartnerConfig footerButtonPartnerConfig) {
+      Context context,
+      Button button,
+      PartnerConfig buttonTextColorConfig,
+      PartnerConfig buttonRippleColorAlphaConfig) {
     // 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.
@@ -126,13 +233,10 @@
       int[] pressedState = {android.R.attr.state_pressed};
       // Get partner text color.
       @ColorInt
-      int color =
-          PartnerConfigHelper.get(context)
-              .getColor(context, footerButtonPartnerConfig.getButtonTextColorConfig());
+      int color = PartnerConfigHelper.get(context).getColor(context, buttonTextColorConfig);
 
       float alpha =
-          PartnerConfigHelper.get(context)
-              .getFraction(context, footerButtonPartnerConfig.getButtonRippleColorAlphaConfig());
+          PartnerConfigHelper.get(context).getFraction(context, buttonRippleColorAlphaConfig);
 
       // Set text color for ripple.
       ColorStateList colorStateList =
@@ -193,7 +297,7 @@
   }
 
   static void updateButtonIconWithPartnerConfig(
-      Context context, Button button, PartnerConfig buttonIconConfig, boolean isPrimary) {
+      Context context, Button button, PartnerConfig buttonIconConfig, boolean isButtonIconAtEnd) {
     if (button == null) {
       return;
     }
@@ -201,10 +305,10 @@
     if (buttonIconConfig != null) {
       icon = PartnerConfigHelper.get(context).getDrawable(context, buttonIconConfig);
     }
-    setButtonIcon(button, icon, isPrimary);
+    setButtonIcon(button, icon, isButtonIconAtEnd);
   }
 
-  private static void setButtonIcon(Button button, Drawable icon, boolean isPrimary) {
+  private static void setButtonIcon(Button button, Drawable icon, boolean isButtonIconAtEnd) {
     if (button == null) {
       return;
     }
@@ -218,7 +322,7 @@
 
     Drawable iconStart = null;
     Drawable iconEnd = null;
-    if (isPrimary) {
+    if (isButtonIconAtEnd) {
       iconEnd = icon;
     } else {
       iconStart = icon;