Merge Android 13 QPR1
Bug: 261731544
Merged-In: I91060901a090bb53ce52654436ebf3445e53118d
Change-Id: I1b238d0eb0454a86f55a69ec22ae86f16d66b25a
diff --git a/OWNERS b/OWNERS
index 3381026..b050f57 100644
--- a/OWNERS
+++ b/OWNERS
@@ -8,4 +8,3 @@
prochinwang@google.com
cipson@google.com #{LAST_RESORT_SUGGESTION}
-luyota@google.com #{LAST_RESORT_SUGGESTION}
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-night-v33/colors.xml b/main/res/values-night-v33/colors.xml
index 79ed31a..5bb3d39 100644
--- a/main/res/values-night-v33/colors.xml
+++ b/main/res/values-night-v33/colors.xml
@@ -17,9 +17,5 @@
<resources>
- <color name="sud_system_primary_text">@color/sud_system_neutral1_0</color>
- <color name="sud_system_secondary_text">@color/sud_system_neutral1_200</color>
- <color name="sud_system_tertiary_text_inactive">@color/sud_system_neutral1_300</color>
- <color name="sud_system_background_surface">@color/sud_system_neutral1_1000</color>
- <color name="sud_system_dividing_line">@color/sud_system_neutral1_600</color>
-</resources>
\ No newline at end of file
+ <color name="sud_system_dividing_line">@color/sud_system_neutral2_700</color>
+</resources>
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-v33/colors.xml b/main/res/values-v33/colors.xml
index c46c6fc..37e3b37 100644
--- a/main/res/values-v33/colors.xml
+++ b/main/res/values-v33/colors.xml
@@ -18,11 +18,10 @@
<resources>
- <color name="sud_system_secondary_text">@color/sud_system_neutral1_700</color>
- <color name="sud_system_tertiary_text_inactive">@color/sud_system_neutral1_600</color>
- <color name="sud_system_background_surface">@color/sud_system_neutral1_0</color>
<color name="sud_system_button_surface">@color/sud_system_accent1_600</color>
- <color name="sud_system_dividing_line">@color/sud_system_neutral1_500</color>
+ <color name="sud_system_button_text">@color/sud_system_neutral1_50</color>
+ <!-- used by other 1p-->
+ <color name="sud_system_dividing_line">@color/sud_system_neutral2_200</color>
<color name="sud_glif_v3_nav_bar_divider_color_light">@android:color/transparent</color>
</resources>
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..e3b3489 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>
@@ -397,6 +405,7 @@
<item name="sudButtonCornerRadius">@dimen/sud_footer_bar_button_radius_material_you</item>
<item name="sudButtonTertiaryGravity">center_horizontal</item>
<item name="sudGlifIconSize">@dimen/sud_glif_icon_max_height_material_you</item>
+ <item name="sudGlifAccountContainerStyle">@style/SudGlifAccountContainerMaterialYou</item>
<item name="sudGlifHeaderTitleStyle">@style/SudGlifHeaderTitleMaterialYou</item>
<item name="sudGlifHeaderGravity">start</item>
<item name="sucGlifHeaderMarginTop">@dimen/sud_glif_header_title_margin_top_material_you</item>
@@ -415,7 +424,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">
@@ -431,6 +440,7 @@
<item name="sudButtonCornerRadius">@dimen/sud_footer_bar_button_radius_material_you</item>
<item name="sudButtonTertiaryGravity">center_horizontal</item>
<item name="sudGlifIconSize">@dimen/sud_glif_icon_max_height_material_you</item>
+ <item name="sudGlifAccountContainerStyle">@style/SudGlifAccountContainerMaterialYou</item>
<item name="sudGlifHeaderTitleStyle">@style/SudGlifHeaderTitleMaterialYou</item>
<item name="sudGlifHeaderGravity">start</item>
<item name="sucGlifHeaderMarginTop">@dimen/sud_glif_header_title_margin_top_material_you</item>
@@ -449,7 +459,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 +887,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 +906,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 +938,51 @@
<item name="android:textSize">@dimen/sud_glif_description_text_size_material_you</item>
</style>
+ <style name="SudGlifAccountContainerMaterialYou">
+ <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" tools:ignore="NewApi">?attr/sudMarginEnd</item>
+ <item name="android:gravity">?attr/sudGlifHeaderGravity</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>
+ <item name="android:layout_gravity">center_vertical</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" tools:ignore="NewApi">?attr/sudMarginEnd</item>
+ <item name="android:gravity">?attr/sudGlifHeaderGravity</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..2970d0e
--- /dev/null
+++ b/main/src/com/google/android/setupdesign/template/ProfileMixin.java
@@ -0,0 +1,201 @@
+/*
+ * 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 ImageView iconView = getAccountAvatarView();
+ final LinearLayout container = getContainerView();
+ if (accountView != null && accountName != null) {
+ accountView.setText(accountName);
+ container.setVisibility(View.VISIBLE);
+ if (iconView != null && getAccountAvatar() == null) {
+ iconView.setVisibility(View.GONE);
+ }
+ } else {
+ Log.w(TAG, "Didn't get the account name");
+ }
+ }
+
+ /**
+ * Sets the icon on this layout.
+ *
+ * @param icon A drawable icon to set, or {@code null} to hide the 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);
+ iconView.setVisibility(View.VISIBLE);
+ } else if (iconView != null) {
+ iconView.setVisibility(View.GONE);
+ Log.w(TAG, "Didn't get the account avatar");
+ }
+ }
+
+ /**
+ * Sets the icon on this layout.
+ *
+ * @param icon A drawable icon resource to set, or {@code null} to hide the icon
+ */
+ 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);
+ iconView.setVisibility(View.VISIBLE);
+ } else if (iconView != null) {
+ iconView.setVisibility(View.GONE);
+ 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 setAccount(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 setAccount(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();
+ final LinearLayout container = getContainerView();
+ View iconAreaView = templateLayout.findManagedViewById(R.id.sud_layout_header);
+ LayoutStyler.applyPartnerCustomizationExtraPaddingStyle(iconAreaView);
+ HeaderAreaStyler.applyPartnerCustomizationAccountStyle(iconView, accountView, container);
+ }
+ }
+
+ /** 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/DeviceHelper.java b/main/src/com/google/android/setupdesign/util/DeviceHelper.java
new file mode 100644
index 0000000..5845cbb
--- /dev/null
+++ b/main/src/com/google/android/setupdesign/util/DeviceHelper.java
@@ -0,0 +1,76 @@
+/*
+ * 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.util;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+import com.google.android.setupdesign.R;
+
+/** Helper class to get attributes of the device, like a friendly display name. */
+public final class DeviceHelper {
+
+ private static final String TAG = DeviceHelper.class.getSimpleName();
+
+ @VisibleForTesting
+ public static final String SUW_AUTHORITY = "com.google.android.setupwizard.partner";
+
+ @VisibleForTesting public static final String GET_DEVICE_NAME_METHOD = "getDeviceName";
+
+ /**
+ * Get the device name text from these resources, if they are unavailable or setupwizard apk is
+ * older which does not contains {@link DeviceHelper#GET_DEVICE_NAME_METHOD} method, return the
+ * device name as default value "device".
+ *
+ * <p>Priority: partner config ({@link
+ * com.google.android.setupwizard.util.PartnerResource#DEVICE_NAME}) > {@link
+ * android.provider.Settings.Global#DEVICE_NAME} > system property ro.product.model)
+ */
+ @Nullable
+ public static CharSequence getDeviceName(@NonNull Context context) {
+ Bundle deviceName = null;
+
+ try {
+ deviceName =
+ context
+ .getContentResolver()
+ .call(
+ new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SUW_AUTHORITY)
+ .build(),
+ GET_DEVICE_NAME_METHOD,
+ /* arg= */ null,
+ /* extras= */ null);
+ } catch (IllegalArgumentException | SecurityException exception) {
+ Log.w(TAG, "device name unknown; return the device name as default value");
+ }
+
+ if (deviceName != null) {
+ return deviceName.getCharSequence(GET_DEVICE_NAME_METHOD, null);
+ }
+
+ return context.getString(R.string.sud_default_device_name);
+ }
+
+ private DeviceHelper() {}
+}
diff --git a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
index e233219..bb1c667 100644
--- a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
+++ b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
@@ -19,18 +19,21 @@
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;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
+import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
@@ -100,6 +103,53 @@
PartnerStyleHelper.getLayoutGravity(description.getContext())));
}
+ public static void applyPartnerCustomizationAccountStyle(
+ ImageView avatar, TextView name, LinearLayout container) {
+ 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,
+ context.getResources().getDimension(R.dimen.sud_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);
+ }
+
+ int gravity = PartnerStyleHelper.getLayoutGravity(container.getContext());
+ container.setGravity(gravity);
+ }
+
/**
* 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()) {
diff --git a/strings/res/values/strings.xml b/strings/res/values/strings.xml
index 7608716..0b976a5 100644
--- a/strings/res/values/strings.xml
+++ b/strings/res/values/strings.xml
@@ -22,6 +22,12 @@
<!-- Button for going to the previous screen or step [CHAR LIMIT=20] -->
<string name="sud_back_button_label">Back</string>
+ <!-- Button for skipping the action on the current screen [CHAR LIMIT=20] -->
+ <string name="sud_skip_button_label">Skip</string>
+
<!-- Button for scrolling down to reveal more content on the screen [CHAR LIMIT=20] -->
<string name="sud_more_button_label">More</string>
+
+ <!-- The default device name when other resources get the device name are not available [CHAR LIMIT=20] -->
+ <string name="sud_default_device_name">device</string>
</resources>