summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorSetup Wizard Team <android-setup-team-eng@google.com>2021-05-04 08:22:45 +0800
committerCn Chen <cnchen@google.com>2021-05-04 04:17:46 +0000
commite530e8b9c6d953bf281696a83dca37b03d212e8e (patch)
treee56ced367ca8fcbbc980a76241bb706201b680cf /main/src
parentff3cc9f2135c480fd66908bbe51c91ac8deb4645 (diff)
downloadsetupdesign-e530e8b9c6d953bf281696a83dca37b03d212e8e.tar.gz
Import updated Android Setupdesign Library 371812065
Copied from google3/third_party/java_src/android_libs/setupdesign Test: mm Bug: 182870319 Bug: 185557130 Included changes: - 371812065 Add replace rule to remove comment - 371731255 Rollback the new layout of layout-v31 due to footer bar m... - 371667272 Add API for ChimeraActivity - 371663930 [GlifLoadingLayout] make the content area keep fixed size... - 371648106 [GlifLoadingLayout] Add padding partner resources for con... - 371647490 [Transition][fallback] adds animation resources files for... - 371626793 [GlifLoadingLayout] Adds comment for functions and fixes ... - 371102383 [ColorExtraction] Adds fix colors for color extraction. - 371080909 [GlifLoadingLayout] Adds padding value for waiting screen... - 371036943 Create theme for support full dynamic color - 370881231 [GlifLoadingLayout] adjust the layout to follow spec to m... - 370868945 It's hard to know the fail reason of trySetDynamicColor PiperOrigin-RevId: 371812065 Change-Id: Ib9108999c9e53b4b8a9b21653bfe16788a6e3e22
Diffstat (limited to 'main/src')
-rw-r--r--main/src/com/google/android/setupdesign/GlifLayout.java62
-rw-r--r--main/src/com/google/android/setupdesign/GlifListLayout.java1
-rw-r--r--main/src/com/google/android/setupdesign/GlifRecyclerLayout.java1
-rw-r--r--main/src/com/google/android/setupdesign/util/DynamicColorPalette.java3
-rw-r--r--main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java35
-rw-r--r--main/src/com/google/android/setupdesign/util/ThemeHelper.java90
6 files changed, 153 insertions, 39 deletions
diff --git a/main/src/com/google/android/setupdesign/GlifLayout.java b/main/src/com/google/android/setupdesign/GlifLayout.java
index dc84c71..c9e159e 100644
--- a/main/src/com/google/android/setupdesign/GlifLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifLayout.java
@@ -154,6 +154,7 @@ public class GlifLayout extends PartnerCustomizationLayout {
applyPartnerCustomizationContentPaddingTopStyle(view);
}
}
+ updateLandscapeMiddleHorizontalSpacing();
ColorStateList backgroundColor =
a.getColorStateList(R.styleable.SudGlifLayout_sudBackgroundBaseColor);
@@ -192,6 +193,66 @@ public class GlifLayout extends PartnerCustomizationLayout {
}
}
+ protected void updateLandscapeMiddleHorizontalSpacing() {
+ int horizontalSpacing =
+ getResources().getDimensionPixelSize(R.dimen.sud_glif_land_middle_horizontal_spacing);
+
+ View headerView = this.findManagedViewById(R.id.sud_landscape_header_area);
+ if (headerView != null) {
+ if (PartnerConfigHelper.get(getContext())
+ .isPartnerConfigAvailable(PartnerConfig.CONFIG_LAYOUT_MARGIN_END)) {
+ int layoutMarginEnd =
+ (int)
+ PartnerConfigHelper.get(getContext())
+ .getDimension(getContext(), PartnerConfig.CONFIG_LAYOUT_MARGIN_END);
+
+ int paddingEnd = (horizontalSpacing / 2) - layoutMarginEnd;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ headerView.setPadding(
+ headerView.getPaddingStart(),
+ headerView.getPaddingTop(),
+ paddingEnd,
+ headerView.getPaddingBottom());
+ } else {
+ headerView.setPadding(
+ headerView.getPaddingLeft(),
+ headerView.getPaddingTop(),
+ paddingEnd,
+ headerView.getPaddingBottom());
+ }
+ }
+ }
+
+ View contentView = this.findManagedViewById(R.id.sud_landscape_content_area);
+ if (contentView != null) {
+ if (PartnerConfigHelper.get(getContext())
+ .isPartnerConfigAvailable(PartnerConfig.CONFIG_LAYOUT_MARGIN_START)) {
+ int layoutMarginStart =
+ (int)
+ PartnerConfigHelper.get(getContext())
+ .getDimension(getContext(), PartnerConfig.CONFIG_LAYOUT_MARGIN_START);
+
+ int paddingStart = 0;
+ if (headerView != null) {
+ paddingStart = (horizontalSpacing / 2) - layoutMarginStart;
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ contentView.setPadding(
+ paddingStart,
+ contentView.getPaddingTop(),
+ contentView.getPaddingEnd(),
+ contentView.getPaddingBottom());
+ } else {
+ contentView.setPadding(
+ paddingStart,
+ contentView.getPaddingTop(),
+ contentView.getPaddingRight(),
+ contentView.getPaddingBottom());
+ }
+ }
+ }
+ }
+
@Override
protected View onInflateTemplate(LayoutInflater inflater, @LayoutRes int template) {
if (template == 0) {
@@ -303,6 +364,7 @@ public class GlifLayout extends PartnerCustomizationLayout {
} else {
view.setVisibility(View.GONE);
}
+ updateLandscapeMiddleHorizontalSpacing();
}
/**
diff --git a/main/src/com/google/android/setupdesign/GlifListLayout.java b/main/src/com/google/android/setupdesign/GlifListLayout.java
index 740b2af..60f0343 100644
--- a/main/src/com/google/android/setupdesign/GlifListLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifListLayout.java
@@ -78,6 +78,7 @@ public class GlifListLayout extends GlifLayout {
if (view != null) {
applyPartnerCustomizationContentPaddingTopStyle(view);
}
+ updateLandscapeMiddleHorizontalSpacing();
}
@Override
diff --git a/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java b/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java
index 973f388..5e75436 100644
--- a/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java
@@ -79,6 +79,7 @@ public class GlifRecyclerLayout extends GlifLayout {
if (view != null) {
applyPartnerCustomizationContentPaddingTopStyle(view);
}
+ updateLandscapeMiddleHorizontalSpacing();
}
@Override
diff --git a/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java b/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java
index d1f038b..d681d9f 100644
--- a/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java
+++ b/main/src/com/google/android/setupdesign/util/DynamicColorPalette.java
@@ -58,6 +58,7 @@ public final class DynamicColorPalette {
case ColorType.ACCENT:
colorRes = R.color.sud_dynamic_color_accent_glif_v3;
break;
+ // TODO: Add testcase for getColor attributes.
case ColorType.PRIMARY_TEXT:
colorRes = R.color.sud_system_primary_text;
break;
@@ -65,7 +66,7 @@ public final class DynamicColorPalette {
colorRes = R.color.sud_system_secondary_text;
break;
case ColorType.DISABLED_OPTION:
- colorRes = R.color.sud_system_disable_option;
+ colorRes = R.color.sud_system_tertiary_text_inactive;
break;
case ColorType.ERROR_WARNING:
colorRes = R.color.sud_system_error_warning;
diff --git a/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java b/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java
index 2cde29e..d6eade8 100644
--- a/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java
+++ b/main/src/com/google/android/setupdesign/util/PartnerStyleHelper.java
@@ -20,7 +20,6 @@ import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
-import androidx.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import com.google.android.setupcompat.PartnerCustomizationLayout;
@@ -35,6 +34,7 @@ import java.util.Locale;
/** The helper reads styles from the partner configurations. */
public final class PartnerStyleHelper {
+ private static final String TAG = "PartnerStyleHelper";
/**
* Returns the partner configuration of layout gravity, usually apply to widgets in header area.
*/
@@ -120,39 +120,6 @@ public final class PartnerStyleHelper {
return isSetupFlow || usePartnerResource;
}
- /** Returns {@code true} if the dynamic color is set. */
- static boolean trySetDynamicColor(@NonNull Context context, boolean isDayNightEnabled) {
- if (!PartnerConfigHelper.shouldApplyDynamicColor(context)) {
- return false;
- }
-
- Activity activity = null;
- try {
- activity = PartnerCustomizationLayout.lookupActivityFromContext(context);
- } catch (IllegalArgumentException ex) {
- return false;
- }
-
- // try best to get partner resource settings from attrs
- boolean isSetupFlow = WizardManagerHelper.isAnySetupWizard(activity.getIntent());
-
- if (isSetupFlow) {
- // apply theme for inside setup flow
- activity.setTheme(
- isDayNightEnabled
- ? R.style.SudDynamicColorThemeGlifV3_DayNight
- : R.style.SudDynamicColorThemeGlifV3_Light);
- } else {
- // apply theme for outside setup flow
- activity.setTheme(
- isDayNightEnabled
- ? R.style.SudFullDynamicColorThemeGlifV3_DayNight
- : R.style.SudFullDynamicColorThemeGlifV3_Light);
- }
-
- return true;
- }
-
/**
* Returns if the current layout/activity applies heavy partner customized configurations or not.
*
diff --git a/main/src/com/google/android/setupdesign/util/ThemeHelper.java b/main/src/com/google/android/setupdesign/util/ThemeHelper.java
index 6852aa4..32c8e5e 100644
--- a/main/src/com/google/android/setupdesign/util/ThemeHelper.java
+++ b/main/src/com/google/android/setupdesign/util/ThemeHelper.java
@@ -20,12 +20,19 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
+import android.util.Log;
+import androidx.annotation.StyleRes;
+import com.google.android.setupcompat.PartnerCustomizationLayout;
import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper;
import com.google.android.setupcompat.util.WizardManagerHelper;
+import com.google.android.setupdesign.R;
+import java.util.Objects;
/** The helper class holds the constant names of themes and util functions */
public final class ThemeHelper {
+ private static final String TAG = "ThemeHelper";
+
/**
* Passed in a setup wizard intent as {@link WizardManagerHelper#EXTRA_THEME}. This is the dark
* variant of the theme used in setup wizard for Nougat MR1.
@@ -158,15 +165,90 @@ public final class ThemeHelper {
return PartnerConfigHelper.shouldApplyExtendedPartnerConfig(context);
}
- /** Returns {@code true} if the partner provider of SetupWizard is ready to dynamic color. */
+ /**
+ * Returns {@code true} if the partner provider of SetupWizard is ready to support dynamic color.
+ */
+ public static boolean isSetupWizardDynamicColorEnabled(@NonNull Context context) {
+ return PartnerConfigHelper.isSetupWizardDynamicColorEnabled(context);
+ }
+
+ /** Returns {@code true} if this {@code context} should apply dynamic color. */
public static boolean shouldApplyDynamicColor(@NonNull Context context) {
- return PartnerConfigHelper.shouldApplyDynamicColor(context);
+ return shouldApplyExtendedPartnerConfig(context) && isSetupWizardDynamicColorEnabled(context);
+ }
+
+ /**
+ * Returns a theme resource id if the {@link com.google.android.setupdesign.GlifLayout} should
+ * apply dynamic color.
+ *
+ * <p>Otherwise returns {@code 0}.
+ */
+ @StyleRes
+ public static int getDynamicColorTheme(@NonNull Context context) {
+ @StyleRes int resId = 0;
+
+ Activity activity;
+ try {
+ activity = PartnerCustomizationLayout.lookupActivityFromContext(context);
+ } catch (IllegalArgumentException ex) {
+ Log.e(TAG, Objects.requireNonNull(ex.getMessage()));
+ return resId;
+ }
+
+ boolean isSetupFlow = WizardManagerHelper.isAnySetupWizard(activity.getIntent());
+ boolean isDayNightEnabled = isSetupWizardDayNightEnabled(context);
+
+ if (isSetupFlow) {
+ // return theme for inside setup flow
+ resId =
+ isDayNightEnabled
+ ? R.style.SudDynamicColorThemeGlifV3_DayNight
+ : R.style.SudDynamicColorThemeGlifV3_Light;
+ } else {
+ // return theme for outside setup flow
+ resId =
+ isDayNightEnabled
+ ? R.style.SudFullDynamicColorThemeGlifV3_DayNight
+ : R.style.SudFullDynamicColorThemeGlifV3_Light;
+ Log.i(
+ TAG,
+ "Return "
+ + (isDayNightEnabled
+ ? "SudFullDynamicColorThemeGlifV3_DayNight"
+ : "SudFullDynamicColorThemeGlifV3_Light"));
+ }
+
+ return resId;
}
/** Returns {@code true} if the dynamic color is set. */
public static boolean trySetDynamicColor(@NonNull Context context) {
- return shouldApplyExtendedPartnerConfig(context)
- && PartnerStyleHelper.trySetDynamicColor(context, isSetupWizardDayNightEnabled(context));
+ if (!shouldApplyExtendedPartnerConfig(context)) {
+ Log.w(TAG, "SetupWizard does not supports the extended partner configs.");
+ return false;
+ }
+
+ if (!isSetupWizardDynamicColorEnabled(context)) {
+ Log.w(TAG, "SetupWizard does not support the dynamic color or supporting status unknown.");
+ return false;
+ }
+
+ Activity activity;
+ try {
+ activity = PartnerCustomizationLayout.lookupActivityFromContext(context);
+ } catch (IllegalArgumentException ex) {
+ Log.e(TAG, Objects.requireNonNull(ex.getMessage()));
+ return false;
+ }
+
+ if (getDynamicColorTheme(context) != 0) {
+ activity.setTheme(getDynamicColorTheme(context));
+ } else {
+ Log.w(TAG, "Error occurred on getting dynamic color theme.");
+ return false;
+ }
+
+ return true;
}
private ThemeHelper() {}