Import updated Android SetupCompat Library 444719060
Copied from google3/third_party/java_src/android_libs/setupcompat
Test: mm
Bug: 230266991
Included changes:
- 444719060 Use longest string to be the footer button width instead ...
- 443116033 Add the sdk check for some attribute.
- 439745387 Not using a constructed instance will soon be a compile e...
- 438811281 Refine the comment of partner configs.
PiperOrigin-RevId: 444719060
Change-Id: If134ba31e2652eb5511bdd5a3ba9f63f545b05e2
diff --git a/Android.bp b/Android.bp
index 01e654d..d3a42a7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -80,6 +80,7 @@
],
static_libs: [
"androidx.annotation_annotation",
+ "error_prone_annotations",
],
min_sdk_version: "14",
sdk_version: "current",
diff --git a/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java b/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java
index 4a88f5b..37cc358 100644
--- a/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java
+++ b/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java
@@ -48,6 +48,7 @@
import com.google.android.setupcompat.util.BuildCompatUtils;
import com.google.android.setupcompat.util.Logger;
import com.google.android.setupcompat.util.WizardManagerHelper;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
/** A templatization layout with consistent style used in Setup Wizard or app itself. */
public class PartnerCustomizationLayout extends TemplateLayout {
@@ -75,14 +76,17 @@
private Activity activity;
+ @CanIgnoreReturnValue
public PartnerCustomizationLayout(Context context) {
this(context, 0, 0);
}
+ @CanIgnoreReturnValue
public PartnerCustomizationLayout(Context context, int template) {
this(context, template, 0);
}
+ @CanIgnoreReturnValue
public PartnerCustomizationLayout(Context context, int template, int containerId) {
super(context, template, containerId);
init(null, R.attr.sucLayoutTheme);
@@ -92,11 +96,13 @@
final ViewTreeObserver.OnWindowFocusChangeListener windowFocusChangeListener =
this::onFocusChanged;
+ @CanIgnoreReturnValue
public PartnerCustomizationLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, R.attr.sucLayoutTheme);
}
+ @CanIgnoreReturnValue
@TargetApi(VERSION_CODES.HONEYCOMB)
public PartnerCustomizationLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
index 9af0077..4d78955 100644
--- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
+++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
@@ -17,6 +17,7 @@
package com.google.android.setupcompat.template;
import static com.google.android.setupcompat.internal.Preconditions.ensureOnMainThread;
+import static java.lang.Math.max;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
@@ -32,7 +33,6 @@
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.LinearLayout;
@@ -240,10 +240,8 @@
if (!isSecondaryButtonInPrimaryStyle) {
return false;
}
- // TODO: Support neutral button style in glif layout for phone and tablet
PartnerConfigHelper.get(context);
- return context.getResources().getConfiguration().smallestScreenWidthDp >= 600
- && PartnerConfigHelper.isNeutralButtonStyleEnabled(context);
+ return PartnerConfigHelper.isNeutralButtonStyleEnabled(context);
}
private View addSpace() {
@@ -531,54 +529,29 @@
}
buttonContainer.addView(tempSecondaryButton);
}
- if (!isFooterButtonAlignedEnd()
- && (!isEvenlyWeightedButtons || (isEvenlyWeightedButtons && isLandscape))) {
+ if (!isFooterButtonAlignedEnd()) {
addSpace();
}
if (tempPrimaryButton != null) {
buttonContainer.addView(tempPrimaryButton);
}
- setEvenlyWeightedButtons(tempPrimaryButton, tempSecondaryButton, isEvenlyWeightedButtons);
+ if (isEvenlyWeightedButtons) {
+ setEvenlyWeightedButtons(tempPrimaryButton, tempSecondaryButton);
+ }
}
- private void setEvenlyWeightedButtons(
- Button primaryButton, Button secondaryButton, boolean isEvenlyWeighted) {
- if (primaryButton != null && secondaryButton != null && isEvenlyWeighted) {
- LinearLayout.LayoutParams primaryLayoutParams =
- (LinearLayout.LayoutParams) primaryButton.getLayoutParams();
- if (null != primaryLayoutParams) {
- primaryLayoutParams.width = 0;
- primaryLayoutParams.weight = 1.0f;
- primaryButton.setLayoutParams(primaryLayoutParams);
- }
+ private void setEvenlyWeightedButtons(Button primaryButton, Button secondaryButton) {
+ if (primaryButton != null && secondaryButton != null) {
+ primaryButton.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
+ int primaryButtonMeasuredWidth = primaryButton.getMeasuredWidth();
+ secondaryButton.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
- LinearLayout.LayoutParams secondaryLayoutParams =
- (LinearLayout.LayoutParams) secondaryButton.getLayoutParams();
- if (null != secondaryLayoutParams) {
- secondaryLayoutParams.width = 0;
- secondaryLayoutParams.weight = 1.0f;
- secondaryButton.setLayoutParams(secondaryLayoutParams);
- }
- } else {
- if (primaryButton != null) {
- LinearLayout.LayoutParams primaryLayoutParams =
- (LinearLayout.LayoutParams) primaryButton.getLayoutParams();
- if (null != primaryLayoutParams) {
- primaryLayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
- primaryLayoutParams.weight = 0;
- primaryButton.setLayoutParams(primaryLayoutParams);
- }
- }
- if (secondaryButton != null) {
- LinearLayout.LayoutParams secondaryLayoutParams =
- (LinearLayout.LayoutParams) secondaryButton.getLayoutParams();
- if (null != secondaryLayoutParams) {
- secondaryLayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
- secondaryLayoutParams.weight = 0;
- secondaryButton.setLayoutParams(secondaryLayoutParams);
- }
- }
+ int secondaryButtonMeasuredWidth = secondaryButton.getMeasuredWidth();
+ int maxButtonMeasureWidth = max(primaryButtonMeasuredWidth, secondaryButtonMeasuredWidth);
+
+ primaryButton.getLayoutParams().width = maxButtonMeasureWidth;
+ secondaryButton.getLayoutParams().width = maxButtonMeasureWidth;
}
}
diff --git a/main/res/values/styles.xml b/main/res/values/styles.xml
index 6474426..6625e83 100644
--- a/main/res/values/styles.xml
+++ b/main/res/values/styles.xml
@@ -45,13 +45,13 @@
<item name="android:theme">@style/SucPartnerCustomizationButton.Primary</item>
<!-- Values used in styles -->
- <item name="android:fontFamily">?attr/sucFooterBarButtonFontFamily</item>
+ <item name="android:fontFamily" tools:targetApi="jelly_bean">?attr/sucFooterBarButtonFontFamily</item>
<item name="android:paddingLeft">?attr/sucFooterButtonPaddingStart</item>
<item name="android:paddingStart" tools:ignore="NewApi">?attr/sucFooterButtonPaddingStart</item>
<item name="android:paddingRight">?attr/sucFooterButtonPaddingEnd</item>
<item name="android:paddingEnd" tools:ignore="NewApi">?attr/sucFooterButtonPaddingEnd</item>
<item name="android:textAllCaps">?attr/sucFooterBarButtonAllCaps</item>
- <item name="android:stateListAnimator">@null</item>
+ <item name="android:stateListAnimator" tools:ignore="NewApi">@null</item>
<!-- Values used in themes -->
<item name="android:buttonCornerRadius" tools:ignore="NewApi">?attr/sucFooterBarButtonCornerRadius</item>
@@ -65,7 +65,7 @@
<item name="android:theme">@style/SucPartnerCustomizationButton.Secondary</item>
<!-- Values used in styles -->
- <item name="android:fontFamily">?attr/sucFooterBarButtonFontFamily</item>
+ <item name="android:fontFamily" tools:targetApi="jelly_bean">?attr/sucFooterBarButtonFontFamily</item>
<item name="android:minWidth">0dp</item>
<item name="android:paddingLeft">?attr/sucFooterButtonPaddingStart</item>
<item name="android:paddingStart" tools:ignore="NewApi">?attr/sucFooterButtonPaddingStart</item>
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java
index 3fe7991..9554ff3 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java
@@ -404,10 +404,10 @@
// The divider of list items are showing.
String KEY_ITEMS_DIVIDER_SHOWN = "setup_design_items_divider_shown";
- // The intrinsic width of the card view for foldabe/tablet.
+ // The intrinsic width of the card view for foldable/tablet.
String KEY_CARD_VIEW_INTRINSIC_WIDTH = "setup_design_card_view_intrinsic_width";
- // The intrinsic height of the card view for foldabe/tablet.
+ // The intrinsic height of the card view for foldable/tablet.
String KEY_CARD_VIEW_INTRINSIC_HEIGHT = "setup_design_card_view_intrinsic_height";
// The animation of loading screen used in those activities which is non of below type.
diff --git a/setup_extension/info_modules.proto b/setup_extension/info_modules.proto
new file mode 100644
index 0000000..5027c4c
--- /dev/null
+++ b/setup_extension/info_modules.proto
@@ -0,0 +1,96 @@
+// 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.
+//
+// Author: yuchaoyu@google.com (Yu Chao)
+
+syntax = "proto2";
+
+package portal_tips_proto;
+
+option java_package = "com.google.android.setupcompat";
+option java_outer_classname = "InfoModules";
+
+// A list of informational modules to be displayed under the deferred setup
+// items.
+// Next index: 5
+message InfoModuleList {
+ // Contains the title of the entire info module section. This is displayed
+ // before the subtitle and the list of info modules.
+ optional string section_title = 1;
+
+ // Contains the subtitle of the entire info module section. This is displayed
+ // before the list of info modules.
+ optional string section_subtitle = 2;
+
+ // A module represents a single informational item to be displayed in the list
+ // under the deferred setup page.
+ //
+ // Each module contains a unique id, three sections of text labels (title,
+ // description, footer), the Intent URI to launch when being clicked, the raw
+ // icon, and a boolean to determine whether or not the icon should be colored.
+ // Next index: 8
+ message InfoModule {
+
+ // The id to uniquely identify an InfoModule.
+ optional string id = 1;
+
+ // Contains the title of the module. This is displayed as the first section
+ // of the text content.
+ optional string title = 2;
+
+ // Contains the main paragraphs of the module. This is displayed as the
+ // second section of the text content.
+ optional string description = 3;
+
+ // Contains the footer text of the module. This is displayed as the third
+ // and final section of the text content.
+ optional string footer = 4;
+
+ // Contains the Intent string to be launched when the module is clicked.
+ //
+ // This string could be generated from an `Intent` object through the
+ // `toUri()` method.
+ optional string intent_uri = 5;
+
+ // Contains the icon of the module in raw bytes of bitmap format.
+ optional bytes raw_icon = 6;
+
+ // Determines whether the icon should be colored according to the theme.
+ // Generally speaking, this should be set to true for monoline icons (such
+ // as Material Icons) because their colors change according to the theme.
+ // For icons which their colors should be preserved (such as package icons),
+ // this should be set to false.
+ optional bool should_apply_theme_color_on_icon = 7;
+ }
+
+ // Contains a list of informational modules to be displayed.
+ repeated InfoModule info_module_list = 3;
+
+ // A trailing link is a button item appearing below the info module list.
+ // Next index: 3
+ message TrailingLink {
+ // Contains the text that should be displayed on the link button.
+ optional string text = 1;
+
+ // Contains the Intent string to be launched when the link button is
+ // clicked.
+ //
+ // This string could be generated from an `Intent` object through the
+ // `toUri()` method.
+ optional string intent_uri = 2;
+ }
+
+ // Contains a trailing link to be displayed below the info modules.
+ optional TrailingLink trailing_link = 4;
+}