diff options
author | Setup Wizard Team <android-setup-team-eng@google.com> | 2020-05-21 21:40:38 +0800 |
---|---|---|
committer | Nicole Huang <nicolehuang@google.com> | 2020-05-25 09:48:42 +0000 |
commit | c6d929030275abe2cfd23756cce4e1de8db70713 (patch) | |
tree | c7081a988f38a61af7ba4abd31376885de4cc10a | |
parent | aa1a894e84ddde71992d56f9d9491e6b21e8768d (diff) | |
download | setupcompat-android11-dev.tar.gz |
Import updated Android SetupCompat Library 312662043android11-dev
Copied from google3/third_party/java_src/android_libs/setupcompat
Bug: 135057670
Test: mm
Included changes:
- 312662043 [Stencil] Support partner resource to customize the disab...
PiperOrigin-RevId: 312662043
Change-Id: I662dd0e785b09bdbddcc4d64927ed754b7c4cce1
4 files changed, 85 insertions, 14 deletions
diff --git a/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java b/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java index 6a019fd..39b50cf 100644 --- a/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java +++ b/main/java/com/google/android/setupcompat/internal/FooterButtonPartnerConfig.java @@ -22,6 +22,8 @@ import com.google.android.setupcompat.template.FooterButton; /** Keep the partner configuration of a footer button. Used when the button is inflated. */ public class FooterButtonPartnerConfig { private final PartnerConfig buttonBackgroundConfig; + private final PartnerConfig buttonDisableAlphaConfig; + private final PartnerConfig buttonDisableBackgroundConfig; private final PartnerConfig buttonIconConfig; private final PartnerConfig buttonTextColorConfig; private final PartnerConfig buttonTextSizeConfig; @@ -33,6 +35,8 @@ public class FooterButtonPartnerConfig { private FooterButtonPartnerConfig( int partnerTheme, PartnerConfig buttonBackgroundConfig, + PartnerConfig buttonDisableAlphaConfig, + PartnerConfig buttonDisableBackgroundConfig, PartnerConfig buttonIconConfig, PartnerConfig buttonTextColorConfig, PartnerConfig buttonTextSizeConfig, @@ -45,6 +49,8 @@ public class FooterButtonPartnerConfig { this.buttonTextSizeConfig = buttonTextSizeConfig; this.buttonTextTypeFaceConfig = buttonTextTypeFaceConfig; this.buttonBackgroundConfig = buttonBackgroundConfig; + this.buttonDisableAlphaConfig = buttonDisableAlphaConfig; + this.buttonDisableBackgroundConfig = buttonDisableBackgroundConfig; this.buttonRadiusConfig = buttonRadiusConfig; this.buttonIconConfig = buttonIconConfig; this.buttonRippleColorAlphaConfig = buttonRippleColorAlphaConfig; @@ -58,6 +64,14 @@ public class FooterButtonPartnerConfig { return buttonBackgroundConfig; } + public PartnerConfig getButtonDisableAlphaConfig() { + return buttonDisableAlphaConfig; + } + + public PartnerConfig getButtonDisableBackgroundConfig() { + return buttonDisableBackgroundConfig; + } + public PartnerConfig getButtonIconConfig() { return buttonIconConfig; } @@ -86,6 +100,8 @@ public class FooterButtonPartnerConfig { public static class Builder { private final FooterButton footerButton; private PartnerConfig buttonBackgroundConfig = null; + private PartnerConfig buttonDisableAlphaConfig = null; + private PartnerConfig buttonDisableBackgroundConfig = null; private PartnerConfig buttonIconConfig = null; private PartnerConfig buttonTextColorConfig = null; private PartnerConfig buttonTextSizeConfig = null; @@ -105,6 +121,16 @@ public class FooterButtonPartnerConfig { return this; } + public Builder setButtonDisableAlphaConfig(PartnerConfig buttonDisableAlphaConfig) { + this.buttonDisableAlphaConfig = buttonDisableAlphaConfig; + return this; + } + + public Builder setButtonDisableBackgroundConfig(PartnerConfig buttonDisableBackgroundConfig) { + this.buttonDisableBackgroundConfig = buttonDisableBackgroundConfig; + return this; + } + public Builder setButtonIconConfig(PartnerConfig buttonIconConfig) { this.buttonIconConfig = buttonIconConfig; return this; @@ -144,6 +170,8 @@ public class FooterButtonPartnerConfig { return new FooterButtonPartnerConfig( partnerTheme, buttonBackgroundConfig, + buttonDisableAlphaConfig, + buttonDisableBackgroundConfig, buttonIconConfig, buttonTextColorConfig, buttonTextSizeConfig, diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java index 3c88791..bc9e5c1 100644 --- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java +++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java @@ -303,6 +303,8 @@ public class FooterBarMixin implements Mixin { /* buttonBackgroundColorConfig= */ PartnerConfig .CONFIG_FOOTER_PRIMARY_BUTTON_BG_COLOR)) .setButtonBackgroundConfig(PartnerConfig.CONFIG_FOOTER_PRIMARY_BUTTON_BG_COLOR) + .setButtonDisableAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_ALPHA) + .setButtonDisableBackgroundConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_BG_COLOR) .setButtonIconConfig(getDrawablePartnerConfig(footerButton.getButtonType())) .setButtonRadiusConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RADIUS) .setButtonRippleColorAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RIPPLE_COLOR_ALPHA) @@ -357,6 +359,8 @@ public class FooterBarMixin implements Mixin { /* buttonBackgroundColorConfig= */ PartnerConfig .CONFIG_FOOTER_SECONDARY_BUTTON_BG_COLOR)) .setButtonBackgroundConfig(PartnerConfig.CONFIG_FOOTER_SECONDARY_BUTTON_BG_COLOR) + .setButtonDisableAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_ALPHA) + .setButtonDisableBackgroundConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_DISABLED_BG_COLOR) .setButtonIconConfig(getDrawablePartnerConfig(footerButton.getButtonType())) .setButtonRadiusConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RADIUS) .setButtonRippleColorAlphaConfig(PartnerConfig.CONFIG_FOOTER_BUTTON_RIPPLE_COLOR_ALPHA) @@ -428,14 +432,16 @@ public class FooterBarMixin implements Mixin { // TODO: Make sure customize attributes in theme can be applied during setup flow. // If sets background color to full transparent, the button changes to colored borderless ink // button style. - int color = PartnerConfigHelper.get(context).getColor(context, buttonBackgroundColorConfig); - if (applyPartnerResources && color == Color.TRANSPARENT) { - overrideTheme = R.style.SucPartnerCustomizationButton_Secondary; - } else if (applyPartnerResources && (color != Color.TRANSPARENT)) { - // TODO: remove the constrain (color != Color.WHITE), need to check all pages go - // well without customization. It should be fine since the default value of secondary bg color - // is set as transparent. - overrideTheme = R.style.SucPartnerCustomizationButton_Primary; + if (applyPartnerResources) { + int color = PartnerConfigHelper.get(context).getColor(context, buttonBackgroundColorConfig); + if (color == Color.TRANSPARENT) { + overrideTheme = R.style.SucPartnerCustomizationButton_Secondary; + } else if (color != Color.TRANSPARENT) { + // TODO: remove the constrain (color != Color.WHITE), need to check all pages + // go well without customization. It should be fine since the default value of secondary bg + // color is set as transparent. + overrideTheme = R.style.SucPartnerCustomizationButton_Primary; + } } return overrideTheme; } @@ -545,7 +551,10 @@ public class FooterBarMixin implements Mixin { updateButtonTypeFaceWithPartnerConfig( button, footerButtonPartnerConfig.getButtonTextTypeFaceConfig()); updateButtonBackgroundWithPartnerConfig( - button, footerButtonPartnerConfig.getButtonBackgroundConfig()); + button, + footerButtonPartnerConfig.getButtonBackgroundConfig(), + footerButtonPartnerConfig.getButtonDisableAlphaConfig(), + footerButtonPartnerConfig.getButtonDisableBackgroundConfig()); updateButtonRadiusWithPartnerConfig(button, footerButtonPartnerConfig.getButtonRadiusConfig()); updateButtonIconWithPartnerConfig(button, footerButtonPartnerConfig.getButtonIconConfig()); updateButtonRippleColorWithPartnerConfig(button, footerButtonPartnerConfig); @@ -586,25 +595,43 @@ public class FooterBarMixin implements Mixin { @TargetApi(VERSION_CODES.Q) private void updateButtonBackgroundWithPartnerConfig( - Button button, PartnerConfig buttonBackgroundConfig) { + Button button, + PartnerConfig buttonBackgroundConfig, + PartnerConfig buttonDisableAlphaConfig, + PartnerConfig buttonDisableBackgroundConfig) { Preconditions.checkArgument( Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q, "Update button background only support on sdk Q or higher"); @ColorInt int color; + @ColorInt int disabledColor; + float disabledAlpha; int[] DISABLED_STATE_SET = {-android.R.attr.state_enabled}; int[] ENABLED_STATE_SET = {}; color = PartnerConfigHelper.get(context).getColor(context, buttonBackgroundConfig); + disabledAlpha = + PartnerConfigHelper.get(context).getFraction(context, buttonDisableAlphaConfig, 0f); + disabledColor = + PartnerConfigHelper.get(context).getColor(context, buttonDisableBackgroundConfig); if (color != Color.TRANSPARENT) { - TypedArray a = context.obtainStyledAttributes(new int[] {android.R.attr.disabledAlpha}); - float alpha = a.getFloat(0, DEFAULT_DISABLED_ALPHA); - a.recycle(); + if (disabledAlpha <= 0f) { + // if no partner resource, fallback to theme disable alpha + float alpha; + TypedArray a = context.obtainStyledAttributes(new int[] {android.R.attr.disabledAlpha}); + alpha = a.getFloat(0, DEFAULT_DISABLED_ALPHA); + a.recycle(); + disabledAlpha = alpha; + } + if (disabledColor == Color.TRANSPARENT) { + // if no partner resource, fallback to button background color + disabledColor = color; + } // Set text color for ripple. ColorStateList colorStateList = new ColorStateList( new int[][] {DISABLED_STATE_SET, ENABLED_STATE_SET}, - new int[] {convertRgbToArgb(color, alpha), color}); + new int[] {convertRgbToArgb(disabledColor, disabledAlpha), color}); // b/129482013: When a LayerDrawable is mutated, a new clone of its children drawables are // created, but without copying the state from the parent drawable. So even though the diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java index 2844e03..56256c9 100644 --- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java +++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java @@ -93,6 +93,14 @@ public enum PartnerConfig { CONFIG_FOOTER_BUTTON_TEXT_SIZE( PartnerConfigKey.KEY_FOOTER_BUTTON_TEXT_SIZE, ResourceType.DIMENSION), + // Disabled background alpha of the footer buttons + CONFIG_FOOTER_BUTTON_DISABLED_ALPHA( + PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_ALPHA, ResourceType.FRACTION), + + // Disabled background color of the footer buttons + CONFIG_FOOTER_BUTTON_DISABLED_BG_COLOR( + PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_BG_COLOR, ResourceType.COLOR), + // Background color of the primary footer button CONFIG_FOOTER_PRIMARY_BUTTON_BG_COLOR( PartnerConfigKey.KEY_FOOTER_PRIMARY_BUTTON_BG_COLOR, ResourceType.COLOR), diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java index 49e96b2..e5c5442 100644 --- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java +++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java @@ -43,6 +43,8 @@ import java.lang.annotation.RetentionPolicy; PartnerConfigKey.KEY_FOOTER_BUTTON_RADIUS, PartnerConfigKey.KEY_FOOTER_BUTTON_RIPPLE_ALPHA, PartnerConfigKey.KEY_FOOTER_BUTTON_TEXT_SIZE, + PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_ALPHA, + PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_BG_COLOR, PartnerConfigKey.KEY_FOOTER_PRIMARY_BUTTON_BG_COLOR, PartnerConfigKey.KEY_FOOTER_PRIMARY_BUTTON_TEXT_COLOR, PartnerConfigKey.KEY_FOOTER_SECONDARY_BUTTON_BG_COLOR, @@ -131,6 +133,12 @@ public @interface PartnerConfigKey { // Text size of the footer button String KEY_FOOTER_BUTTON_TEXT_SIZE = "setup_compat_footer_button_text_size"; + // Disabled background alpha of the footer buttons + String KEY_FOOTER_BUTTON_DISABLED_ALPHA = "setup_compat_footer_button_disabled_alpha"; + + // Disabled background color of the footer buttons + String KEY_FOOTER_BUTTON_DISABLED_BG_COLOR = "setup_compat_footer_button_disabled_bg_color"; + // Background color of the primary footer button String KEY_FOOTER_PRIMARY_BUTTON_BG_COLOR = "setup_compat_footer_primary_button_bg_color"; |