Import updated Android Setupdesign Library 467157122 am: 6bc5b679e6
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/setupdesign/+/19599666
Change-Id: Ia9e12db1ef46e29b13561c0e176587f67682d3cf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/main/res/layout/sud_glif_header.xml b/main/res/layout/sud_glif_header.xml
index 70b8daa..accb3c0 100644
--- a/main/res/layout/sud_glif_header.xml
+++ b/main/res/layout/sud_glif_header.xml
@@ -43,6 +43,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
+ <include layout="@layout/sud_glif_profile" />
+
<ViewStub
android:id="@+id/sud_layout_progress_stub"
android:layout_width="match_parent"
diff --git a/main/res/layout/sud_glif_profile.xml b/main/res/layout/sud_glif_profile.xml
new file mode 100644
index 0000000..dbbf813
--- /dev/null
+++ b/main/res/layout/sud_glif_profile.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+
+<!-- TODO: Change LinearLayout to a TextView include drawable -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/sud_layout_profile"
+ style="?attr/sudGlifAccountContainerStyle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:visibility="gone"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:id="@+id/sud_account_avatar"
+ style="?attr/sudGlifAccountAvatarStyle"
+ android:contentDescription="@null"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:id="@+id/sud_account_name"
+ style="?attr/sudGlifAccountNameStyle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="left" />
+
+</LinearLayout>
diff --git a/main/res/values-v31/styles.xml b/main/res/values-v31/styles.xml
index df86de7..1be5b13 100644
--- a/main/res/values-v31/styles.xml
+++ b/main/res/values-v31/styles.xml
@@ -19,6 +19,7 @@
<!-- Main theme for dynamic color -->
<style name="SudDynamicColorBaseTheme">
<item name="colorAccent">@color/sud_dynamic_color_accent_glif_v3_dark</item>
+ <item name="android:colorAccent">?attr/colorAccent</item>
<item name="android:textColorLink">@color/sud_system_hyperlink_text</item>
<item name="alertDialogTheme">@style/SudDynamicColorAlertDialogThemeCompat</item>
<item name="android:datePickerDialogTheme">@style/SudDynamicColorDateTimePickerDialogTheme</item>
@@ -33,6 +34,7 @@
<style name="SudDynamicColorBaseTheme.Light">
<item name="colorAccent">@color/sud_dynamic_color_accent_glif_v3_light</item>
+ <item name="android:colorAccent">?attr/colorAccent</item>
<item name="android:textColorLink">@color/sud_system_hyperlink_text</item>
<item name="alertDialogTheme">@style/SudDynamicColorAlertDialogThemeCompat.Light</item>
<item name="android:datePickerDialogTheme">@style/SudDynamicColorDateTimePickerDialogTheme.Light</item>
diff --git a/main/res/values/attrs.xml b/main/res/values/attrs.xml
index 22aee0d..4600bcc 100644
--- a/main/res/values/attrs.xml
+++ b/main/res/values/attrs.xml
@@ -61,11 +61,14 @@
<attr name="sudGlifIconSize" format="dimension" />
<attr name="sudGlifDescriptionStyle" format="reference" />
+ <attr name="sudGlifAccountNameStyle" format="reference" />
+ <attr name="sudGlifAccountAvatarStyle" format="reference" />
+ <attr name="sudGlifAccountContainerStyle" format="reference" />
+ <attr name="sudGlifAccountAvatarSize" format="dimension" />
<attr name="sudButtonAllCaps" format="boolean" />
<attr name="sudButtonCornerRadius" format="dimension" />
<attr name="sudButtonFontFamily" format="string|reference" />
- <!-- Values copied from frameworks/base/core/res/res/values/attrs.xml -->
<attr name="sudButtonTertiaryGravity">
<!-- Push object to the left of its container, not changing its size. -->
<flag name="left" value="0x03" />
diff --git a/main/res/values/dimens.xml b/main/res/values/dimens.xml
index 4b821a4..1562cc5 100644
--- a/main/res/values/dimens.xml
+++ b/main/res/values/dimens.xml
@@ -152,6 +152,11 @@
<dimen name="sud_glif_header_title_margin_bottom">2dp</dimen>
<dimen name="sud_header_container_margin_bottom">0dp</dimen>
+ <!-- Account information -->
+ <dimen name="sud_account_name_text_size">14sp</dimen>
+ <dimen name="sud_account_avatar_margin_end">8dp</dimen>
+ <dimen name="sud_account_avatar_max_height">24dp</dimen>
+
<!-- This value leverages sud_description_glif_margin_top -->
<dimen name="sud_glif_description_margin_top">3dp</dimen>
<dimen name="sud_glif_description_margin_bottom">12dp</dimen>
diff --git a/main/res/values/styles.xml b/main/res/values/styles.xml
index e33b305..9cc93bc 100644
--- a/main/res/values/styles.xml
+++ b/main/res/values/styles.xml
@@ -168,6 +168,10 @@
<item name="sudDividerInsetStart">@dimen/sud_items_glif_icon_divider_inset</item>
<item name="sudDividerInsetStartNoIcon">@dimen/sud_items_glif_text_divider_inset</item>
<item name="sudDividerShown">true</item>
+ <item name="sudGlifAccountContainerStyle">@style/SudGlifAccountContainer</item>
+ <item name="sudGlifAccountNameStyle">@style/SudGlifAccountName</item>
+ <item name="sudGlifAccountAvatarSize">@dimen/sud_account_avatar_max_height</item>
+ <item name="sudGlifAccountAvatarStyle">@style/sudGlifAccountAvatar</item>
<item name="sudGlifHeaderTitleStyle">@style/SudGlifHeaderTitle</item>
<item name="sudGlifHeaderGravity">start</item>
<item name="sudGlifSubtitleGravity">start</item>
@@ -262,6 +266,10 @@
<item name="sudDividerInsetStart">@dimen/sud_items_glif_icon_divider_inset</item>
<item name="sudDividerInsetStartNoIcon">@dimen/sud_items_glif_text_divider_inset</item>
<item name="sudDividerShown">true</item>
+ <item name="sudGlifAccountContainerStyle">@style/SudGlifAccountContainer</item>
+ <item name="sudGlifAccountNameStyle">@style/SudGlifAccountName</item>
+ <item name="sudGlifAccountAvatarSize">@dimen/sud_account_avatar_max_height</item>
+ <item name="sudGlifAccountAvatarStyle">@style/sudGlifAccountAvatar</item>
<item name="sudGlifHeaderTitleStyle">@style/SudGlifHeaderTitle</item>
<item name="sudGlifHeaderGravity">start</item>
<item name="sudGlifSubtitleGravity">start</item>
@@ -415,7 +423,7 @@
<item name="sudItemDescriptionStyle">@style/SudItemContainerMaterialYou.Description</item>
<item name="sudItemVerboseTitleStyle">@style/SudMaterialYouItemTitle.Verbose</item>
<item name="alertDialogTheme">@style/SudMaterialYouAlertDialogThemeCompat</item>
- <item name="android:alertDialogTheme" >@style/SudMaterialYouAlertDialogTheme</item>
+ <item name="android:alertDialogTheme">@style/SudMaterialYouAlertDialogTheme</item>
</style>
<style name="SudThemeGlifV4.Light" parent="SudThemeGlifV3.Light">
@@ -449,7 +457,7 @@
<item name="sudItemDescriptionStyle">@style/SudItemContainerMaterialYou.Description</item>
<item name="sudItemVerboseTitleStyle">@style/SudMaterialYouItemTitle.Verbose</item>
<item name="alertDialogTheme">@style/SudMaterialYouAlertDialogThemeCompat.Light</item>
- <item name="android:alertDialogTheme" >@style/SudMaterialYouAlertDialogTheme.Light</item>
+ <item name="android:alertDialogTheme">@style/SudMaterialYouAlertDialogTheme.Light</item>
</style>
<style name="SudDynamicColorTheme" />
@@ -877,6 +885,7 @@
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textDirection" tools:targetApi="jelly_bean_mr1">locale</item>
<item name="android:accessibilityHeading" tools:targetApi="p">true</item>
+ <item name="android:hyphenationFrequency" tools:targetApi="23">full</item>
</style>
<style name="SudGlifHeaderTitleMaterialYou">
@@ -895,6 +904,7 @@
<item name="android:textDirection" tools:targetApi="jelly_bean_mr1">locale</item>
<item name="android:accessibilityHeading" tools:targetApi="p">true</item>
<item name="android:textSize">@dimen/sud_glif_header_title_size_material_you</item>
+ <item name="android:hyphenationFrequency" tools:targetApi="23">full</item>
</style>
<style name="SudGlifDescription" parent="SudDescription.Glif">
@@ -926,16 +936,39 @@
<item name="android:textSize">@dimen/sud_glif_description_text_size_material_you</item>
</style>
+ <style name="sudGlifAccountAvatar">
+ <item name="android:layout_marginRight">@dimen/sud_account_avatar_margin_end</item>
+ <item name="android:layout_marginEnd">@dimen/sud_account_avatar_margin_end</item>
+ <item name="android:adjustViewBounds">true</item>
+ <item name="android:maxHeight">@dimen/sud_account_avatar_max_height</item>
+ </style>
+
+ <style name="SudGlifAccountName">
+ <item name="android:fontFamily" tools:targetApi="jelly_bean">@string/sudFontSecondary</item>
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
+ <item name="android:textSize">@dimen/sud_account_name_text_size</item>
+ <item name="android:layout_gravity">center_vertical</item>
+ </style>
+
<style name="SudGlifHeaderContainer">
<item name="android:gravity">?attr/sudGlifHeaderGravity</item>
<item name="android:layout_marginBottom">?attr/sucHeaderContainerMarginBottom</item>
</style>
+ <style name="SudGlifAccountContainer">
+ <item name="android:layout_marginBottom">@dimen/sud_glif_header_title_margin_bottom_material_you</item>
+ <item name="android:layout_marginTop">@dimen/sud_glif_header_title_margin_top_material_you</item>
+ <item name="android:layout_marginLeft">?attr/sudMarginStart</item>
+ <item name="android:layout_marginStart" tools:ignore="NewApi">?attr/sudMarginStart</item>
+ <item name="android:layout_marginRight">?attr/sudMarginEnd</item>
+ <item name="android:layout_marginEnd">?attr/sudMarginEnd</item>
+ </style>
+
<style name="SudGlifIconContainer">
<item name="android:layout_marginLeft">?attr/sudMarginStart</item>
- <item name="android:layout_marginStart" tools:ignore="NewApi">?attr/sudMarginStart</item>
+ <item name="android:layout_marginStart" tools:ignore="NewApi">?attr/sudMarginStart</item>
<item name="android:layout_marginRight">?attr/sudMarginEnd</item>
- <item name="android:layout_marginEnd" tools:ignore="NewApi">?attr/sudMarginEnd</item>
+ <item name="android:layout_marginEnd" tools:ignore="NewApi">?attr/sudMarginEnd</item>
<item name="android:layout_marginTop">?attr/sucGlifIconMarginTop</item>
<item name="android:maxHeight">?attr/sudGlifIconSize</item>
</style>
diff --git a/main/src/com/google/android/setupdesign/GlifLayout.java b/main/src/com/google/android/setupdesign/GlifLayout.java
index 1b8c8f8..3f0d243 100644
--- a/main/src/com/google/android/setupdesign/GlifLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifLayout.java
@@ -45,6 +45,7 @@
import com.google.android.setupdesign.template.HeaderMixin;
import com.google.android.setupdesign.template.IconMixin;
import com.google.android.setupdesign.template.IllustrationProgressMixin;
+import com.google.android.setupdesign.template.ProfileMixin;
import com.google.android.setupdesign.template.ProgressBarMixin;
import com.google.android.setupdesign.template.RequireScrollMixin;
import com.google.android.setupdesign.template.ScrollViewScrollHandlingDelegate;
@@ -121,6 +122,7 @@
registerMixin(HeaderMixin.class, new HeaderMixin(this, attrs, defStyleAttr));
registerMixin(DescriptionMixin.class, new DescriptionMixin(this, attrs, defStyleAttr));
registerMixin(IconMixin.class, new IconMixin(this, attrs, defStyleAttr));
+ registerMixin(ProfileMixin.class, new ProfileMixin(this, attrs, defStyleAttr));
registerMixin(ProgressBarMixin.class, new ProgressBarMixin(this, attrs, defStyleAttr));
registerMixin(IllustrationProgressMixin.class, new IllustrationProgressMixin(this));
final RequireScrollMixin requireScrollMixin = new RequireScrollMixin(this);
@@ -184,6 +186,7 @@
getMixin(HeaderMixin.class).tryApplyPartnerCustomizationStyle();
getMixin(DescriptionMixin.class).tryApplyPartnerCustomizationStyle();
getMixin(ProgressBarMixin.class).tryApplyPartnerCustomizationStyle();
+ getMixin(ProfileMixin.class).tryApplyPartnerCustomizationStyle();
tryApplyPartnerCustomizationStyleToShortDescription();
}
diff --git a/main/src/com/google/android/setupdesign/template/ProfileMixin.java b/main/src/com/google/android/setupdesign/template/ProfileMixin.java
new file mode 100644
index 0000000..f3f346d
--- /dev/null
+++ b/main/src/com/google/android/setupdesign/template/ProfileMixin.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2022 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.template;
+
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import androidx.annotation.DrawableRes;
+import com.google.android.setupcompat.internal.TemplateLayout;
+import com.google.android.setupcompat.template.Mixin;
+import com.google.android.setupdesign.R;
+import com.google.android.setupdesign.util.HeaderAreaStyler;
+import com.google.android.setupdesign.util.LayoutStyler;
+import com.google.android.setupdesign.util.PartnerStyleHelper;
+import com.google.errorprone.annotations.CheckReturnValue;
+
+/** A {@link Mixin} for setting an account name and account avatar on the template layout. */
+@CheckReturnValue // see go/why-crv
+public class ProfileMixin implements Mixin {
+
+ private final TemplateLayout templateLayout;
+ private static final String TAG = "ProfileMixin";
+ public static final int RIGHT = 5;
+ public static final int CENTER = 17;
+ public static final int LEFT = 3;
+
+ /**
+ * A {@link Mixin} for setting and getting the Account.
+ *
+ * @param layout The template layout that this Mixin is a part of
+ * @param attrs XML attributes given to the layout
+ * @param defStyleAttr The default style attribute as given to the constructor of the layout
+ */
+ public ProfileMixin(TemplateLayout layout, AttributeSet attrs, int defStyleAttr) {
+ templateLayout = layout;
+ }
+
+ /**
+ * Sets the Account name.
+ *
+ * @param accountName The text to be set as account name
+ */
+ public void setAccountName(CharSequence accountName) {
+ final TextView accountView = getAccountNameView();
+ final LinearLayout container = getContainerView();
+ if (accountView != null && accountName != null) {
+ accountView.setText(accountName);
+ container.setVisibility(View.VISIBLE);
+ } else {
+ Log.w(TAG, "Didn't get the account name");
+ }
+ }
+
+ /**
+ * Sets the icon on this layout.
+ *
+ * @param icon A drawable icon
+ */
+ public void setAccountAvatar(Drawable icon) {
+ final ImageView iconView = getAccountAvatarView();
+ final LinearLayout container = getContainerView();
+ if (iconView != null && icon != null) {
+ iconView.setImageDrawable(icon);
+ container.setVisibility(View.VISIBLE);
+ } else {
+ Log.w(TAG, "Didn't get the account avatar");
+ }
+ }
+
+ /**
+ * Sets the icon on this layout.
+ *
+ * @param icon A drawable icon resource
+ */
+ public void setAccountAvatar(@DrawableRes int icon) {
+ final ImageView iconView = getAccountAvatarView();
+ final LinearLayout container = getContainerView();
+ if (iconView != null && icon != 0) {
+ // Note: setImageResource on the ImageView is overridden in AppCompatImageView for
+ // support lib users, which enables vector drawable compat to work on versions pre-L.
+ iconView.setImageResource(icon);
+ container.setVisibility(View.VISIBLE);
+ } else {
+ Log.w(TAG, "Didn't get the account avatar");
+ }
+ }
+
+ /**
+ * Sets the account name icon on this layout.
+ *
+ * @param accountName The text to be set as account name
+ * @param icon A drawable icon
+ */
+ public void setAcccount(CharSequence accountName, Drawable icon) {
+ setAccountName(accountName);
+ setAccountAvatar(icon);
+ }
+
+ /**
+ * Sets the account name icon on this layout.
+ *
+ * @param accountName The text to be set as account name
+ * @param icon A drawable icon resource
+ */
+ public void setAcccount(CharSequence accountName, @DrawableRes int icon) {
+ setAccountName(accountName);
+ setAccountAvatar(icon);
+ }
+
+ /**
+ * Sets the visibility of the account. gone map to 8 invisible map to 4 visible map to 0
+ *
+ * @param visibility Set it visible or not
+ */
+ public void setVisibility(int visibility) {
+ getContainerView().setVisibility(visibility);
+ }
+
+ /**
+ * Makes account align to left, center or right.
+ *
+ * @param gravity the number or the gravity
+ */
+ public void setAccountAlignment(int gravity) {
+ final LinearLayout container = getContainerView();
+ if (gravity == RIGHT || gravity == CENTER || gravity == LEFT) {
+ container.setGravity(gravity);
+ } else {
+ Log.w(TAG, "Unsupported alignment");
+ }
+ }
+
+ /** Tries to apply the partner customization to the account photo. */
+ public void tryApplyPartnerCustomizationStyle() {
+ if (PartnerStyleHelper.shouldApplyPartnerResource(templateLayout)) {
+ final ImageView iconView = getAccountAvatarView();
+ final TextView accountView = getAccountNameView();
+ View iconAreaView = templateLayout.findManagedViewById(R.id.sud_layout_header);
+ LayoutStyler.applyPartnerCustomizationExtraPaddingStyle(iconAreaView);
+ HeaderAreaStyler.applyPartnerCustomizationAccountStyle(iconView, accountView);
+ }
+ }
+
+ /** Returns the current account name. */
+ public CharSequence getAccountName() {
+ final TextView accountView = getAccountNameView();
+ return accountView.getText();
+ }
+
+ /** Returns the current account avatar. */
+ public Drawable getAccountAvatar() {
+ final ImageView iconView = getAccountAvatarView();
+ return iconView.getDrawable();
+ }
+
+ /** Returns the current account name text. */
+ private TextView getAccountNameView() {
+ return (TextView) templateLayout.findManagedViewById(R.id.sud_account_name);
+ }
+
+ /** Returns the current account icon image. */
+ private ImageView getAccountAvatarView() {
+ return (ImageView) templateLayout.findManagedViewById(R.id.sud_account_avatar);
+ }
+
+ private LinearLayout getContainerView() {
+ return (LinearLayout) templateLayout.findManagedViewById(R.id.sud_layout_profile);
+ }
+
+ /** Returns the current account visibility. */
+ public int getVisibility() {
+ return getContainerView().getVisibility();
+ }
+}
diff --git a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
index e233219..9b9e95a 100644
--- a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
+++ b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
@@ -19,12 +19,14 @@
import static com.google.android.setupcompat.util.BuildCompatUtils.isAtLeastS;
import android.content.Context;
+import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.util.Log;
+import android.util.TypedValue;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
@@ -100,6 +102,47 @@
PartnerStyleHelper.getLayoutGravity(description.getContext())));
}
+ public static void applyPartnerCustomizationAccountStyle(
+ ImageView avatar, TextView name) {
+ if (avatar == null || name == null) {
+ return;
+ }
+
+ Context context = avatar.getContext();
+
+ ViewGroup.LayoutParams lpIcon = avatar.getLayoutParams();
+ if (lpIcon instanceof ViewGroup.MarginLayoutParams) {
+ ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lpIcon;
+
+ int rightMargin =
+ (int)
+ PartnerConfigHelper.get(context)
+ .getDimension(context, PartnerConfig.CONFIG_ACCOUNT_AVATAR_MARGIN_END);
+ mlp.setMargins(mlp.leftMargin, mlp.topMargin, rightMargin, mlp.bottomMargin);
+ }
+
+ int maxHeight =
+ (int)
+ PartnerConfigHelper.get(context)
+ .getDimension(context, PartnerConfig.CONFIG_ACCOUNT_AVATAR_SIZE,
+ context.getResources().getDimension(R.dimen.sud_account_avatar_max_height));
+ avatar.setMaxHeight(maxHeight);
+
+ int textSize =
+ (int)
+ PartnerConfigHelper.get(context)
+ .getDimension(context, PartnerConfig.CONFIG_ACCOUNT_NAME_TEXT_SIZE);
+ name.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
+
+ String textFamily =
+ PartnerConfigHelper.get(context)
+ .getString(context, PartnerConfig.CONFIG_ACCOUNT_NAME_FONT_FAMILY);
+ Typeface font = Typeface.create(textFamily, Typeface.NORMAL);
+ if (font != null) {
+ name.setTypeface(font);
+ }
+ }
+
/**
* Applies the partner style of header area to the given layout {@code headerArea}. The theme
* should set partner heavy theme first, and then the partner style of header would be applied. As
diff --git a/main/src/com/google/android/setupdesign/util/Partner.java b/main/src/com/google/android/setupdesign/util/Partner.java
index cf26f16..2052afb 100644
--- a/main/src/com/google/android/setupdesign/util/Partner.java
+++ b/main/src/com/google/android/setupdesign/util/Partner.java
@@ -33,6 +33,7 @@
import androidx.annotation.ArrayRes;
import androidx.annotation.BoolRes;
import androidx.annotation.ColorRes;
+import androidx.annotation.DimenRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
@@ -84,6 +85,28 @@
}
/**
+ * Gets a dimension value from partner overlay, or if not available, gets the value from the
+ * original context instead.
+ *
+ * @see #getResourceEntry(Context, int)
+ */
+ public static int getDimensionPixelSize(Context context, @DimenRes int id) {
+ final ResourceEntry entry = getResourceEntry(context, id);
+ return entry.resources.getDimensionPixelSize(entry.id);
+ }
+
+ /**
+ * Gets a dimension value from partner overlay, or if not available, gets the value from the
+ * original context instead.
+ *
+ * @see #getResourceEntry(Context, int)
+ */
+ public static float getDimension(Context context, @DimenRes int id) {
+ final ResourceEntry entry = getResourceEntry(context, id);
+ return entry.resources.getDimension(entry.id);
+ }
+
+ /**
* Gets a drawable from partner overlay, or if not available, the drawable from the original
* context.
*
diff --git a/main/src/com/google/android/setupdesign/util/ThemeHelper.java b/main/src/com/google/android/setupdesign/util/ThemeHelper.java
index eeee7dd..57a8278 100644
--- a/main/src/com/google/android/setupdesign/util/ThemeHelper.java
+++ b/main/src/com/google/android/setupdesign/util/ThemeHelper.java
@@ -19,6 +19,8 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import com.google.android.setupcompat.PartnerCustomizationLayout;
@@ -235,6 +237,39 @@
return resId;
}
+ /** Returns a default theme resource id which provides by setup wizard. */
+ @StyleRes
+ public static int getSuwDefaultTheme(@NonNull Context context) {
+ String themeName = PartnerConfigHelper.getSuwDefaultThemeString(context);
+ @StyleRes int defaultTheme;
+ if (VERSION.SDK_INT < VERSION_CODES.O) {
+ defaultTheme =
+ ThemeHelper.isSetupWizardDayNightEnabled(context)
+ ? R.style.SudThemeGlif_DayNight
+ : R.style.SudThemeGlif_Light;
+ } else if (VERSION.SDK_INT < VERSION_CODES.P) {
+ defaultTheme =
+ ThemeHelper.isSetupWizardDayNightEnabled(context)
+ ? R.style.SudThemeGlifV2_DayNight
+ : R.style.SudThemeGlifV2_Light;
+ } else if (VERSION.SDK_INT < VERSION_CODES.TIRAMISU) {
+ defaultTheme =
+ ThemeHelper.isSetupWizardDayNightEnabled(context)
+ ? R.style.SudThemeGlifV3_DayNight
+ : R.style.SudThemeGlifV3_Light;
+ } else {
+ defaultTheme =
+ ThemeHelper.isSetupWizardDayNightEnabled(context)
+ ? R.style.SudThemeGlifV4_DayNight
+ : R.style.SudThemeGlifV4_Light;
+ }
+ return new ThemeResolver.Builder()
+ .setDefaultTheme(defaultTheme)
+ .setUseDayNight(isSetupWizardDayNightEnabled(context))
+ .build()
+ .resolve(themeName, /* suppressDayNight= */ !isSetupWizardDayNightEnabled(context));
+ }
+
/** Returns {@code true} if the dynamic color is set. */
public static boolean trySetDynamicColor(@NonNull Context context) {
if (!BuildCompatUtils.isAtLeastS()) {